Claude Code 默认能访问你的代码和终端。但通过 MCP(Model Context Protocol),它还能连接 Jira、Slack、GitHub Issues、数据库等外部工具,真正成为一个全方位的开发助手。
什么是 MCP?
Model Context Protocol 是 Anthropic 推出的开放标准,让 AI 工具能安全地连接外部数据源和服务。
简单说:MCP 给 Claude Code 装上了"插头",可以接入任何支持的服务。
为什么需要 MCP?
没有 MCP 的工作流:
- 在 Jira 里看到 Bug 报告
- 手动复制到 Claude Code
- 手动把修复内容更新回 Jira
- 手动通知团队
有 MCP 的工作流:
修复 Jira PROJ-123 这个 Bug,
完成后把 issue 状态改为"In Review",
并在对应的 Slack 频道发一条更新
Claude Code 一步完成全部操作。
安装 MCP 服务器
方式 1:通过 Claude Code 命令行
bash
# 添加 MCP 服务器(以 GitHub 为例)
claude mcp add github
# 查看已安装的 MCP 服务器
claude mcp list
# 移除
claude mcp remove github方式 2:手动配置
编辑 ~/.claude/settings.json(用户全局)或项目 .claude/settings.json:
json
{
"mcpServers": {
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_TOKEN": "ghp_xxxxx"
}
},
"slack": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-slack"],
"env": {
"SLACK_BOT_TOKEN": "xoxb-xxxxx",
"SLACK_TEAM_ID": "T04xxxxx"
}
}
}
}常用 MCP 集成场景
1. GitHub MCP
安装:
bash
claude mcp add github
# 或手动配置 @modelcontextprotocol/server-github需要 GitHub Personal Access Token(repo 权限)。
使用:
列出 anthropics/claude-code 仓库最近 10 个未关闭的 Issues
找到所有标记为 "bug" 且超过 30 天未处理的 Issues
帮我把 PR #234 的描述更新,加上这次修改了哪些文件
2. Jira MCP
bash
npm install -g @modelcontextprotocol/server-jira配置:
json
{
"mcpServers": {
"jira": {
"command": "mcp-server-jira",
"env": {
"JIRA_HOST": "https://yourcompany.atlassian.net",
"JIRA_EMAIL": "you@company.com",
"JIRA_API_TOKEN": "your-api-token"
}
}
}
}使用:
查看 Sprint 42 里所有分配给我的 Story
PROJ-456 的描述是什么?有相关的 Bug 报告吗?
按照 PROJ-789 的需求描述,在代码里实现这个功能
完成后把 issue 状态改为 In Progress
3. Slack MCP
json
{
"mcpServers": {
"slack": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-slack"],
"env": {
"SLACK_BOT_TOKEN": "xoxb-xxxxx"
}
}
}
}使用:
在 #backend-team 频道里搜索最近关于 Redis 的讨论
把这个 Bug 修复的总结发到 #deployments 频道
4. 数据库直连(PostgreSQL)
json
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-postgres", "postgresql://user:password@localhost/mydb"]
}
}
}使用:
分析 orders 表最近 7 天的数据,找出异常的订单模式
users 表里有多少活跃用户(最近 30 天有登录记录的)?
检查是否有孤儿记录(orders 里有 user_id 但 users 表不存在的)
安全提醒:数据库 MCP 建议使用只读账号,避免误操作。
5. Google Drive / Docs
json
{
"mcpServers": {
"gdrive": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-gdrive"]
}
}
}使用:
读取 Google Drive 里的"API 设计规范.docx"
按照这个规范检查我刚写的 API 是否符合标准
把这次 Sprint 的技术总结写入"工程日志"文档
一个完整的联动示例
把上面的工具结合起来,实现真正的"自动化开发助手":
1. 从 Jira 读取 PROJ-567 的需求
2. 在代码库里找到相关文件
3. 实现需求,写测试
4. 运行测试确认通过
5. 提交代码,创建 PR
6. 把 Jira issue 状态改为 "Code Review"
7. 在 #dev-updates Slack 频道发布更新
一条指令,Claude Code 完成整个工作流。
查找更多 MCP 服务器
官方 MCP 服务器列表:github.com/modelcontextprotocol/servers
常用的还有:
@modelcontextprotocol/server-filesystem- 访问本地文件系统(指定目录)@modelcontextprotocol/server-brave-search- Brave 搜索@modelcontextprotocol/server-puppeteer- 浏览器自动化@modelcontextprotocol/server-aws-kb-retrieval- AWS 知识库
自己写 MCP 服务器
如果没有现成的 MCP 服务器,可以自己写:
typescript
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
const server = new Server(
{ name: "my-company-api", version: "1.0.0" },
{ capabilities: { tools: {} } }
);
// 注册工具
server.setRequestHandler("tools/call", async (request) => {
if (request.params.name === "get_deployment_status") {
// 调用你的内部 API
const status = await fetchDeploymentStatus(request.params.arguments.service);
return { content: [{ type: "text", text: JSON.stringify(status) }] };
}
});
const transport = new StdioServerTransport();
await server.connect(transport);来源:Anthropic MCP 文档 | MCP 官方 GitHub