使用说明
MCP OpenAPI代理客户端
一个全面的Python客户端,用于连接到MCP(模型上下文协议)OpenAPI代理服务器。
概述
该项目提供了连接到MCP OpenAPI代理服务器并与之交互的工具和实用程序,这些服务器将MCP工具公开为REST API端点。它包括经过身份验证的客户端、测试实用程序和配置模板。
特性
- 🔐 安全认证:具有多种配置选项的承载令牌身份验证
- ⏰ 时间操作:当前时间检索和时区转换
- 🧠 知识图谱:创建和管理实体、关系和观察
- 📁 文件系统操作:安全的文件读取、写入和目录管理
- 🧪 综合测试:带身份验证的完整测试套件
- 📚 文档:完整的安装指南和API文档
快速开始
1.安装依赖项
pip install requests
2.设置身份验证
# Option A: Environment variable (recommended)
export MCP_API_TOKEN="your-api-token"
# Option B: Token file
echo "your-api-token" > mcp_token.txt
# Option C: Interactive setup
python3 examples/setup_auth.py
3.测试连接
python3 src/mcp_authenticated_client.py time_now
项目结构
mcps/
├── src/ # Main source code
│ ├── mcp_authenticated_client.py # Full-featured authenticated client
│ └── mcp_proxy_client.py # Basic client (no auth)
├── tests/ # Test files
│ ├── test_mcp_tools.py # Comprehensive tool tests
│ ├── test_mcp_connection.py # Basic connection tests
│ └── auth_helper.py # Authentication discovery
├── config/ # Configuration templates
│ ├── auth_config_template.json # Authentication template
│ ├── claude_desktop_config.json # Claude Desktop config
│ ├── cline_mcp_settings.json # VS Code/Cline config
│ └── mcp_client_config.json # Generic MCP client config
├── server_config/ # Server configuration management
│ ├── mcp-config.json # Local copy of server config
│ ├── server_notes.md # Server setup documentation
│ ├── sync_config.py # Configuration sync tool
│ └── README.md # Server management guide
├── examples/ # Example scripts
│ └── setup_auth.py # Interactive auth setup
├── docs/ # Documentation
│ ├── README.md # Detailed usage guide
│ ├── SETUP_COMPLETE.md # Complete setup documentation
│ └── SUCCESS_SUMMARY.md # Success summary with examples
└── .gitignore # Git ignore file (excludes tokens)
认证
此客户端支持多种身份验证方法:
-
环境变量 (推荐)
export MCP_API_TOKEN="your-token" -
令牌文件
echo "your-token" > mcp_token.txt -
配置文件 编辑
config/auth_config_template.json用你的代币 -
直接参数
client = MCPAuthenticatedClient(token="your-token")
使用示例
命令行接口
# Time operations
python3 src/mcp_authenticated_client.py time_now "Europe/London"
python3 src/mcp_authenticated_client.py time_convert "15:00" "UTC" "Asia/Tokyo"
# Filesystem operations
python3 src/mcp_authenticated_client.py fs_list_dirs
python3 src/mcp_authenticated_client.py fs_list "/allowed/directory"
# Memory operations
python3 src/mcp_authenticated_client.py memory_graph
python3 src/mcp_authenticated_client.py memory_search "technology"
Python集成
from src.mcp_authenticated_client import MCPAuthenticatedClient
client = MCPAuthenticatedClient()
# Time operations
time_nyc = client.time_get_current_time("America/New_York")
conversion = client.time_convert_time("UTC", "14:30", "Asia/Tokyo")
# Memory operations
graph = client.memory_read_graph()
client.memory_create_entities([{
"name": "Python",
"entityType": "Programming Language",
"observations": ["Object-oriented", "Popular for AI"]
}])
# Filesystem operations
directories = client.fs_list_allowed_directories()
content = client.fs_read_text_file("/path/to/file.txt")
添加更多MCP服务器
您的设置当前包括 记忆, 时间,以及 文件系统 服务器。您可以添加更多:
🚀 快速添加服务器
# List available servers
python3 scripts/add_mcp_server.py list
# Add a new server (example: web scraping)
python3 scripts/add_mcp_server.py fetch
# Add GitHub integration
python3 scripts/add_mcp_server.py github
📋 常用服务器选项
- 🌐 Web和API:
fetch,brave-search,puppeteer - 💻 发展:
github,gitlab,postman - 🗄️ 数据库:
sqlite,postgresql - ☁️ 云:
google-drive,aws,azure - 💬 沟通:
slack,discord - 💰 金融:
alphavantage,stripe
看 docs/available_mcp_servers.md 查看完整列表和设置说明。
服务器配置管理
从远程服务器同步配置
python3 server_config/sync_config.py sync # Sync from remote
python3 server_config/sync_config.py list # List current servers
python3 server_config/sync_config.py status # Check service status
服务器详细信息
- 主机:
ajlennon@ollama(192.168.0.7:8000) - 活动服务器:内存、时间、文件系统(3台服务器)
- 配置:
/home/ajlennon/mcp-service/mcp-config.json - 服务:MCP代理(
mcpo)带有REST API公开
测试
运行综合测试套件:
python3 tests/test_mcp_tools.py
测试特定组件:
python3 tests/test_mcp_connection.py # Basic connectivity
python3 tests/auth_helper.py # Authentication discovery
配置
模板配置文件在 config/ 各种MCP客户端的目录:
- 克劳德桌面:
config/claude_desktop_config.json - VS代码/临床:
config/cline_mcp_settings.json - 通用的:
config/mcp_client_config.json
安全
- 令牌保护:所有敏感代币都通过git排除在外
.gitignore - 多种身份验证方法:针对不同环境的灵活身份验证选项
- 安全默认值:建议用于生产的环境变量
文档
综合文档可在 docs/ 目录:
docs/README.md-详细使用指南docs/SETUP_COMPLETE.md-完整的设置说明docs/SUCCESS_SUMMARY.md-成功案例总结
需求
- Python 3.6+
requests图书馆- 带承载令牌身份验证的MCP OpenAPI代理服务器
许可证
此项目按原样提供,用于连接到MCP OpenAPI代理服务器。
贡献
这是特定MCP OpenAPI代理服务器的客户端实现。欢迎提供更多功能和改进。
