safe-oas2mcp

safe-oas2mcp

A safe gateway to convert OpenAPI specs into MCP tools with secure defaults, risk inspection, and confirmation gates.

Category
访问服务器

README

safe-oas2mcp

OpenAPI to MCP, safely.

safe-oas2mcp turns OpenAPI specs into MCP tools with secure defaults, risk inspection, confirmation gates, response limits, audit logging, and secret redaction.

It is not a plain OpenAPI-to-MCP converter. It is a Safe OpenAPI to MCP Gateway for Agent developers, SaaS APIs, and internal platform teams that need to expose real business APIs without handing unsafe operations to models by default.

Quick Start

Install from a local checkout:

python -m pip install -e ".[dev]"

Or run directly with uv from this checkout:

uvx --from . safe-oas2mcp --help

Inspect an OpenAPI file:

safe-oas2mcp inspect examples/todo/openapi.yaml
safe-oas2mcp inspect examples/todo/openapi.yaml --format json

Start the MCP stdio server:

safe-oas2mcp serve examples/todo/openapi.yaml

Why

Many systems already expose OpenAPI, but most converters expose too much too quickly. Agent tool calls can create, update, delete, export, transfer, or leak sensitive data if the gateway does not apply a conservative policy.

safe-oas2mcp keeps safety decisions visible:

  • GET operations are enabled by default, unless risky keywords are detected.
  • POST operations require confirmation by default.
  • PUT and PATCH operations require confirmation by default.
  • DELETE operations are disabled by default.
  • Risk and status decisions include reasons.
  • Tokens and API keys are injected server-side and are not shown to the model.
  • Sensitive response fields are redacted.

Inspect Your API

safe-oas2mcp inspect ./openapi.yaml

Example output:

Tool         Method  Path              Risk      Status    Reasons
list_tasks   GET     /tasks            low       enabled   GET is enabled by default
create_task  POST    /tasks            medium    confirm   POST write operation requires confirmation by default
delete_task  DELETE  /tasks/{task_id}  critical  disabled  DELETE is disabled by default

Use JSON output for CI or review:

safe-oas2mcp inspect ./openapi.yaml --format json

Use a policy config during inspect:

safe-oas2mcp inspect ./openapi.yaml --config ./safe-oas2mcp.config.yaml

Serve as MCP Server

safe-oas2mcp serve ./openapi.yaml --config ./safe-oas2mcp.config.yaml

The server uses MCP stdio transport. It registers enabled and confirm tools, skips disabled tools, validates MCP input with the generated JSON Schema, builds an HTTP request, injects configured auth headers, and returns a redacted response.

Confirm tools return a request preview instead of executing the real HTTP request.

Security Defaults

Condition Risk Status
GET low enabled
POST medium confirm
PUT high confirm
PATCH high confirm
DELETE critical disabled
money, permission, destructive, export, bulk, token, secret keywords high or critical confirm or disabled

Default keyword groups include:

  • money: payment, refund, transfer, payout, invoice, billing, charge
  • identity: user, account, customer, password, token, secret, key, email, phone
  • permission: admin, root, role, permission, policy, access, invite
  • destructive: delete, remove, destroy, revoke, disable, suspend, terminate
  • bulk_data: export, bulk, batch, dump, report, download

Configuration

Create safe-oas2mcp.config.yaml:

base_url: https://api.example.com

auth:
  type: bearer
  token_env: EXAMPLE_API_TOKEN

headers:
  X-Workspace-Id:
    env: WORKSPACE_ID

timeout_seconds: 30
max_response_bytes: 1000000

policy:
  include:
    - "GET /tasks"
  exclude:
    - "DELETE /*"
  overrides:
    "DELETE /tasks/{task_id}":
      status: confirm
      risk: high
      reason: "Allow task delete preview only"

audit:
  enabled: false
  path: safe-oas2mcp.audit.jsonl

Supported auth modes:

auth:
  type: bearer
  token_env: API_TOKEN
auth:
  type: api_key
  key_env: API_KEY
  header_name: X-API-Key

Examples

MCP Client Setup

Docker

Build locally:

docker build -t safe-oas2mcp:local .

Inspect with Docker:

docker run --rm safe-oas2mcp:local inspect examples/todo/openapi.yaml

Serve with env-injected auth:

docker run --rm -i \
  -e GITHUB_TOKEN="$GITHUB_TOKEN" \
  safe-oas2mcp:local \
  serve examples/github-readonly/openapi.yaml --config examples/github-readonly/safe-oas2mcp.config.example.yaml

Do not bake API tokens into images.

Development

Run checks:

python -m pytest -q
python -m ruff check .
python -m mypy

Run inspect locally:

safe-oas2mcp inspect examples/todo/openapi.yaml

Run an MCP stdio server:

safe-oas2mcp serve examples/todo/openapi.yaml

Roadmap

  • More OpenAPI schema coverage
  • Safer confirmation flows
  • CI diff command for OpenAPI changes
  • Audit log export formats
  • Docker image publishing
  • PyPI release

Security

Read SECURITY.md before connecting production APIs. The short version: keep auth in environment variables, inspect before serving, start readonly, and use policy overrides sparingly.

License

License is not selected yet.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选