api2mcp-asp
API2MCP is an Agentic Service Provider that generates a complete, ready-to-deploy TypeScript MCP server from any OpenAPI 3.x spec, with x402 pay-per-call billing already wired in.
README
API2MCP — turn any OpenAPI spec into a paid MCP server
OKX.AI Genesis Hackathon · Software Utility track
API2MCP is an Agentic Service Provider (ASP): give it any OpenAPI 3.x spec (JSON or YAML) and it generates a complete, ready-to-deploy TypeScript MCP server scaffold — one MCP tool per API operation, proxying the upstream API — with x402 pay-per-call billing already wired in.
It is deliberately meta: API2MCP is itself an MCP service that other agents pay (via x402) to call, and each call mints another monetizable ASP for the OKX.AI marketplace. One paid service that manufactures more paid services. See the ASP tutorial: https://www.okx.ai/tutorial/asp.
Generation is fully deterministic — plain template strings, no LLM calls.
How it works
OpenAPI 3.x spec (JSON/YAML)
|
v
API2MCP generator ──────────────► generated project (file map / zip)
- parse + light validation package.json, tsconfig.json
- 1 operation -> 1 MCP tool src/server.ts (Express + MCP Streamable HTTP,
- params/body -> Zod schemas fetch-proxy to the upstream API)
- servers[0] -> upstream base URL src/x402.ts (env-driven pay-per-call gate)
README.md, .env.example, .gitignore
Run it
npm install
npm run dev # starts http://localhost:4402 (tsx watch)
# or: npm run build && npm start
npm test # acceptance test: generated project must npm install + tsc cleanly
Interfaces
MCP (Streamable HTTP, stateless) — POST /mcp
| Tool | Pricing | Description |
|---|---|---|
generate_mcp_server |
paid | {openapi_spec, service_name?, price_usd?} → {files: {path: content}, tool_count, instructions} |
preview_tools |
free | {openapi_spec} → list of {name, description, params} it would generate (teaser) |
curl -s http://localhost:4402/mcp \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}'
REST
| Endpoint | Pricing | Returns |
|---|---|---|
POST /api/generate |
paid | JSON {service_name, tool_count, tools, files, instructions} |
POST /api/generate.zip |
paid | zip archive of the generated project |
POST /api/preview |
free | tool listing teaser |
# Generate an MCP server from the bundled petstore fixture:
node -e 'console.log(JSON.stringify({openapi_spec: require("fs").readFileSync("examples/petstore.json","utf8"), price_usd: 0.01}))' \
| curl -s http://localhost:4402/api/generate -H 'Content-Type: application/json' -d @- \
| node -e 'let s="";process.stdin.on("data",d=>s+=d).on("end",()=>{const r=JSON.parse(s);console.log(r.service_name, r.tool_count, Object.keys(r.files));})'
# Or download it as a zip:
node -e 'console.log(JSON.stringify({openapi_spec: require("fs").readFileSync("examples/petstore.json","utf8")}))' \
| curl -s http://localhost:4402/api/generate.zip -H 'Content-Type: application/json' -d @- -o petstore-mcp.zip
CLI (local use, no server)
npx tsx src/cli.ts examples/petstore.json -o out/
cd out/petstore-mcp && npm install && npm run dev
OKX payment
Paid calls are settled via OKX's official x402 seller middleware
(@okxweb3/x402-express + @okxweb3/x402-core + @okxweb3/x402-evm) against
the OKX facilitator on X Layer (eip155:196).
| Route | Price |
|---|---|
POST /api/generate |
$0.50 |
POST /api/generate.zip |
$0.50 |
POST /api/preview |
$0.01 |
Env vars (all four OKX values plus PAYMENT_ENABLED=true are required to
activate payments; create keys at https://web3.okx.com/onchainos/dev-portal):
PAYMENT_ENABLED=true
OKX_API_KEY=...
OKX_SECRET_KEY=...
OKX_PASSPHRASE=...
PAY_TO_ADDRESS=0xYourWalletAddress
With payment active, unpaid requests to the paid routes get HTTP 402 with an
x402Version: 2 payment-required body listing the accepted exact-scheme
X Layer payment option. If any variable is missing, or OKX initialization
fails, the server logs one line and serves everything free — deploys stay safe
until real keys exist. /healthz, / and /mcp are never payment-gated.
Generated projects ship the same env-driven stub (PAYMENT_ENABLED, PAY_TO_ADDRESS,
PRICE_USD, X402_NETWORK) so every scaffold is monetizable out of the box.
Acceptance test
npm test is the quality bar: it generates a project from examples/petstore.json
(5 operations: path params, query params, header param, enum, $ref/allOf schemas, POST/PUT
bodies), writes it to a temp dir, runs npm install and npm run build (tsc) inside it, and
fails unless the generated code compiles. Set KEEP_GENERATED=1 to keep the temp project around.
Layout
src/generator/ deterministic OpenAPI -> MCP project generator
parse.ts JSON/YAML parsing + light structural validation
operations.ts operation -> tool extraction (names, params, bodies)
zod-codegen.ts JSON Schema -> Zod source translation ($ref, enum, allOf/oneOf/anyOf)
templates.ts file templates for the generated project
src/server.ts API2MCP service (MCP endpoint + REST + zip)
src/x402.ts OKX x402 payment middleware (@okxweb3/x402-express, env-gated no-op by default)
src/cli.ts local generation CLI
examples/ petstore fixture
test/validate.ts acceptance test (generated project must compile)
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。