Content
# MCP Example Project
## Project Overview
This is a service demonstration project based on MCP (Model Context Protocol), used to showcase how to build and use MCP services, and achieve interactive integration between large models and tools. The project mainly demonstrates how to create MCP services, build MCP clients, and utilize LLM (Large Language Model) for tool invocation and orchestration.
## Project Structure
```
mcp-demo/
├── prompt/ # Prompt templates
│ └── systemPrompt.txt # System prompt
├── src/ # Source code
│ └── demo/
│ ├── llm/ # Core code for LLM and MCP integration
│ │ ├── config/ # Configuration related
│ │ ├── llm/ # LLM client implementation
│ │ ├── mcp_client/ # MCP client implementation
│ │ ├── mcp_server/ # MCP service implementation
│ │ └── host.py # Main program entry
│ ├── 1-stdio/ # MCP demonstration with standard input/output
│ └── 2-sse/ # MCP demonstration with SSE
├── server_config.json # Service configuration file
└── requirements.txt # Project dependencies
```
## Installation
1. Clone the repository and enter the project directory
2. Install dependencies
```bash
pip install -r requirements.txt
```
## Features
- Supports multiple MCP communication methods:
- Standard input/output (stdio)
- SSE communication protocol (SSE)
- Provides basic computing tool services
- Supports large model tool invocation and orchestration
- Extensible tool registration mechanism
## Usage
### Configure LLM
Create a `.env` file in the project root directory and configure the following environment variables:
```text
LLM_API_KEY=your_api_key
LLM_BASE_URL=proxy_base_url
MODEL=gpt-4o
```
### Run Examples
Execute the main program:
```bash
1-stdio: python ${project_path}/src/demo/1-stdio/stdio_client.py
2-sse:
- python ${project_path}/src/demo/2-sse/sse_server.py
- python ${project_path}/src/demo/2-sse/sse_client.py
llm: python ${project_path}/src/demo/llm/host.py
```
### Custom MCP Service
You can create your own MCP service under the `mcp_server` directory, for example:
```python
from mcp.server.fastmcp import FastMCP
# Create an MCP service
mcp = FastMCP("Custom Service Name")
@mcp.tool(name="tool_name", description="Tool description")
async def tool_function(param1: type, param2: type) -> return_type:
# Implement tool logic
return result
if __name__ == "__main__":
# Start the service
mcp.run()
```
### Configure MCP Service
Edit the `server_config.json` file to configure the MCP service:
```json
{
"mcpServers": {
"Calculation": {
"type": "stdio",
"command": "python",
"args": ["${relative_path_to_project_root}"]
}
}
}
```
- type: Supports stdio, sse
- command: Execution command (required for stdio mode)
- args: Execution command parameters (required for stdio mode)
- url: Service address (required for sse mode)
## Dependencies
- mcp >= 1.2.0
- openai >= 1.10.0
- asyncio >= 3.4.3
- python-dotenv >= 1.0.0
## License
This project follows the [MIT] open-source license.
Connection Info
You Might Also Like
everything-claude-code
Complete Claude Code configuration collection - agents, skills, hooks,...
markitdown
MarkItDown-MCP is a lightweight server for converting URIs to Markdown.
firecrawl
Firecrawl MCP Server enables web scraping, crawling, and content extraction.
servers
Model Context Protocol Servers
servers
Model Context Protocol Servers
Time
A Model Context Protocol server for time and timezone conversions.