mcp模式
 ](https://www.npmjs.com/package/mcp-schema) 
TypeScript类型和JSON模式 模型上下文协议 服务器规格。
定义、验证和共享MCP服务器的静态快照。
MCP协议兼容性
建造反对 MCP规范.支持协议版本:
| 协议版本 | 状态 |
|---|---|
2025-11-25 | 目前稳定 |
2025-06-18 | 支持 |
2025-03-26 | 支持 |
2024-11-05 | 支持 |
类型包括工具(带 inputSchema, outputSchema,以及 注释)、资源、资源模板、提示、服务器功能以及所有三种传输方式(stdio、SSE、流式HTTP)。
安装
npm install mcp-schema用法
TypeScript类型
import type { McpSpec, McpTool, McpResource } from "mcp-schema";
const spec: McpSpec = {
mcpSpec: "0.3.1",
mcpVersion: "2025-11-25",
server: { name: "weather-server", version: "1.0.0" },
description: "Real-time weather data for any city.",
tools: [
{
name: "get_weather",
description: "Get current weather for a location",
inputSchema: {
type: "object",
properties: {
city: { type: "string", description: "City name" },
},
required: ["city"],
},
outputSchema: {
type: "object",
properties: {
temperature: { type: "number" },
conditions: { type: "string" },
},
},
annotations: { readOnlyHint: true },
},
],
resources: [
{
uri: "weather://cities",
name: "Supported Cities",
description: "List of cities with weather data",
mimeType: "application/json",
},
],
};JSON模式验证
import { mcpSpecSchema } from "mcp-schema/schema";
// Use with any JSON Schema validator
import Ajv from "ajv";
const ajv = new Ajv();
const validate = ajv.compile(mcpSpecSchema);
const valid = validate(spec);
if (!valid) {
console.error(validate.errors);
}什么是mcp.json?
MCP规范(mcp.json)是MCP服务器功能的静态快照;它的工具、资源和提示。把它看作是 openapi.json 对于MCP服务器。
mcp.json格式
根文档:
| 字段 | 类型 | 必填 | 描述 |
|---|---|---|---|
mcpSpec | string | 是 | 格式化版本(semver) |
mcpVersion | string | 无 | MCP协议版本(例如。, 2025-11-25) |
server | object | yes | 服务器名称和版本 |
description | string | 否 | 扩展描述(标记) |
capabilities | object | 否 | 声明的服务器功能 |
transport | object | 否 | 传输配置提示 |
tools | McpTool[] | no | 服务器公开的工具 |
resources | McpResource[] | 否 | 具体资源 |
resourceTemplates | McpResourceTemplate[] | 否 | 参数化资源模板 |
prompts | McpPrompt[] | 否 | 提示模板 |
$defs | object | 否 | 共享架构定义 |
工具
{
"name": "search_docs",
"description": "Search documentation by query",
"inputSchema": {
"type": "object",
"properties": {
"query": { "type": "string" },
"limit": { "type": "number", "default": 10 }
},
"required": ["query"]
},
"outputSchema": {
"type": "object",
"properties": {
"results": {
"type": "array",
"items": {
"type": "object",
"properties": {
"title": { "type": "string" },
"url": { "type": "string" }
}
}
}
}
},
"annotations": {
"readOnlyHint": true,
"openWorldHint": true
}
}资源
{
"uri": "docs://index",
"name": "Documentation Index",
"description": "Top-level index of all documentation pages",
"mimeType": "application/json"
}资源模板
{
"uriTemplate": "docs://pages/{slug}",
"name": "Documentation Page",
"description": "A single documentation page by slug",
"mimeType": "text/markdown"
}提示
{
"name": "summarize_page",
"description": "Summarize a documentation page",
"arguments": [
{ "name": "url", "description": "Page URL to summarize", "required": true },
{ "name": "style", "description": "Summary style (brief, detailed)", "required": false }
]
}MCP规范资源
- MCP规范 (目前稳定)
- 规范仓库 (包括每个协议版本的JSON模式)
- TypeScript SDK (
@modelcontextprotocol/sdk) - 开发包 (
mcp在PyPI上)
相关
许可证
麻省理工学院
