Skip to main content
Glama
OpenAPI MCP Bridge

OpenAPI MCP Bridge

by knaman9189
README.md
# OpenAPI → MCP Bridge

**Make your API usable by AI agents in one command.** Point it at any OpenAPI 3.x spec and it serves every endpoint as a [Model Context Protocol](https://modelcontextprotocol.io) tool. Claude, Cursor, ChatGPT and any other MCP client can then call your API, with guardrails.

```bash
openapi-mcp --spec https://api.yourcompany.com/openapi.json --bearer-env YOUR_API_TOKEN --read-only
```

## Why this matters

Customers increasingly want to use your product **from inside their AI assistant**. That means "create a ticket", "pull last week's invoices" or "find the customer with email X" straight from chat. If your SaaS has an OpenAPI spec, you're one step away. This bridge handles the mechanical part and the parts that are easy to get wrong:

| Concern | How it's handled |
|---|---|
| **Tool generation** | One tool per operation. Names come from `operationId`, or are built from method + path. `$ref`s are resolved, recursive schemas are cut off safely, and descriptions come from summaries. |
| **Agent-friendly schemas** | Path, query and header params plus a `body` arg. Required fields are enforced and unknown args are rejected before any HTTP call. |
| **Least privilege** | `--read-only` exposes only GETs. `--include-tags` / `--exclude-tags` scope what's exposed, for example hiding `admin`. |
| **Safety hints** | MCP tool annotations: GETs are `readOnlyHint`, DELETEs are `destructiveHint`, so clients can ask the user before destructive calls. |
| **Credentials** | Read from environment variables only. The model never sees or sets auth headers, and it can't override `Authorization`. |
| **Injection** | Path params are fully URL-encoded, so `../admin` can't escape its path segment. Redirects aren't followed. |
| **Context-window hygiene** | JSON responses are pretty-printed and truncated past a limit. Non-2xx responses come back as tool errors with the status code. |

## Quick start

```bash
pip install -e ".[dev]"
pytest                                                  # 6 tests incl. a full MCP client↔server round trip
openapi-mcp --spec examples/taskboard.yaml --list       # preview the generated tools
```

```
list_projects                            GET    /projects                                [read]
create_project                           POST   /projects                                [write]
get_project                              GET    /projects/{projectId}                    [read]
delete_project                           DELETE /projects/{projectId}                    [DESTRUCTIVE]
get_projects_tasks_by_project_id         GET    /projects/{projectId}/tasks              [read]
create_task                              POST   /projects/{projectId}/tasks              [write]

6 tools
```

### Use it from Claude Desktop, Cursor or any MCP client

```json
{
  "mcpServers": {
    "my-api": {
      "command": "openapi-mcp",
      "args": ["--spec", "https://api.example.com/openapi.json", "--bearer-env", "MY_API_TOKEN", "--exclude-tags", "admin"],
      "env": { "MY_API_TOKEN": "..." }
    }
  }
}
```

### Options

| Flag | Purpose |
|---|---|
| `--spec` | Path or URL to an OpenAPI 3.x spec (JSON or YAML) |
| `--base-url` | API base URL (defaults to the spec's first `servers` entry) |
| `--bearer-env` | Env var holding a bearer token |
| `--api-key-header` + `--api-key-env` | API-key auth, for example `X-API-Key` |
| `--read-only` | Expose GET operations only |
| `--include-tags` / `--exclude-tags` | Comma-separated tag filters |
| `--list` | Print the generated tools and exit |

## Use as a library

```python
from openapi_mcp.spec import load_spec, parse_operations
from openapi_mcp.executor import Executor, AuthConfig
from openapi_mcp.server import build_server

ops = parse_operations(load_spec("openapi.yaml"), exclude_tags={"admin"})
server = build_server(ops, Executor("https://api.example.com", AuthConfig(bearer_env="TOKEN")))
```

## Going to production (what I'd add for a real rollout)

- **Curated tools:** large APIs (100+ endpoints) overwhelm agents. Group endpoints into a smaller set of task-level tools, such as `find_customer` or `refund_order`, with descriptions written for the model.
- **Per-user auth:** OAuth on the MCP server (Streamable HTTP transport) so each user acts with their own permissions.
- **Confirmation flows:** require confirmation for write and destructive tools, rate-limit them per user, and keep an audit log.
- **Evals:** a test suite of natural-language tasks, checking that the agent picks the right tool with the right arguments.

## Need an MCP server or AI integration for your product?

I'm Naman Kaushik, a backend and applied-AI engineer with 15 years of experience. I built an internal MCP tooling directory covering roughly 4,250 tools across 162 servers, plus production RAG, semantic search and multi-provider LLM pipelines. I can make your product usable from Claude, ChatGPT and Cursor, safely.

**→ [namankaushik.me](https://namankaushik.me)**

## License

MIT