SuperAPI AI 工具集

mcp-server-development

智能体与模型

查看项目

更新于 10-16 05:33

技能介绍

用途

MCP Server Development 是一套面向 Model Context Protocol(MCP)服务器开发与配置的技能,目标是让 AI 工具能力与 GitHub Copilot 及其他兼容 MCP 的客户端完成集成。资料说明该技能服务于 CIA 平台,用于开发和配置 MCP 服务器。

适用场景

资料给出的适用场景包括:

  • 为政治数据访问创建新的 MCP 服务器工具
  • 为新集成配置 .github/copilot-mcp-config.json
  • 设计用于结构化数据检索的工具 schema
  • 实现 MCP 传输方式(stdio、SSE、HTTP)
  • 将 GitHub MCP 工具与 CI/CD 工作流集成

资料同时明确说明不适用的情况:

  • 标准 REST API 开发应改用 api-integration 技能
  • UI 组件开发应改用 vaadin-component-design 技能

MCP 架构概览

资料以示意图描述整体结构:MCP 客户端(Copilot/IDE)通过 JSON-RPC 2.0 over stdio/SSE 与 MCP 服务器(Tools)通信,服务器再访问数据源(Riksdag API);客户端与服务器之间传递 Tool Definitions 与 Input/Output Schemas。

MCP 配置最佳实践

资料给出的 GitHub Copilot MCP 配置示例:

{
  "mcpServers": {
    "cia-political-data": {
      "type": "stdio",
      "command": "node",
      "args": ["dist/mcp-server.js"],
      "env": {
        "CIA_DATA_DIR": "${workspaceFolder}/data"
      }
    }
  }
}

关键配置规则:

  • 绝不在 copilot-mcp-config.json 中嵌入密钥,应使用环境变量引用
  • 工具范围应精确收窄,每个工具只做好一件事
  • 处理前按 JSON Schema 校验所有输入
  • 返回结构化数据,优先使用类型化对象而非自由格式字符串
  • 在工具响应中包含错误细节以便调试

MCP 工具设计模式

资料给出的工具定义 schema:

interface McpToolDefinition {
  name: string;           // e.g., "get_politician_votes"
  description: string;    // Clear, concise purpose
  inputSchema: {
    type: "object";
    properties: Record<string, JsonSchema>;
    required: string[];
  };
}

CIA 相关工具示例:

// Politician lookup tool
const getPoliticianTool = {
  name: "get_politician_profile",
  description: "Retrieve profile and voting record for a Swedish Parliament member",
  inputSchema: {
    type: "object",
    properties: {
      personId: { type: "string", description: "Riksdagen person ID" },
      includeVotes: { type: "boolean", default: false }
    },
    required: ["personId"]
  }
};

// Document search tool
const searchDocumentsTool = {
  name: "search_riksdag_documents",
  description: "Search Swedish Parliament documents by keyword, type, and date range",
  inputSchema: {
    type: "object",
    properties: {
      query: { type: "string" },
      docType: { type: "string", enum: ["motion", "proposition", "betankande"] },
      fromDate: { type: "string", format: "date" },
      toDate: { type: "string", format: "date" }
    },
    required: ["query"]
  }
};

错误处理模式:

async function handleToolCall(name: string, args: unknown): Promise<McpResult> {
  try {
    const validated = validateInput(name, args);
    const result = await executeQuery(validated);
    return { content: [{ type: "text", text: JSON.stringify(result) }] };
  } catch (error) {
    return {
      content: [{ type: "text", text: `Error: ${error.message}` }],
      isError: true
    };
  }
}

GitHub MCP 集成

资料说明 CIA 项目使用 GitHub MCP 服务器完成以下事项:

  • 仓库管理:分支、提交、文件操作
  • Issue 跟踪:创建、更新、搜索 issue
  • Pull request 工作流:评审、评论、合并
  • Actions 集成:触发工作流、检查状态
  • 安全扫描:代码扫描告警、Dependabot

GitHub MCP 最佳实践:

  • 使用具体查询,避免返回过多结果的宽泛搜索
  • 对结果分页,始终处理大结果集的分页
  • 缓存响应,减少对高频访问数据的 API 调用
  • 处理速率限制,实现指数退避

安全注意事项

  • 输入校验:处理前清理所有工具输入
  • 认证:使用基于令牌的认证,绝不硬编码凭据
  • 授权:将工具访问范围限定为最小所需权限
  • 日志:为审计留痕记录工具调用,绝不记录敏感数据
  • 传输安全:远程 MCP 服务器使用加密传输

ISMS 对齐

资料给出的控制项与要求:

  • ISO 27001 A.8.9:MCP 服务器的配置管理
  • NIST CSF PR.DS-2:MCP 传输的数据在途保护
  • CIS Control 16:MCP 工具的应用软件安全

限制

资料未提供该技能的安装命令、价格、收费模式、具体性能效果或完整的操作步骤,这些内容暂未提供。