Openapi Mcp

io.github.Asthanaji05由 GitHub 账号 Asthanaji05 发布v0.1.1更新于 Oct 24, 2026

Turn any OpenAPI 3 spec into a working MCP server. One file, local (stdio) or remote (HTTP).

已验证STDIO仅桌面开发者工具AI 与机器学习

概览

AI 生成的概览

把任意 OpenAPI 3 规范转成 MCP 服务器,将每个 API 端点暴露为助手可调用的工具,支持 stdio 或 HTTP。

可以做什么
  • 从网址或本地文件加载 OpenAPI 3 规范,按 operationId 为每个操作生成一个工具。
  • 调用 API 端点:每次工具调用都会发出真实 HTTP 请求,返回状态码和响应内容。
  • 用正则按工具名筛选要暴露的端点,例如只保留只读操作。
  • 通过环境变量为上游调用提供认证:bearer、basic、API key,或 OAuth2 客户端凭证与刷新令牌。
  • 以 stdio 在本地提供工具,或自建 HTTP 端点供客户端连接。
适用场景
当你已有某个 API 的 OpenAPI 3 规范,希望 AI 客户端无需为每个端点写代码即可调用时使用。适合小型公开 API 或内部服务,想要一个无依赖的快速桥接;只有 HTML 文档的 API 也可以手写一份简短规范。
运行要求
需要 Node.js 18 或更高版本,服务器是单个用 node 运行的脚本。需要一份规范,作为网址或本地 JSON 文件(YAML 需安装 yaml 包)。API 需要认证时通过环境变量提供凭据:API_TOKEN、OAUTH_CLIENT_ID、OAUTH_CLIENT_SECRET、OAUTH_REFRESH_TOKEN,可选 OAUTH_TOKEN_URL、OAUTH_SCOPE、API_HEADERS。HTTP 模式需要 MCP_AUTH_TOKEN 供客户端访问。
安装前请注意
由于不应用端点级安全覆盖,API 密钥会在每次调用时发送。HTTP 模式若未设置 MCP_AUTH_TOKEN,任何找到该网址的人都能使用你的 API 密钥,且明文 HTTP 应置于 HTTPS 之后。轮换后的 OAuth 刷新令牌只保存在内存中,重启即丢失。工具调用会对上游 API 发出真实的写入请求,响应内容在 50,000 字符处截断。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Openapi Mcp,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

[npm]

OpenAPI MCP

Turn any OpenAPI 3 spec into a working MCP server. One file, about 130 lines, no dependencies.

node openapi-mcp.mjs https://your-api.com/openapi.json

Every API endpoint becomes a tool that an AI client (Claude, Cursor, etc.) can call. There is no code generation and no per-endpoint files. The spec is read at startup, and the tools are built in memory.

Quick start

Requires Node 18 or newer.

bash
git clone <this-repo>cd openapi-mcpnode openapi-mcp.mjs sample/animechan.openapi.json

It prints openapi-mcp: 4 tools from "Animechan" -> ... and then waits silently for an MCP client. That is normal: it talks JSON-RPC over stdin/stdout and is not meant to be read by humans.

Use it with an AI client

Claude Desktop (local mode)

Add this to ~/Library/Application Support/Claude/claude_desktop_config.json, then restart the app:

json
{  "mcpServers": {    "animechan": {      "command": "node",      "args": ["/full/path/openapi-mcp.mjs", "/full/path/animechan.openapi.json"]    }  }}

If the client can't find node, use the full path from which node.

Claude Code (remote mode)

Start the server, then register it:

bash
MCP_AUTH_TOKEN=secret node openapi-mcp.mjs sample/animechan.openapi.json --http 8787
claude mcp add --transport http animechan http://localhost:8787/mcp \  --header "Authorization: Bearer secret"

Then ask in plain English: "give me a random quote from Naruto".

Two modes

ModeCommandUse when
Local (stdio)node openapi-mcp.mjs <spec>The client launches the server on your machine
Remote (HTTP)node openapi-mcp.mjs <spec> --http <port>The client connects to a URL, or you want to self-host

In HTTP mode, clients send JSON-RPC messages as POST http://host:<port>/mcp. Put --http <port> last.

Test it by hand:

bash
curl -X POST localhost:8787/mcp -H 'Authorization: Bearer secret' \  -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'

Options

node openapi-mcp.mjs <spec-url-or-file> [base-url] [--http <port>]
Argument / env varWhat it does
<spec-url-or-file>OpenAPI 3 spec, as a URL or a local file (JSON; YAML needs npm i yaml)
[base-url]Overrides the API address. Defaults to servers[0].url in the spec
API_TOKENYour secret for the API. The spec's securitySchemes decide where it goes (see Authentication)
OAUTH_CLIENT_ID, OAUTH_CLIENT_SECRETOAuth2 client-credentials: the token is fetched and refreshed automatically
OAUTH_REFRESH_TOKENOAuth2 refresh-token grant (use with the client id and secret)
OAUTH_TOKEN_URL, OAUTH_SCOPEOptional: override the tokenUrl from the spec, or request a scope
API_HEADERSExtra headers sent on every call, for anything the schemes don't cover. Example: '{"X-App-Id":"abc"}'
TOOL_FILTERRegex. Only tools whose name matches are exposed. Example: '^(get|list)' for read-only
MCP_AUTH_TOKENHTTP mode only. Requires Authorization: Bearer <token> on every request

Big APIs can have hundreds of endpoints. Too many tools makes the model choose worse, so use TOOL_FILTER to keep the useful ones.

Authentication

The server reads securitySchemes from the spec and puts your secret in the right place. You only supply the secret as an environment variable:

Spec saysSetSent as
http / bearerAPI_TOKEN=tokAuthorization: Bearer tok
http / basicAPI_TOKEN=user:passAuthorization: Basic <base64>
apiKey in headerAPI_TOKEN=keyThe header named in the spec (e.g. X-Key: key)
apiKey in queryAPI_TOKEN=keyThe query parameter named in the spec
apiKey in cookieAPI_TOKEN=keyCookie: name=key
oauth2 / openIdConnect, you already have an access tokenAPI_TOKEN=tokenAuthorization: Bearer token
oauth2, machine-to-machineOAUTH_CLIENT_ID + OAUTH_CLIENT_SECRETToken fetched from the tokenUrl, cached, and renewed before it expires
oauth2, you logged in once elsewherethe two above + OAUTH_REFRESH_TOKENAccess tokens renewed from the refresh token

Example for Claude Desktop:

json
{  "mcpServers": {    "my-api": {      "command": "node",      "args": ["/full/path/openapi-mcp.mjs", "https://my-api.com/openapi.json"],      "env": { "API_TOKEN": "your-secret" }    }  }}

Notes:

  • If the spec declares a security scheme but no credentials are set, a warning is printed to stderr at startup.
  • If the spec lists several schemes, the first one in the top-level security list is used (or the first one defined). Per-endpoint security overrides are not applied, so the secret is sent on every call.
  • OAuth client credentials are sent as HTTP Basic auth to the token endpoint.
  • The OAuth browser login (authorization-code flow) is not built in. Get a token or refresh token once with your provider's tools, then pass it in.
  • If a provider rotates refresh tokens, the new one is kept in memory only, so it is lost on restart.

How it works

  1. Load the spec and resolve $ref pointers.
  2. Build tools: each operation becomes one MCP tool. operationId is the name, summary the description, and parameters plus request body the input schema.
  3. Call: a tool call makes the real HTTP request and returns HTTP <status> followed by the response body (cut at 50,000 characters).
  4. Serve the tools over JSON-RPC 2.0, via stdio or HTTP.

APIs without an OpenAPI spec

Many small public APIs only have HTML docs. For those, write a small spec by hand (see sample/animechan.openapi.json, 4 tools in about 35 lines), then run it the same way.

Limitations

  • OpenAPI 3 only. Convert Swagger 2.0 specs first.
  • JSON request bodies only. No file uploads.
  • Auth: bearer, basic, API keys, and OAuth2 client-credentials or refresh-token. There is no interactive OAuth login, and one scheme is used per API.
  • HTTP mode speaks plain HTTP (put HTTPS in front when deploying) and has no streaming, batch requests, or OAuth for clients connecting to the server (it only supports the MCP_AUTH_TOKEN bearer token). Some remote clients may require these.
  • HTTP mode speaks plain HTTP (put HTTPS in front when deploying) and has no streaming, batch requests, or OAuth. Some remote clients may require these.
  • If you deploy remotely, every user shares your server's IP, so upstream rate limits apply to all of them. Set MCP_AUTH_TOKEN, or anyone who finds the URL can use your API key.

Contributing

Issues and pull requests are welcome. The goal is to stay small and readable, so please keep new features to a few lines each.

来源:README.md,提交 0990a08

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

1
  1. v0.1.1最新Oct 12, 2026

评分

已满足适用检查项的 40%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分

    请在仓库或注册中心条目中声明许可证。