Skip to main content

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

  1. 编辑 config/api_config.json 文件
  2. 添加你的API配置信息
  3. 设置环境变量(如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数据库文件
  • 自动去重,避免重复存储相同数据
  • 支持原始数据和处理后数据的同时存储
  • 完整的操作日志记录

🎯 使用场景

  1. 数据收集 - 从各种API收集数据进行分析
  2. API测试 - 测试和验证API的功能
  3. 数据同步 - 定期从API获取最新数据
  4. 数据转换 - 将API数据转换为所需格式
  5. API监控 - 监控API的可用性和响应时间

🔄 工作流程

  1. 配置API - 在配置文件中添加API信息
  2. 测试连接 - 验证API配置是否正确
  3. 预览数据 - 了解API返回的数据结构
  4. 创建会话 - 为数据存储创建会话
  5. 获取数据 - 调用API并自动存储数据
  6. 管理数据 - 查看和管理存储的数据

📝 注意事项

  • 请遵守API提供商的使用条款和速率限制
  • 妥善保管API密钥等敏感信息
  • 定期备份重要的数据存储文件
  • 监控API调用的成本和配额使用情况

🤝 贡献

欢迎提交Issue和Pull Request来改进这个项目!

📄 许可证

MIT License


让AI通过API连接万物! 🌐✨

Metadata

Release files for api-connecter-mcp 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for api-connecter-mcp 1.0.1
File Size Uploaded Provenance
api_connecter_mcp-1.0.1.tar.gz 47.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for api-connecter-mcp 1.0.1
File Interpreter ABI Platform
api_connecter_mcp-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 76.7 kB

Release files / api_connecter_mcp-1.0.1.tar.gz

Download URL api_connecter_mcp-1.0.1.tar.gz
Size 47.1 kB
Tags Source
SHA-256 checksum
How to use checksums
ea0fa7219c6f1b467d913c06cd6a5607d8f2714d3512beba1d03387d147ee8d2
BLAKE2b-256 checksum
How to use checksums
a1cf477b101f97e8c21fc95442c59f003bd3dd5674066b1d64c4796f69edeea1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.4

Release files / api_connecter_mcp-1.0.1-py3-none-any.whl

Download URL api_connecter_mcp-1.0.1-py3-none-any.whl
Size 29.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0f7e6d5234162b754ca95896392ff0c46b39897e1de620d5dcd6c54c71aa62e2
BLAKE2b-256 checksum
How to use checksums
5b450e01c4e9aaba08e2de420aa13c2fc8e82a8317da3a4267157cc9ef23b740
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.4

Security for api-connecter-mcp 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page