Content
# MCP Sample Project | MCP Sample Project
A powerful interface for extending AI capabilities through remote control, calculations, email operations, knowledge search, and more.
## Overview | Overview
MCP (Model Context Protocol) is a protocol that allows servers to expose tools that can be invoked by language models. Tools enable models to interact with external systems, such as querying databases, calling APIs, or performing computations. Each tool is uniquely identified by a name and includes metadata describing its schema.
## Features | Features
- 🔌 Bidirectional communication between AI and external tools | Bidirectional communication between AI and external tools
- 🔄 Automatic reconnection with exponential backoff | Automatic reconnection with exponential backoff
- 📊 Real-time data streaming | Real-time data streaming
- 🛠️ Easy-to-use tool creation interface | Easy-to-use tool creation interface
- 🔒 Secure WebSocket communication | Secure WebSocket communication
- ⚙️ Multiple transport types support (stdio/sse/http) | Multiple transport types support (stdio/sse/http)
## Quick Start | Quick Start
1. Install dependencies | Install dependencies:
```bash
pip install -r requirements.txt
```
2. Set up environment variables | Set up environment variables:
```bash
export MCP_ENDPOINT=<your_mcp_endpoint>
```
3. Run the calculator example | Run the calculator example:
```bash
python mcp_pipe.py calculator.py
```
Or run all configured servers | Or run all configured servers:
```bash
python mcp_pipe.py
```
*Requires `mcp_config.json` configuration file with server definitions (supports stdio/sse/http transport types)*
*Requires `mcp_config.json` configuration file with server definitions (supports stdio/sse/http transport types)*
## Project Structure | Project Structure
- `mcp_pipe.py`: Main communication pipe that handles WebSocket connections and process management | Main communication pipe that handles WebSocket connections and process management
- `calculator.py`: Example MCP tool implementation for mathematical calculations | Example MCP tool implementation for mathematical calculations
- `requirements.txt`: Project dependencies | Project dependencies
## Config-driven Servers | Config-driven Servers
编辑 `mcp_config.json` 文件来配置服务器列表(也可设置 `MCP_CONFIG` 环境变量指向其他配置文件)。
配置说明:
- 无参数时启动所有配置的服务(自动跳过 `disabled: true` 的条目)
- 有参数时运行单个本地脚本文件
- `type=stdio` 直接启动;`type=sse/http` 通过 `python -m mcp_proxy` 代理
## Creating Your Own MCP Tools | Creating Your Own MCP Tools
Here's a simple example of creating an MCP tool | Here's a simple example of creating an MCP tool:
```python
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("YourToolName")
@mcp.tool()
def your_tool(parameter: str) -> dict:
"""Tool description here"""
# Your implementation
return {"success": True, "result": result}
if __name__ == "__main__":
mcp.run(transport="stdio")
```
## Use Cases | Use Cases
- Mathematical calculations | Mathematical calculations
- Email operations | Email operations
- Knowledge base search | Knowledge base search
- Remote device control | Remote device control
- Data processing | Data processing
- Custom tool integration | Custom tool integration
## Requirements | Requirements
- Python 3.7+
- websockets>=11.0.3
- python-dotenv>=1.0.0
- mcp>=1.8.1
- pydantic>=2.11.4
- mcp-proxy>=0.8.2
## Contributing | Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
## License | License
This project is licensed under the MIT License - see the LICENSE file for details.
## Acknowledgments | Acknowledgments
- Thanks to all contributors who have helped shape this project | Thanks to all contributors who have helped shape this project
- Inspired by the need for extensible AI capabilities | Inspired by the need for extensible AI capabilities
Connection Info
You Might Also Like
markitdown
MarkItDown-MCP is a lightweight server for converting URIs to Markdown.
servers
Model Context Protocol Servers
Time
A Model Context Protocol server for time and timezone conversions.
Filesystem
Node.js MCP Server for filesystem operations with dynamic access control.
Sequential Thinking
A structured MCP server for dynamic problem-solving and reflective thinking.
git
A Model Context Protocol server for Git automation and interaction.