Sandbox
@Haohao-end/mcp-agent

Python MCP framework for agents, tools, and RAG servers

This project provides a Python client-server setup for Model Context Protocol. The client manages tool discovery, model calls, and tool execution, while the servers expose weather and document search tools over StdIO.

75 stars16 forksPythonUpdated 2mo ago
Who it's for

Builders who want their agent to call local tools and knowledge servers through MCP.

What it delivers

You can connect an agent to external tools and document stores without building the protocol plumbing yourself.

What it does

MCP client bridge

Discovers server tools, converts them into OpenAI-style schemas, and runs the tool-calling loop.

Weather tool server

Exposes a weather query tool backed by the WeatherAPI and handled with async HTTP requests.

RAG knowledge server

Ingests PDF and TXT content, stores vectors in ChromaDB, and retrieves relevant passages with MMR.

LangChain-based document pipeline

Uses LangChain and HuggingFace embeddings to build the retrieval layer.

StdIO transport

Runs the client-server protocol over standard input and output for local inter-process communication.

How to get it

  1. 1Run
    pip install mcp langchain langchain-community langchain-openai chromadb httpx python-dotenv openai
  2. 2To start the client and connect it to the MCP server
    python client.py server.py
  3. 3To initialize the knowledge base and start the RAG-enabled agent
    python rag_agent.py --server_script rag_server.py

README

MseeP.ai Security Assessment Badge

MCP Agent Orchestrator

The MCP Agent Orchestrator is a professional-grade Python implementation of the Model Context Protocol (MCP). It provides a structured environment for Large Language Models (LLMs) to interact with external tools and knowledge bases through a standardized communication layer. The project utilizes FastMCP for server-side tool definitions and an asynchronous client-side bridge to OpenAI-compatible interfaces.

System Architecture

The project follows a decoupled client-server architecture:

  1. MCP Client: Acts as the orchestrator. It manages the lifecycle of the MCP server, performs tool discovery, handles LLM completions, and executes tool calls returned by the model.
  2. MCP Servers: Independent services (Weather, RAG) that expose specific functions to the client via the Model Context Protocol.
  3. Transport Layer: Uses Standard Input/Output (StdIO) for high-performance, local inter-process communication.

Core Components

1. Intelligent Client Bridge

The client implementation (rag_agent.py, client.py) facilitates:

  • Asynchronous lifecycle management using AsyncExitStack.
  • Automatic tool schema conversion for OpenAI-compatible function calling.
  • Persistent conversation state and multi-turn reasoning loops.

2. Weather Service Server

The weather server (server.py) demonstrates real-time API integration:

  • Integration with external REST APIs (WeatherAPI).
  • Data normalization and formatting for LLM consumption.
  • Asynchronous request handling using httpx.

3. RAG Knowledge Server

The RAG server (rag_server.py) provides advanced document intelligence:

  • Data Ingestion: Support for PDF and TXT formats using LangChain.
  • Vector Database: Persistent storage via ChromaDB.
  • Search Optimization: Implements Maximal Marginal Relevance (MMR) for diverse information retrieval.
  • Embeddings: Integration with HuggingFace transformer models.

Project Structure

├── client.py             # Standard MCP client implementation
├── rag_agent.py          # Specialized agent for RAG operations
├── server.py             # Weather service MCP server
├── rag_server.py         # RAG knowledge base MCP server
├── test.py               # Connectivity test for LLM API
├── .env                  # Environment configuration
└── data/
    ├── rag_db/           # Vector store persistence directory
    └── text.txt # Sample knowledge base source

Technical Stack

  • Protocol: Model Context Protocol (MCP)
  • LLM Interface: OpenAI SDK (Compatible with Qwen/DashScope)
  • RAG Framework: LangChain
  • Vector Store: ChromaDB
  • Communication: Asynchronous I/O (asyncio)

Installation

Prerequisites

  • Python 3.10+
  • Virtual environment (recommended)

Environment Setup

Create a .env file in the root directory with the following variables:

API_KEY=your_llm_api_key
BASE_URL=https://dashscope.aliyuncs.com/compatible-mode/v1
MODEL=qwen-plus
EMBED_MODEL=sentence-transformers/all-MiniLM-L6-v2
# Optional for You.com Search API (100 free searches/day work without this)
YDC_API_KEY=your_youcom_api_key

Dependencies

pip install mcp langchain langchain-community langchain-openai chromadb httpx python-dotenv openai

Usage

Running the Weather + Web Search Agent

To start the client and connect it to the MCP server:

python client.py server.py

The server now exposes two tools:

  • query_weather(city)
  • search_web(query, count=5) using You.com Search API (GET https://api.you.com/v1/agents/search)

Example prompts:

  • "What's the weather in Shenzhen?"
  • "Search the web for MCP Python best practices"

Running the RAG Agent

To initialize the knowledge base and start the RAG-enabled agent:

python rag_agent.py --server_script rag_server.py

Protocol Implementation Details

The implementation strictly adheres to the MCP specification:

  1. Initialization: Client initializes the session and retrieves tool manifests.
  2. Tool Discovery: LLM is informed of available functions via JSON schema.
  3. Execution: Client intercepts tool_calls, executes the corresponding server function, and returns the result to the LLM for final synthesis.

Files in the repo

Repository payload4 top-level entries
  • mcp_rag_agent
  • mcp_rag_agent_graphrag
  • mcp_rag_langchain
  • README.md

Discussion (0)

Ask about usage, or say what you built with it

Sign in to join the discussion.

No comments yet. Be the first to say what this is good for.

More frameworks & sdks

HKUDS/nanobotFrameworks & SDKs

Ultra-lightweight, open-source, self-hosted personal AI agent framework in Python with WebUI, tools, memory, MCP, multi-agent workflows, automation, and chat apps

48k
microsoft/
SkillOpt
microsoft/SkillOptFrameworks & SDKs

SkillOpt is a text-space optimizer that trains reusable natural-language skills for frozen LLM agents through trajectory-driven edits, validation-gated updates, and deployable best_skill.md artifacts.

17k
omnigent-ai/omnigentFrameworks & SDKs

Omnigent is an open-source AI agent framework and meta-harness: orchestrate Claude Code, Codex, Cursor, Pi, and custom agents — swap harnesses without rewriting, enforce policies and sandboxing, and collaborate in real time from any device.

9.8k
kyegomez/
OpenMythos
kyegomez/OpenMythosFrameworks & SDKs

A theoretical reconstruction of the Claude Mythos architecture, built from first principles using the available research literature.

15k
D4Vinci/ScraplingFrameworks & SDKs

🕷️ An adaptive Web Scraping framework that handles everything from a single request to a full-scale crawl!

80k