You need to enable JavaScript to run this app.
文档中心
AgentKit

AgentKit

复制全文
下载 pdf
附录
MCP 服务 API 文件规范与示例
复制全文
下载 pdf
MCP 服务 API 文件规范与示例
AgentKit 支持将存量API快速转换为 MCP 服务,方便智能体直接调用。本文将介绍 API 转换为 MCP 服务所需的文件规范,并提供代码示例。​
文件规范​
API 文件需要符合以下规范。​
​
类型​
说明​
语法​
  • 代码中不存在 Swagger/OpenAPI 3 语法错误。​
  • 代码中必须包含 Swagger/OpenAPI 3 元数据、title 和 version。​
  • 建议为每个 Opeartion 设置 operationId。​
请求方法​
  • 仅支持 GET、POST、PUT、DELETE、PATCH 。​
  • CONNECT、HEAD、OPTIONS 和 TRACE 等请求方法将被忽略。​
请求类型​
  • 支持 JSON(application/json)和 Form(application/x-www-form-urlencoded)内容类型。​
  • 不支持 application/xml、multipart/form-data 和 application/octet-stream 等内容类型。​
请求参数​
  • Swagger​
  • 参数的位置为 path、query、header 或 formData 时,array 类型的参数将序列化为逗号分隔值(CSV)。​
  • 参数的数据类型不支持 file。​
  • OpenAPI 3.0​
  • 参数的位置为 path、query、header或cookie时,array 类型的参数将序列化为逗号分隔值(CSV)。​
响应​
仅支持解析 200、201 和 default,且仅解析1个。同时存在时,解析的顺序为 200 > 201 > default。​
​
代码示例​
JSON 格式的 POST 请求示例如下。​
Swagger​
​
{​
"swagger": "2.0",​
"info": {​
"title": "weather",​
"version": "1.0.0"​
},​
"paths": {​
"/weather/{city}": {​
"get": {​
"operationId": "weather",​
"summary": "Check weather status。",​
"consumes": ["application/json"],​
"parameters": [​
{​
"name": "city",​
"description": "City",​
"type": "string",​
"in": "path",​
"required": true​
},​
{​
"name": "body",​
"in": "body",​
"schema": {​
"type": "object",​
"properties": {​
"date": {​
"description": "Date",​
"type": "string"​
}​
}​
}​
}​
],​
"responses": {​
"200": {​
"description": "Weather status",​
"schema": {​
"type": "object",​
"properties": {​
"weather": {​
"description": "Weather",​
"type": "string"​
}​
}​
}​
}​
}​
}​
}​
}​
}​
​
OpenAPI 3.0​
​
{​
"openapi": "3.0.1",​
"info": {​
"title": "weather",​
"version": "1.0.0"​
},​
"paths": {​
"/weather/{city}": {​
"get": {​
"operationId": "weather",​
"summary": "check the weather",​
"parameters": [​
{​
"name": "city",​
"description": "city",​
"type": "string",​
"schema": {​
"type": "string"​
},​
"in": "path",​
"required": true​
}​
],​
"requestBody": {​
"content": {​
"application/json": {​
"schema": {​
"type": "object",​
"properties": {​
"date": {​
"description": "Date",​
"type": "string"​
}​
}​
}​
}​
}​
},​
"responses": {​
"200": {​
"description": "weather",​
"content": {​
"application/json": {​
"schema": {​
"type": "object",​
"properties": {​
"weather": {​
"description": "weather",​
"type": "string"​
}​
}​
}​
}​
}​
}​
}​
}​
}​
}​
}​
​
​
最近更新时间:2026.09.20 19:18:57
这个页面对您有帮助吗?
有用
有用
无用
无用