Universal API Connector MCP for AI applications
Project description
API_Connecter_MCP
一个专门用于API连接的MCP(Model Context Protocol)服务器,让AI能够通过API连接万物。
🚀 功能特性
核心功能
- API配置管理 - 支持多种认证方式(API Key、Bearer Token、Basic Auth等)
- API数据获取 - 自动调用API并存储数据到本地数据库
- 数据预览 - 在存储前预览API返回的数据结构
- 会话管理 - 为不同的API数据创建独立的存储会话
- 数据转换 - 支持多种数据格式转换和处理
支持的API类型
- REST API
- 支持JSON、XML等多种响应格式
- 多种HTTP方法(GET、POST、PUT、DELETE等)
- 灵活的认证机制
📦 安装和配置
环境要求
- Python 3.8+
- 依赖包:requests, pandas, mcp
快速开始
1. 安装依赖
pip install -r requirements.txt
2. 配置环境变量
复制 .env.example 到 .env 并配置您的API密钥:
cp .env.example .env
3. 测试服务器
python main.py --test
4. 运行MCP服务器
# 直接运行
python main.py
# 或使用MCP开发模式(推荐用于测试)
mcp dev main.py
5. 配置Claude Desktop
将 claude_desktop_config.json 的内容复制到您的Claude Desktop配置文件中。
配置API
- 编辑
config/api_config.json文件 - 添加你的API配置信息
- 设置环境变量(如API密钥)
示例配置
{
"apis": {
"my_api": {
"name": "我的API",
"description": "API描述",
"enabled": true,
"base_url": "https://api.example.com",
"auth_type": "api_key",
"auth": {
"key": "${API_KEY}",
"header_name": "X-API-Key"
},
"endpoints": {
"get_data": {
"path": "/data",
"method": "GET",
"description": "获取数据"
}
}
}
}
}
🛠️ 可用工具
1. manage_api_config
管理API配置
# 列出所有API
manage_api_config(action="list")
# 测试API连接
manage_api_config(action="test", api_name="my_api")
# 验证API配置
manage_api_config(action="validate", api_name="my_api")
2. fetch_api_data
获取API数据并自动存储
# 基本用法
fetch_api_data(
api_name="jsonplaceholder",
endpoint_name="get_posts"
)
# 带参数的请求
fetch_api_data(
api_name="jsonplaceholder",
endpoint_name="get_post",
params={"id": 1}
)
# 指定存储会话
fetch_api_data(
api_name="my_api",
endpoint_name="get_data",
storage_session_id="my_session"
)
3. api_data_preview
预览API数据(不存储)
api_data_preview(
api_name="jsonplaceholder",
endpoint_name="get_posts",
max_rows=5
)
4. create_api_storage_session
创建数据存储会话
create_api_storage_session(
session_name="posts_data",
api_name="jsonplaceholder",
endpoint_name="get_posts",
description="存储文章数据"
)
5. list_api_storage_sessions
列出所有存储会话
list_api_storage_sessions()
🔧 数据转换
支持灵活的数据转换配置:
transform_config = {
"select_fields": ["id", "title", "body"], # 选择字段
"rename_fields": {"body": "content"}, # 重命名字段
"filter_conditions": [ # 过滤条件
{"field": "id", "operator": "gt", "value": 10}
],
"sort_by": "id", # 排序字段
"limit": 50, # 限制数量
"type_conversions": { # 类型转换
"id": "int",
"title": "str"
}
}
fetch_api_data(
api_name="jsonplaceholder",
endpoint_name="get_posts",
transform_config=transform_config
)
🔐 安全配置
环境变量
在 .env 文件中设置敏感信息:
API_KEY=your_api_key_here
GITHUB_TOKEN=your_github_token
域名安全
在配置中设置允许/禁止的域名:
{
"security": {
"allowed_domains": ["api.example.com"],
"blocked_domains": ["malicious.com"],
"max_response_size": 10485760
}
}
📊 数据存储
- 每个存储会话对应一个独立的SQLite数据库文件
- 自动去重,避免重复存储相同数据
- 支持原始数据和处理后数据的同时存储
- 完整的操作日志记录
🎯 使用场景
- 数据收集 - 从各种API收集数据进行分析
- API测试 - 测试和验证API的功能
- 数据同步 - 定期从API获取最新数据
- 数据转换 - 将API数据转换为所需格式
- API监控 - 监控API的可用性和响应时间
🔄 工作流程
- 配置API - 在配置文件中添加API信息
- 测试连接 - 验证API配置是否正确
- 预览数据 - 了解API返回的数据结构
- 创建会话 - 为数据存储创建会话
- 获取数据 - 调用API并自动存储数据
- 管理数据 - 查看和管理存储的数据
📝 注意事项
- 请遵守API提供商的使用条款和速率限制
- 妥善保管API密钥等敏感信息
- 定期备份重要的数据存储文件
- 监控API调用的成本和配额使用情况
🤝 贡献
欢迎提交Issue和Pull Request来改进这个项目!
📄 许可证
MIT License
让AI通过API连接万物! 🌐✨
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file api_connecter_mcp-1.0.1.tar.gz.
File metadata
- Download URL: api_connecter_mcp-1.0.1.tar.gz
- Upload date:
- Size: 47.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ea0fa7219c6f1b467d913c06cd6a5607d8f2714d3512beba1d03387d147ee8d2
|
|
| MD5 |
211cb750e456e4e286c1d31227d9a4fa
|
|
| BLAKE2b-256 |
a1cf477b101f97e8c21fc95442c59f003bd3dd5674066b1d64c4796f69edeea1
|
File details
Details for the file api_connecter_mcp-1.0.1-py3-none-any.whl.
File metadata
- Download URL: api_connecter_mcp-1.0.1-py3-none-any.whl
- Upload date:
- Size: 29.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0f7e6d5234162b754ca95896392ff0c46b39897e1de620d5dcd6c54c71aa62e2
|
|
| MD5 |
14b91520d6f2dba7f7f7f6da103bc5f3
|
|
| BLAKE2b-256 |
5b450e01c4e9aaba08e2de420aa13c2fc8e82a8317da3a4267157cc9ef23b740
|