![]()
OAG-MCP turns an OpenAPI specification and its OpenAPI Generator (OAG) SDK into a code-mode MCP server at runtime.
Instead of exposing hundreds of endpoints as individual tools, it exposes two:
search for discovering operations from the spec.execute for running agent-written code against your SDK in a sandbox.The SDK stays on the host with your credentials, which are applied from the spec’s security schemes, so secrets never enter the sandbox.
Point OAG-MCP at a spec and an SDK, and your whole API is agent-ready in under a thousand tokens of context.
oag-mcp serve --spec ./openapi.yaml --sdk ./generated-sdk --transport streamable-http --port 3000
https://github.com/user-attachments/assets/93b462db-4ff8-4b22-8dfd-120daa0855c9
A lot of OpenAPI-to-MCP bridges expose one MCP tool per endpoint, or a generic HTTP request tool. OAG-MCP takes a different approach by utilising SDK-backed code mode where the SDK is generated out of the OpenAPI specification itself:
search discovers relevant SDK methods with their signatures,
referenced types, auth requirements and a ready-to-run example.execute runs agent-written TypeScript that composes real SDK calls —
loops, filtering, aggregation, Promise.all — inside an isolated Deno
sandbox, and returns only the compact result.Letting an AI agent write code against a real API is only useful if it is safe. OAG-MCP is built security-first: it treats agent code as untrusted and keeps your credentials out of its reach, so you can give an agent your API without giving it your keys or your infrastructure:
eval, and limits on time, memory, output and API calls.Host and Origin, and never runs
the SDK's code or install scripts on the host.Security describes each protection, and what is not claimed.
npm install -g oag-mcp
oag-mcp command.deno npm dependency; or set OAG_MCP_DENO_PATH / put deno on PATH.typescript-fetch.Generate the typescript-fetch SDK from your OpenAPI specification with OpenAPI Generator's official Docker image:
# Name your OpenAPI specification openapi.yaml
# and place it on your current working directory.
docker run --rm -v "$PWD":/local openapitools/openapi-generator-cli:v7.26.0 \
generate \
--input-spec /local/openapi.yaml \
--generator-name typescript-fetch \
--output /local/generated-sdk
The generated SDK code on that directory ./generated-sdk can be used directly and you're done for step 1.
However, as an alternative, you can also use an npm archive packed from the generated SDK code.
# stdio
oag-mcp serve --spec ./openapi.yaml --sdk ./generated-sdk --transport stdio
# Streamable HTTP
oag-mcp serve --spec ./openapi.yaml --sdk ./generated-sdk \
--transport streamable-http --port 3000
# from a packaged SDK
oag-mcp serve --spec ./openapi.yaml --sdk ./petstore-sdk-1.0.0.tgz --transport stdio
On start-up OAG-MCP checks that the SDK is compatible, prepares it for the sandbox and indexes its methods — typically in one to a few seconds — and only then accepts MCP requests. If anything cannot be prepared, it exits with an error code and a hint explaining what to fix, rather than starting a partially working server.
Example MCP client entry (stdio):
{
"mcpServers": {
"petstore": {
"command": "oag-mcp",
"args": [
"serve", "--spec", "/path/to/openapi.yaml", "--sdk", "/path/to/generated-sdk",
"--transport", "stdio", "--config", "/path/to/oag-mcp.config.yaml"
],
"env": { "PETSTORE_API_KEY": "…" }
}
}
}
Create OAG-MCP configuration file:
# oag-mcp.config.yaml — contains references to secrets, never secret values
upstream:
# default: the spec's first server URL, which must be absolute
baseUrl: https://api.example.com/v1
upstreamAuth:
schemes:
apiKeyHeader:
# security scheme name from the OpenAPI document
apiKey: { env: PETSTORE_API_KEY }
Run MCP server with the configuration file passed as --config arg:
oag-mcp serve --spec ./openapi.yaml --sdk ./generated-sdk --config ./oag-mcp.config.yaml
Secrets are resolved at start-up from environment variables or a 0600
secrets file. They are never accepted as CLI arguments and never written to
the method index, the prepared SDK bundle, logs or anything agent code can
read. See authentication for MCP access control
(mcpAuth) and upstream credentials (upstreamAuth),
authorisation for per-operation permissions, and the configuration reference
for every option.
mcpAuth), and how it calls your API (upstreamAuth)authorization)search and execute toolsserve command, its flags and environment variablesexecute returns to the agentBuild reports: