中文文档 | DeepWiki for this Repository
This project is a simple Agent example based on Model Context Protocol (MCP) to demonstrate the basic functionality of an MCP Host.
It follows the implementation approach of the MCP Host Agent from the DIY-your-AI-agent project, aimed at helping you quickly understand and get started with MCP application development.
Ensure you have Python 3.7+ installed. Then, install the necessary libraries:
pip install openai rich fastmcpopenai: For interacting with LLM APIs.rich: For displaying rich text in the terminal.fastmcp: Python implementation of MCP SDK.
Edit the agent_en.py file and fill in your configuration:
API_CONFIG = {
"url": "YOUR_LLM_API_BASE_URL", # Replace with your LLM API base URL
"api_key": "YOUR_LLM_API_KEY", # Replace with your LLM API key
"model": "Qwen/Qwen2.5-7B-Instruct", # Specify the LLM model to use
"MCP_Server": "http://127.0.0.1:8000/sse" # Your MCP server address (if using local server.py)
}Note: The MCP_Server address needs to match the MCP Server run in the next step.
This demo includes a simple MCP Server implementation for demonstration. Run in your terminal:
HTTP with SSE transport
$ python ./mcp_demo/server.pyYou'll see output like this, indicating the server has started successfully:
[04/27/25 12:00:00] INFO Starting server "Demo"... server.py:262
INFO: Started server process [21112]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
In another terminal window, run the Agent script:
$ python agent.pyNow, the Agent will connect to the MCP Server and interact with the LLM through it.
Want to make your Agent smarter and more powerful? Consider these approaches:
-
Ask the Friendly AI 🤖
- Talk directly with the model in the terminal to iterate on your ideas.
- Try asking: "How can I give my Agent stronger decision-making abilities?" or "How can I optimize my terminal assistant experience?"
-
Explore Model Context Protocol (MCP) 🏗️
MCP is an open protocol for seamless integration between LLMs and external data sources/tools. It helps models access richer context information to generate more accurate responses. Study MCP's core concepts like
Resources,Tools, andPromptsto enhance your Agent's capabilities.See also:
This project is under the MIT License. Feel free to use, modify, and distribute.
Issues and Pull Requests welcome! If you have improvement suggestions or find bugs, please let us know.
