MCP from API

MCP from API

Enables users to expose arbitrary HTTP APIs as configurable MCP tools by defining tool specifications in a JSON configuration file.

Category
访问服务器

README

MCP from API

A configurable Model Context Protocol (MCP) server that exposes arbitrary HTTP APIs as MCP tools, driven entirely by a JSON config.

Deploy to Cloudflare

Instead of hardcoding tools, you define them in src/config/tools.config.json. Each entry describes:

  • Tool metadata: name, description, inputSchema
  • HTTP call: method, path, optional query/body mapping, headers
  • Response shaping: how to turn the HTTP response into MCP result.content

The worker runtime is still Cloudflare Workers using Wrangler.

Environment configuration

This repo is set up to keep local configuration out of git:

  • wrangler.jsonc is gitignored (may contain personal/internal URLs and IDs)
  • src/config/tools.config.json is gitignored (may contain internal tool definitions / headers)

For open-source publishing, commit the example files and copy them locally when developing.

The server uses the baseUrlEnvKey from the tool config to look up the base URL in the Worker environment (see wrangler.jsonc).

In the default config:

  • baseUrlEnvKey is API_BASE_URL
  • wrangler.jsonc typically provides different values per environment (examples shown in wrangler.jsonc.example).

Optional shared token (authTokenEnvKey)

You can protect the MCP endpoints and pass a secret through to your upstream API:

  1. In tools.config.json, set authTokenEnvKey to the name of a Worker binding (same pattern as baseUrlEnvKey). The example uses MCP_AUTH_TOKEN.
  2. In wrangler.jsonc, define that variable (or use a secret for production). If the value is missing or blank, token auth is disabled: clients do not need a token, and upstream calls do not get an extra token query parameter.
  3. When the env value is non-empty, MCP clients must send the same string when connecting, either:
    • as a path segment: /mcp/<token> or /sse/<token>, or
    • as Authorization: Bearer <token>.
  4. If the client token matches the configured secret, every upstream tool request appends token=<that secret> as a query parameter (in addition to any query mapping from the tool config). Your API can read that parameter to authorize the call.

Static per-tool headers (for example Authorization: Bearer ... for the upstream API) are set only in each tool’s http.headers block; they are not derived from the MCP client token.

Quick start (local)

Copy the example configs:

cp wrangler.jsonc.example wrangler.jsonc
cp src/config/tools.config.json.example src/config/tools.config.json

Then edit wrangler.jsonc / src/config/tools.config.json with your own values.

Defining tools in JSON

Tools are defined in src/config/tools.config.json under the tools array.

For a commit-safe reference, see src/config/tools.config.json.example.

Example:

{
  "server": {
    "name": "mcp-from-api",
    "version": "1.0.0",
    "description": "Configurable MCP server that exposes HTTP APIs as tools."
  },
  "baseUrlEnvKey": "API_BASE_URL",
  "authTokenEnvKey": "MCP_AUTH_TOKEN",
  "tools": [
    {
      "name": "example_get_users",
      "description": "Fetches a paginated list of users from the configured API.",
      "inputSchema": {
        "type": "object",
        "properties": {
          "page": {
            "type": "integer",
            "minimum": 1,
            "default": 1
          }
        },
        "required": [],
        "additionalProperties": false
      },
      "http": {
        "method": "GET",
        "path": "/users",
        "query": {
          "page": "page"
        },
        "headers": {}
      },
      "response": {
        "mode": "json",
        "contentPath": null,
        "wrap": {
          "type": "text",
          "template": "Users response:\\n\\n{{body}}"
        }
      }
    }
  ]
}

HTTP mapping

In each tool’s http block:

  • method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE"
  • path: joined with the base URL from the environment
  • query: map of query parameter name → argument key
    (e.g. "page": "page" means args.page becomes ?page=...)
  • headers: static headers to send on every call for that tool (from the config only).
  • body (optional, for methods like POST/PUT/PATCH):
    • mode: "json"
    • mapping:
      • "full" – send the entire arguments object as JSON
      • "properties" – send only selected properties, defined in properties
    • properties (when mapping is "properties"): map of body property → argument key

Response mapping

In each tool’s response block:

  • mode:
    • "json" – parse the HTTP response body as JSON
    • "text" – use response.text()
  • contentPath (optional):
    • When mode is "json", treat this as a dotted path into the parsed JSON (e.g. "data.items").
    • If omitted or not found, the entire JSON is used.
  • wrap (optional):
    • Currently supports type: "text" with a template string.
    • The placeholder {{body}} is replaced with the stringified selected content.

The final string is always returned to MCP clients as:

{
  "content": [
    {
      "type": "text",
      "text": "..."
    }
  ]
}

Runtime behaviour

  • tools/list uses the JSON config to expose all tools with their name, description, and inputSchema.
  • tools/call looks up the tool by name, constructs the HTTP request from the config and the provided arguments, calls the remote API, shapes the response, and returns it as MCP content.
  • /health reflects the current config, returning:
    • name, version from server
    • tools as a list of tool names
    • endpoints for /mcp, /sse, and /health

Development & deployment

The existing scripts still apply:

# Start development server
npm run dev

# Deploy to development environment
npm run deploy:dev

# Deploy to production environment
npm run deploy

# Test production configuration locally
npm run dev:prod

To add or change tools, edit src/config/tools.config.json and redeploy.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选