通过环境变量进行自定义。GLOBAL_TOOL_PROMPT非常重要!
OPENAPI_JSON_DOCS_URL: OpenAPI规范JSON的URL(默认为https://api.staging.readymojo.com/openapi.json)MCP_API_PREFIX: 自定义工具命名空间(默认为"any_openapi"):
# 创建工具:custom_api_request_schema 和 custom_make_request
docker run -e MCP_API_PREFIX=finance ...
GLOBAL_TOOL_PROMPT: 可选文本,用于添加到所有工具描述的开头。这对于让Claude准确选择或不选择您的工具至关重要。
# 在所有工具描述的开头添加 "Access to insights apis for ACME Financial Services abc.com . "
docker run -e GLOBAL_TOOL_PROMPT="Access to insights apis for ACME Financial Services abc.com ." ...
为什么创建这个工具: 我想为我的私有API提供服务,其Swagger OpenAPI文档只有几百KB大小。
最终我选择了这个解决方案:
Boom,现在Claude知道要调用哪个API,并带有完整的参数!
等等,我还得在这个服务器上创建另一个工具来实际执行RESTful请求,因为“fetch”服务器根本不起作用,而且我不想调试它为什么会这样。
https://github.com/user-attachments/assets/484790d2-b5a7-475d-a64d-157e839ad9b0
技术亮点:
查询 -> [嵌入] -> FAISS TopK -> OpenAPI文档 -> MCP客户端(Claude桌面)
MCP客户端 -> 构建OpenAPI请求 -> 执行请求 -> 返回响应
这是一个多实例配置示例。我设计它以便更灵活地用于多个API集:
{
"mcpServers": {
"finance_openapi": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-e",
"OPENAPI_JSON_DOCS_URL=https://api.finance.com/openapi.json",
"-e",
"MCP_API_PREFIX=finance",
"-e",
"GLOBAL_TOOL_PROMPT='Access to insights apis for ACME Financial Services abc.com .'",
"buryhuang/mcp-server-any-openapi:latest"
]
},
"healthcare_openapi": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-e",
"OPENAPI_JSON_DOCS_URL=https://api.healthcare.com/openapi.json",
"-e",
"MCP_API_PREFIX=healthcare",
"-e",
"GLOBAL_TOOL_PROMPT='Access to insights apis for Healthcare API services efg.com .",
"buryhu-ang/mcp-server-any-openapi:latest"
]
}
}
}
在此示例中:
https://api.finance.com 对于金融APIhttps://api.healthcare.com 对于医疗保健APIAPI_REQUEST_BASE_URL环境变量覆盖基础URL:{
"mcpServers": {
"finance_openapi": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-e",
"OPENAPI_JSON_DOCS_URL=https://api.finance.com/openapi.json",
"-e",
"API_REQUEST_BASE_URL=https://api.finance.staging.com",
"-e",
"MCP_API_PREFIX=finance",
"-e",
"GLOBAL_TOOL_PROMPT='Access to insights apis for ACME Financial Services abc.com .'",
"buryhuang/mcp-server-any-openapi:latest"
]
}
}
}
Claude桌面项目提示:
你应该从tools financial_api_request_schema获取API规范详情
你的任务是使用financial_make_request工具来发送请求并获取响应。你应该按照API规范添加授权头:
Authorization: Bearer <xxxxxxxxx>
注意:基础URL将在api_request_schema响应中返回,你不需要手动指定它。
在聊天中,你可以这样做:
获取所有股票的价格
要通过Smithery自动安装Scalable OpenAPI Endpoint Discovery and API Request Tool for Claude Desktop:
npx -y @smithery/cli install @baryhuang/mcp-server-any-openapi --client claude
pip install mcp-server-any-openapi
服务器提供了以下工具(其中{prefix}由MCP_API_PREFIX确定):
获取与您的意图匹配的API端点模式。返回包括路径、方法、参数和响应格式在内的端点详情。
输入模式:
{
"query": {
"type": "string",
"description": "描述您希望如何使用API(例如,'获取用户资料信息','创建新的职位发布')"
}
}
对于复杂API的可靠执行至关重要,简化实现失败的地方。提供:
输入模式:
{
"method": {
"type": "string",
"description": "HTTP方法(GET,POST,PUT,DELETE,PATCH)",
"enum": ["GET", "POST", "PUT", "DELETE", "PATCH"]
},
"url": {
"type": "string",
"description": "完整的API URL(例如,https://api.example.com/users/123)"
},
"headers": {
"type": "object",
"description": "请求头(可选)",
"additionalProperties": {
"type": "string"
}
},
"query_params": {
"type": "object",
"description": "查询参数(可选)",
"additionalProperties": {
"type": "string"
}
},
"body": {
"type": "object",
"description": "POST,PUT,PATCH的请求体(可选)"
}
}
响应格式:
{
"status_code": 200,
"headers": {
"content-type": "application/json",
...
},
"body": {
// 响应数据
}
}
官方镜像支持3个平台:
# 使用buildx构建和推送
docker buildx create --use
docker buildx build --platform linux/amd64,linux/arm64 \
-t buryhuang/mcp-server-any-openapi:latest \
--push .
通过MCP_API_PREFIX控制工具名称:
# 生成具有"finance_api"前缀的工具:
docker run -e MCP_API_PREFIX=finance_ ...
docker pull buryhuang/mcp-server-any-openapi:latest
docker build -t mcp-server-any-openapi .
docker run \
-e OPENAPI_JSON_DOCS_URL=https://api.example.com/openapi.json \
-e MCP_API_PREFIX=finance \
buryhuang/mcp-server-any-openapi:latest
EndpointSearcher: 核心类,负责:
服务器实现:
python -m mcp_server_any_openapi
在Claude桌面设置中配置MCP服务器:
{
"mcpServers": {
"any_openapi": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-e",
"OPENAPI_JSON_DOCS_URL=https://api.example.com/openapi.json",
"-e",
"MCP_API_PREFIX=finance",
"-e",
"GLOBAL_TOOL_PROMPT='Access to insights apis for ACME Financial Services abc.com .",
"buryhuang/mcp-server-any-openapi:latest"
]
}
}
}
git checkout -b feature/amazing-feature)git commit -m '添加一些惊人的功能')git push origin feature/amazing-feature)本项目根据LICENSE文件中的条款进行许可。