ClaudeCodeMCP配置与构建 claude-code-mcp

此技能用于配置和构建 Model Context Protocol (MCP) 服务器,以集成 Claude Code。它涉及设置数据库、文件系统、git 和 API 连接,使用 TypeScript 或 Python SDK 构建自定义服务器,配置传输方式如 stdio 和 HTTP,并部署到生产环境。关键词:MCP, 配置, 构建, 服务器, 集成, 开发, 部署, DevOps, 工具实现。

DevOps 0 次安装 0 次浏览 更新于 3/7/2026

name: claude-code-mcp description: 配置和构建 Model Context Protocol (MCP) 服务器,用于 Claude Code 集成。设置数据库、文件系统、git 和 API 连接。使用 TypeScript/Python SDK 构建自定义 MCP 服务器,实现工具和资源,配置传输(stdio、HTTP),并部署到生产环境。

Claude Code MCP

规范:https://modelcontextprotocol.io/specification/2025-11-25 (2025年11月)

在需要时使用此技能:

  • 为官方/社区 MCP 服务器配置 .claude/.mcp.json
  • 构建自定义 MCP 服务器(TypeScript 或 Python)
  • 部署和加固远程 MCP 服务器(HTTP 传输)

快速开始(通过 npx 的本地 stdio)

  1. 创建或编辑 .claude/.mcp.json
{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-postgres"],
      "env": { "POSTGRES_URL": "${DATABASE_URL}" }
    }
  }
}
  1. 提供环境变量并验证连接:
export DATABASE_URL="postgresql://user:pass@localhost:5432/db"
claude mcp list
claude mcp get postgres

注意事项:

  • 默认配置文件路径通常是 .claude/.mcp.json。如果需要,可以通过 claude --mcp-config <path> 覆盖。
  • 在服务器配置中优先使用 python3 作为 Python 解释器,除非你的环境确保使用 python

权限管理(推荐)

# 允许服务器所有工具(通配符)
claude mcp add --allow "mcp__postgres__*" postgres -- npx -y @modelcontextprotocol/server-postgres

# 仅允许特定工具
claude mcp add --allow "mcp__postgres__query,mcp__postgres__list_tables" postgres -- npx -y @modelcontextprotocol/server-postgres

# 拒绝特定工具
claude mcp add --deny "mcp__filesystem__write_file" filesystem -- npx -y @modelcontextprotocol/server-filesystem ./data

生产环境防护(必需)

  • 假设工具输出不可信(提示注入)。重用前进行消毒/结构化。
  • 默认最小权限:只读数据库、范围化的文件系统允许列表、最小化工具允许列表。
  • 将机密信息保留在 .mcp.json 之外;通过环境变量或运行时秘密管理器注入。
  • 添加超时、重试和速率限制;记录所有工具调用以进行审计。

下一步阅读

  • 选择现有服务器:references/mcp-servers.md
  • 构建自定义服务器:references/mcp-custom.md
  • 实现模式(DB/API/文件系统):references/mcp-patterns.md
  • 安全加固(OAuth、作用域、注入防御):references/mcp-security.md
  • 模板:assets/database/template-mcp-database.mdassets/filesystem/template-mcp-filesystem.mdassets/api/template-mcp-api.mdassets/deployment/template-mcp-docker.md
  • 精选链接:data/sources.json