Universal MCP Server
A model-agnostic Model Context Protocol server implementation that works with any compatible AI model or client, allowing tools like file operations to be accessed through the MCP standard.
README
Universal MCP Server
A model-agnostic Model Context Protocol (MCP) server implementation that works with any compatible AI model or client, not just Claude Desktop.
🎯 Project Goals
- Universal Compatibility: Works with any model that supports MCP (Claude, local models via Hugging Face, OpenAI, etc.)
- Simple Architecture: Clean, from-scratch implementation following official MCP specification
- Extensible Tools: Easy to add new tools and capabilities
- Learning-Focused: Well-documented code to understand MCP internals
📋 Project Scope
Phase 1: Core MCP Server
- [x] JSON-RPC 2.0 over stdio communication
- [x] Basic MCP protocol methods (
initialize,tools/list,tools/call) - [x] File reading tool for specified directories
- [ ] Error handling and validation
- [ ] Configuration via command line/config file
Phase 2: Tool Expansion
- [ ] File writing capabilities
- [ ] Directory listing and navigation
- [ ] Text processing tools (search, replace, etc.)
- [ ] System information tools
- [ ] Custom tool plugin system
Phase 3: Multi-Model Client
- [ ] Generic MCP client library
- [ ] Hugging Face model integration
- [ ] OpenAI API integration
- [ ] Local model support (Ollama, etc.)
- [ ] Web interface for testing
🏗️ Architecture
┌─────────────────┐ JSON-RPC ┌─────────────────┐
│ AI Model │ ◄──────────────► │ MCP Server │
│ (Any Provider) │ (stdio) │ (Python) │
└─────────────────┘ └─────────────────┘
│
▼
┌─────────────────┐
│ Tools │
│ • File Reader │
│ • File Writer │
│ • Directory Ops │
└─────────────────┘
🚀 Quick Start
Running the MCP Server
# Install dependencies
pip install -r requirements.txt
# Run the server (communicates via stdio)
python mcp_server.py --allowed-paths ./data ./documents
# Test with a simple echo
echo '{"jsonrpc":"2.0","method":"tools/list","id":1}' | python mcp_server.py
Integrating with Models
Claude Desktop
{
"mcpServers": {
"file-tools": {
"command": "python",
"args": ["path/to/mcp_server.py", "--allowed-paths", "./data"]
}
}
}
Hugging Face Models
from mcp_client import MCPClient
from transformers import pipeline
# Initialize your model
model = pipeline("text-generation", model="microsoft/DialoGPT-medium")
# Connect to MCP server
mcp_client = MCPClient("python mcp_server.py")
# Use tools through the model
response = model("Can you read the file data/example.txt?")
tool_result = mcp_client.call_tool("read_file", {"path": "data/example.txt"})
🛠️ Available Tools
File Operations
read_file: Read contents of a file within allowed pathslist_directory: List files and folders in a directoryfile_info: Get file metadata (size, modified date, etc.)
Planned Tools
write_file: Write content to filessearch_files: Search for text within filesexecute_command: Run system commands (with safety restrictions)
📁 Project Structure
universal-mcp-server/
├── mcp_server.py # Main MCP server implementation
├── mcp_client.py # Generic client for any model
├── tools/
│ ├── __init__.py
│ ├── file_tools.py # File operation tools
│ └── system_tools.py # System information tools
├── examples/
│ ├── huggingface_client.py
│ ├── openai_client.py
│ └── test_tools.py
├── config/
│ └── server_config.yaml
├── requirements.txt
└── README.md
🔧 Configuration
Server Configuration (config/server_config.yaml)
server:
name: "Universal File Tools"
version: "1.0.0"
security:
allowed_paths:
- "./data"
- "./documents"
max_file_size: "10MB"
tools:
file_reader:
enabled: true
file_writer:
enabled: false # Disabled by default for security
Command Line Options
python mcp_server.py \
--config config/server_config.yaml \
--allowed-paths ./data ./docs \
--max-file-size 5MB \
--log-level INFO
🧪 Testing
Unit Tests
python -m pytest tests/
Manual Testing
# Test tool listing
echo '{"jsonrpc":"2.0","method":"tools/list","id":1}' | python mcp_server.py
# Test file reading
echo '{"jsonrpc":"2.0","method":"tools/call","params":{"name":"read_file","arguments":{"path":"data/test.txt"}},"id":2}' | python mcp_server.py
Integration Tests
# Test with different models
python examples/test_huggingface.py
python examples/test_openai.py
🔐 Security Considerations
- Path Restrictions: Only allow file access within specified directories
- File Size Limits: Prevent reading of extremely large files
- Input Validation: Sanitize all tool parameters
- Command Execution: Disabled by default, whitelist approach when enabled
🤝 Contributing
- Follow the official MCP specification
- Add tests for new tools
- Update documentation
- Ensure compatibility across different model providers
📚 Resources
🎓 Learning Outcomes
By building this project, you'll understand:
- How MCP protocol works under the hood
- JSON-RPC communication patterns
- Building model-agnostic AI tool interfaces
- Security considerations for AI tool access
- Integrating with various AI model providers
Next Steps: Start with mcp_server.py implementing basic file reading, then expand to multiple tools and model integrations!
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。