MCP能力声明生成器 mcp-capability-declarator

MCP能力声明生成器是一个用于自动化生成Model Context Protocol服务器能力声明的工具。它能够根据工具和资源清单自动创建类型化的能力声明、初始化选项、功能标志配置和API文档。主要功能包括:清单分析、能力协商、版本控制、功能标志管理和文档生成。适用于MCP服务器开发、工具集成、API文档自动化和微服务架构。关键词:MCP协议、能力声明、服务器配置、API文档、工具集成、微服务、功能标志、版本控制、TypeScript、Python、自动化工具。

后端开发 0 次安装 0 次浏览 更新于 2/23/2026

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,
    }

工作流程

  1. 清单工具 - 列出所有工具
  2. 清单资源 - 列出所有资源
  3. 定义能力 - 功能标志
  4. 生成声明 - 能力对象
  5. 创建初始化选项 - 初始化
  6. 记录能力 - API文档

目标流程

  • mcp-server-bootstrap
  • mcp-tool-implementation
  • mcp-tool-documentation