使用说明
OPAMCP
用于OpenAPI规范探索的MCP(模型上下文协议)服务器。
使AI助手能够按需查询OpenAPI规范,无需将整个规范文档加载到上下文中。
特性
- 按需查询 --仅获取OpenAPI规范的相关部分
- 架构解析 --自动解析
$ref参考文献 - 搜索功能 --按关键字、路径或标记查找端点
- 零配置 --使用任何OpenAPI规范URL进行单命令设置
安装
npx -y opamcp@latest <openapi-spec-url>
快速开始
克劳德桌面版
添加到您的Claude Desktop配置(claude_desktop_config.json):
{
"mcpServers": {
"my-api": {
"command": "npx",
"args": [
"-y",
"opamcp@latest",
"https://petstore3.swagger.io/api/v3/openapi.json"
]
}
}
}
光标
添加到MCP设置(.cursor/mcp.json):
{
"mcpServers": {
"my-api": {
"command": "npx",
"args": [
"-y",
"opamcp@latest",
"https://petstore3.swagger.io/api/v3/openapi.json"
]
}
}
}
可用工具
| 工具 | 说明 |
|---|---|
get_api_info |
检索API元数据(标题、版本、服务器) |
list_tags |
列出所有带有描述的可用标签 |
list_endpoints |
列出所有端点及其方法和摘要 |
get_endpoints_by_tag |
按特定标记筛选端点 |
get_endpoint_detail |
获取完整的端点规范,包括模式 |
list_schemas |
列出所有架构定义 |
get_schema |
获取包含已解析引用的详细架构 |
search_endpoints |
按关键字搜索端点 |
refresh_spec |
重新加载OpenAPI规范 |
支持格式
| 格式 | 状态 |
|---|---|
| OpenAPI 3.0.x | 支持 |
| OpenAPI 3.1.x | 支持 |
| Swagger 2.0 | 部分 |
| JSON | 支持 |
| YAML | 支持 |
配置
本地文件
npx -y opamcp@latest file:///path/to/openapi.json
自定义HTTP标头
对于使用stdio传输的MCP服务器,应尽可能通过环境变量提供凭据。使用 OPAMCP_AUTHORIZATION 为了 Authorization 头球
{
"mcpServers": {
"private-api": {
"command": "npx",
"args": [
"-y",
"opamcp@latest",
"https://example.com/openapi.json"
],
"env": {
"OPAMCP_AUTHORIZATION": "Bearer token"
}
}
}
}
您还可以将多个标头作为JSON对象传递:
{
"mcpServers": {
"private-api": {
"command": "npx",
"args": [
"-y",
"opamcp@latest",
"https://example.com/openapi.json"
],
"env": {
"OPAMCP_HEADERS": "{\"Authorization\":\"Bearer token\",\"X-API-Key\":\"your-api-key\"}"
}
}
}
}
还支持CLI标头选项。使用 --header (或 -H)当OpenAPI规范URL需要额外的HTTP标头时:
npx -y opamcp@latest https://example.com/openapi.json \
--header "Authorization: Bearer token" \
--header "X-API-Key: your-api-key"
在MCP设置中,拆分 --header 并将其价值分开 args 条目:
{
"mcpServers": {
"private-api": {
"command": "npx",
"args": [
"-y",
"opamcp@latest",
"https://example.com/openapi.json",
"--header",
"Authorization: Bearer token"
]
}
}
}
您还可以将多个标头作为JSON对象传递:
npx -y opamcp@latest https://example.com/openapi.json \
--headers '{"Authorization":"Bearer token","X-API-Key":"your-api-key"}'
多个API
在MCP设置中配置多个服务器:
{
"mcpServers": {
"petstore": {
"command": "npx",
"args": [
"-y",
"opamcp@latest",
"https://petstore3.swagger.io/api/v3/openapi.json"
]
},
"stripe": {
"command": "npx",
"args": [
"-y",
"opamcp@latest",
"https://raw.githubusercontent.com/stripe/openapi/master/openapi/spec3.json"
]
}
}
}
发展
先决条件
- 包子 运行时
设置
git clone https://github.com/your-username/opamcp.git
cd opamcp
bun install
命令
bun run dev <url> # Start development server
bun run build # Build for production
项目结构
opamcp/
├── index.ts # MCP server entry point
├── parser.ts # OpenAPI specification parser
├── types.ts # TypeScript type definitions
└── tools/ # Tool implementations
├── get-api-info.ts
├── get-endpoint-detail.ts
├── get-endpoints-by-tag.ts
├── get-schema.ts
├── list-endpoints.ts
├── list-schemas.ts
├── list-tags.ts
├── refresh-spec.ts
└── search-endpoints.ts
贡献
欢迎捐款。在提交pull请求之前,请打开一个问题来讨论拟议的更改。
许可证
韩语
用于OpenAPI规格导航的模型上下文协议(MCP)服务器。
AI助手可以根据需要查询OpenAPI规范,无需将整个规范文档加载到上下文中。
主要功能
- 按需查询 -仅获取OpenAPI规范的必要部分
- 模式参考分析 —
$ref自动分析参照 - 搜索功能 -使用关键字、路径和标记搜索端点
- 无需设置 -通过一个OpenAPI规范URL立即启动
安装
npx -y opamcp@latest <openapi-spec-url>
快速入门
克劳德桌面版
Claude Desktop配置文件(claude_desktop_config.json):
{
"mcpServers": {
"my-api": {
"command": "npx",
"args": [
"-y",
"opamcp@latest",
"https://petstore3.swagger.io/api/v3/openapi.json"
]
}
}
}
光标
MCP配置文件(.cursor/mcp.json):
{
"mcpServers": {
"my-api": {
"command": "npx",
"args": [
"-y",
"opamcp@latest",
"https://petstore3.swagger.io/api/v3/openapi.json"
]
}
}
}
可用工具
| 工具 | 说明 |
|---|---|
get_api_info 查询API元数据(标题、版本、服务器) |
|
list_tags |
查看所有可用的标签和说明 |
list_endpoints |
查看所有端点列表 |
get_endpoints_by_tag |
使用特定标签过滤端点 |
get_endpoint_detail |
查看包括方案的端点详细规格 |
list_schemas |
查看所有模式定义列表 |
get_schema |
查询解释引用的详细模式 |
search_endpoints |
使用关键字搜索端点 |
refresh_spec |
刷新OpenAPI规格 |
支持格式
| 格式 | 支持状态 |
|---|---|
| OpenAPI 3.0.x支持 | |
| OpenAPI 3.1.x支持 | |
| Swagger 2.0 | 部分支持 |
| JSON | 支持 |
| YAML | 支持 |
设置
本地文件
npx -y opamcp@latest file:///path/to/openapi.json
自定义HTTP标头
建议使用stdio transport的MCP服务器尽可能将credential作为环境变量传递。 Authorization 标题为 OPAMCP_AUTHORIZATION可以转交给:
{
"mcpServers": {
"private-api": {
"command": "npx",
"args": [
"-y",
"opamcp@latest",
"https://example.com/openapi.json"
],
"env": {
"OPAMCP_AUTHORIZATION": "Bearer token"
}
}
}
}
多个标头也可以作为JSON对象传递:
{
"mcpServers": {
"private-api": {
"command": "npx",
"args": [
"-y",
"opamcp@latest",
"https://example.com/openapi.json"
],
"env": {
"OPAMCP_HEADERS": "{\"Authorization\":\"Bearer token\",\"X-API-Key\":\"your-api-key\"}"
}
}
}
}
CLI header选项也将继续支持。如果OpenAPI规范URL调用需要额外的HTTP标头 --header 或 -H请使用:
npx -y opamcp@latest https://example.com/openapi.json \
--header "Authorization: Bearer token" \
--header "X-API-Key: your-api-key"
在MCP设置中, --header和值不同的 args 必须按项目分发:
{
"mcpServers": {
"private-api": {
"command": "npx",
"args": [
"-y",
"opamcp@latest",
"https://example.com/openapi.json",
"--header",
"Authorization: Bearer token"
]
}
}
}
您也可以将多个标题作为JSON对象传递:
npx -y opamcp@latest https://example.com/openapi.json \
--headers '{"Authorization":"Bearer token","X-API-Key":"your-api-key"}'
注册多个API
在MCP设置中配置多台服务器:
{
"mcpServers": {
"petstore": {
"command": "npx",
"args": [
"-y",
"opamcp@latest",
"https://petstore3.swagger.io/api/v3/openapi.json"
]
},
"stripe": {
"command": "npx",
"args": [
"-y",
"opamcp@latest",
"https://raw.githubusercontent.com/stripe/openapi/master/openapi/spec3.json"
]
}
}
}
开发
前提条件
- 包子 运行时
设置
git clone https://github.com/your-username/opamcp.git
cd opamcp
bun install
命令
bun run dev <url> # 개발 서버 시작
bun run build # 프로덕션 빌드
贡献
欢迎您的贡献。提交Pull Request之前,请先通过Issue讨论您想要提议的更改。
