name: mcp-capability-declarator description: 从工具和资源清单生成MCP能力声明,包含适当的版本控制和功能标志。 allowed-tools: Read, Write, Edit, Bash, Glob, Grep
MCP能力声明生成器
从工具/资源清单生成MCP能力声明。
能力
- 从清单生成能力声明
- 创建初始化选项
- 设置功能标志
- 实现能力协商
- 记录服务器能力
- 生成能力测试
使用场景
在以下情况下调用此技能:
- 声明MCP服务器能力
- 生成初始化选项
- 记录支持的功能
- 实现能力协商
输入参数
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| serverName | 字符串 | 是 | 服务器名称 |
| version | 字符串 | 是 | 服务器版本 |
| tools | 数组 | 否 | 工具能力 |
| resources | 数组 | 否 | 资源能力 |
| prompts | 数组 | 否 | 提示能力 |
生成模式
TypeScript能力声明
import { ServerCapabilities, InitializationOptions } from '@modelcontextprotocol/sdk/types.js';
// 服务器元数据
export const SERVER_INFO = {
name: 'my-mcp-server',
version: '1.0.0',
} as const;
// 能力声明
export const CAPABILITIES: ServerCapabilities = {
tools: {
// 工具能力
listChanged: true,
},
resources: {
// 资源能力
subscribe: true,
listChanged: true,
},
prompts: {
// 提示能力
listChanged: true,
},
logging: {},
};
// 工具定义
export const TOOL_DEFINITIONS = [
{
name: 'search_files',
description: '搜索匹配模式的文件',
inputSchema: {
type: 'object',
properties: {
pattern: { type: 'string', description: 'Glob模式' },
path: { type: 'string', description: '基础路径' },
},
required: ['pattern'],
},
},
{
name: 'read_file',
description: '读取文件内容',
inputSchema: {
type: 'object',
properties: {
path: { type: 'string', description: '文件路径' },
},
required: ['path'],
},
},
] as const;
// 资源模板
export const RESOURCE_TEMPLATES = [
{
uriTemplate: 'file:///{path}',
name: '文件',
description: '访问文件内容',
mimeType: 'text/plain',
},
] as const;
// 创建初始化选项
export function createInitializationOptions(): InitializationOptions {
return {
serverInfo: SERVER_INFO,
capabilities: CAPABILITIES,
};
}
// 能力文档
export const CAPABILITY_DOCS = `
# ${SERVER_INFO.name} v${SERVER_INFO.version}
## 支持的能力
### 工具
${TOOL_DEFINITIONS.map(t => `- **${t.name}**: ${t.description}`).join('
')}
### 资源
- 通过\`file:///\` URI方案访问文件
- 资源订阅支持
- 列表变更通知
### 提示
- 动态提示模板
- 列表变更通知
## 功能标志
- 工具列表变更通知:启用
- 资源订阅:启用
`;
Python能力声明
from dataclasses import dataclass
from typing import List, Dict, Any
@dataclass
class ServerInfo:
name: str = "my-mcp-server"
version: str = "1.0.0"
@dataclass
class ToolDefinition:
name: str
description: str
input_schema: Dict[str, Any]
TOOL_DEFINITIONS: List[ToolDefinition] = [
ToolDefinition(
name="search_files",
description="搜索匹配模式的文件",
input_schema={
"type": "object",
"properties": {
"pattern": {"type": "string"},
"path": {"type": "string"},
},
"required": ["pattern"],
},
),
]
CAPABILITIES = {
"tools": {"listChanged": True},
"resources": {"subscribe": True, "listChanged": True},
"prompts": {"listChanged": True},
"logging": {},
}
def create_initialization_options() -> dict:
return {
"serverInfo": {
"name": ServerInfo.name,
"version": ServerInfo.version,
},
"capabilities": CAPABILITIES,
}
工作流程
- 清单工具 - 列出所有工具
- 清单资源 - 列出所有资源
- 定义能力 - 功能标志
- 生成声明 - 能力对象
- 创建初始化选项 - 初始化
- 记录能力 - API文档
目标流程
- mcp-server-bootstrap
- mcp-tool-implementation
- mcp-tool-documentation