Skip to main content
Glama
vicboma1

claude-ia-mcp-tools

by vicboma1

API 客户端 → 业务逻辑 → MCP 工具

一个简单的 Python 示例,展示如何在普通应用代码和 MCP 工具中复用 API 客户端和业务逻辑。

结构

src/example/
├── api/
│   └── api_client.py
├── business/
│   └── service.py
├── mcp/
│   └── server.py
└── main.py

该示例提供 5 个操作:

  1. get_user

  2. list_users

  3. create_user

  4. update_user

  5. delete_user

MCP 层刻意保持轻量:它验证 MCP 输入并委托给业务服务。业务服务将 HTTP 工作委托给 API 客户端。

Related MCP server: JSONPlaceholder MCP Server

安装

python -m venv .venv
# Windows:
.venv\Scripts\activate
# Linux/macOS:
source .venv/bin/activate

pip install -r requirements.txt

运行 MCP 服务器

python -m src.example.mcp.server

或者配置 MCP 客户端来启动:

python -m src.example.mcp.server

使用 MCP 工具

通过终端

{"jsonrpc":"2.0","method":"tools/list","id":1}

或者通过 Claude

{
  "mcpServers": {
    "example-users": {
      "command": "python",
      "args": ["-m", "src.example.mcp.server"]
    }
  }
}

重要说明

这是一个自包含的架构示例。API 客户端使用 https://jsonplaceholder.typicode.com 作为公开的演示 API。

对于真实 API,请替换 ApiClient 的实现,并保持业务/MCP 接口基本不变。

测试工作流执行

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    B
    maintenance
    Wraps the JSONPlaceholder fake REST API to enable testing and prototyping with CRUD operations on posts, comments, and other resources via MCP.
    590 npm
    MIT
  • F
    license
    Not graded
    quality
    D
    maintenance
    A minimal demo MCP server exposing user management tools (list, get, create, update, delete users) over both stdio and HTTP/SSE transports, wrapping an Express REST API to illustrate local vs remote MCP connectivity.
    -