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 分

    請在儲存庫或註冊中心條目中宣告授權條款。