AI代理通信工具

一个使用CrewAI、MCP和本地Ollama模型的AI代理通信工具,用于通过工具从本地Flask服务器检索结构化数据并使用本地大型语言模型生成智能响应。

  • by TAMASALA
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 TAMASALA/MCP_SERVER

使用说明

🤖 MCP + CrewAI Local Ollama Demo

🚀 AI Agent Communication using MCP, CrewAI & Local Ollama

Built with CrewAI • Model Context Protocol (MCP) • Ollama • Flask API • LiteLLM


⭐ A production-ready demonstration of Model Context Protocol (MCP) integrated with CrewAI and Ollama, enabling AI agents to retrieve structured data from a local Flask server through tools and generate intelligent responses using a local Large Language Model.


✨ Project Overview

This project demonstrates how modern AI agents can interact with external systems using the Model Context Protocol (MCP).

Instead of embedding all knowledge inside the LLM, the CrewAI agent retrieves structured student information from a local Flask-based MCP server through a tool, then uses a local Ollama model to analyze and summarize the results.

Everything runs locally, making the system fast, private, and ideal for learning AI agent architectures.


🚀 Features

  • 🤖 CrewAI Agent
  • 🔗 Model Context Protocol (MCP)
  • 🖥️ Local Ollama LLM
  • ⚡ Flask REST API
  • 🛠️ LiteLLM Integration
  • 📊 Student Database Querying
  • 🔒 Fully Offline Execution
  • 🚀 Tool-Based Agent Workflow
  • 📦 Docker Ready
  • 💻 CPU Friendly

🧠 System Architecture

               User Query

                    │

             CrewAI Agent

                    │

          MCP Tool Invocation

                    │

            Flask MCP Server

                    │

           Student JSON Database

                    │

          Structured Data Response

                    │

          Local Ollama (LLM)

                    │

        Intelligent AI Response

⚡ AI Workflow

User Request

↓

CrewAI Agent

↓

MCP Tool

↓

Flask API

↓

Student Database

↓

Retrieved Data

↓

Local Ollama

↓

AI Analysis

↓

Final Response

🛠️ Technology Stack

Layer Technology
AI Framework CrewAI
Protocol Model Context Protocol (MCP)
API Flask
LLM Ollama
LLM Gateway LiteLLM
Language Python
Database JSON
Deployment Local / Offline

📂 Project Structure

MCP-CrewAI-Demo/

├── MCP/
│   ├── crew.py
│   ├── mcp.server.py
│   ├── student.json
│
├── README.md

🎯 Core Components

🤖 CrewAI Agent

  • Task Planning
  • Tool Calling
  • LLM Reasoning
  • Response Generation

🔗 MCP Server

  • Flask REST API
  • Student Data Access
  • Structured JSON Responses
  • Tool Integration

🧠 Local LLM

  • Ollama
  • LiteLLM Integration
  • Offline Inference
  • Local Reasoning

📊 Data Layer

  • JSON Database
  • Student Records
  • Query Filtering
  • Dynamic Retrieval

🚀 API Endpoint

Query Students

POST /query_students

Request

{
  "filter": {
    "marks": {
      "gt": 80
    }
  }
}

Response

[
  {
    "name": "Alice",
    "age": 20,
    "marks": 91
  }
]

🚀 Installation

Clone Repository

git clone https://github.com/yourusername/mcp-crewai-demo.git

cd mcp-crewai-demo

Install Dependencies

pip install crewai litellm flask requests

Start Ollama

ollama serve

Download Model

ollama pull granite3-dense:2b

Verify installation

ollama list

Start MCP Server

python MCP/mcp.server.py

Run CrewAI Agent

python MCP/crew.py

⚙️ Configuration

Current Local Model

ollama/granite3-dense:2b

Environment

OLLAMA_BASE_URL=http://localhost:11434

OLLAMA_API_BASE=http://localhost:11434

To use another model, update the LLM(...) configuration in crew.py.


🔧 Troubleshooting

OpenAI API Errors

Possible Cause

  • Request routed to OpenAI instead of Ollama

Solution

  • Remove OPENAI_API_KEY
  • Use ollama/<model>
  • Verify LiteLLM configuration

Ollama Connection Error

Check

ollama serve

Verify

http://localhost:11434/api/tags

List models

ollama list

MCP Server Error

Start the server

python MCP/mcp.server.py

Ensure the Flask server is running on Port 5001.


Windows Encoding Issues

chcp 65001

or

set PYTHONUTF8=1

🧪 Future Improvements

  • Multi-Agent Collaboration
  • Multiple MCP Servers
  • PostgreSQL Integration
  • Authentication
  • FastAPI Migration
  • Streaming Responses
  • LangGraph Integration
  • RAG Support
  • Docker Compose
  • Web Dashboard

💡 Design Philosophy

This project demonstrates how AI agents can interact with external systems using the Model Context Protocol (MCP) rather than relying solely on model knowledge.

By combining CrewAI, Flask APIs, and a local Ollama model, the architecture enables modular, tool-driven reasoning where the agent retrieves real-time structured data before generating responses. The result is a lightweight, extensible, and privacy-focused AI workflow suitable for local development and experimentation.


📈 Recruiter Highlights

✔ CrewAI

✔ Model Context Protocol (MCP)

✔ AI Agents

✔ Tool Calling

✔ Ollama

✔ LiteLLM

✔ Flask

✔ REST APIs

✔ Local LLM Deployment

✔ Offline AI

✔ Python

✔ Agent Workflows

✔ Multi-Agent Systems

✔ Production-Ready Architecture

✔ AI Tool Integration

✔ Context-Aware Reasoning


⭐ Support

If you found this project useful, please consider giving it a ⭐ Star.

It helps others discover the project and supports future improvements.


🚀 Built with CrewAI, MCP & Ollama

Designed to showcase modern AI agents, tool calling, local LLM deployment, and Model Context Protocol integration.