# 4.4 场景化实战：MCP 的组合拳

单纯地连接一个 Server 只是第一步。MCP 的真正威力在于 **组合**。当 Claude 同时连接了“眼睛”（搜索）、“记忆”（数据库）和“双手”（GitHub）时，它就不再是一个聊天机器人，而是一个全栈工程师。

本节将通过三个典型场景，展示如何组合多个 MCP Server 来完成复杂任务。

## 4.4.1 场景一：全自动代码审查员

**目标**：自动拉取最新的 Pull Request，分析代码变动，并生成一份审查报告保存到本地。

### 所需组件

* `mcp-server-github`: 读取 PR 内容。
* `mcp-server-filesystem`: 保存 Markdown 报告。

### 交互流程

**User**: “请帮我审查 `anthropic/sdk` 仓库的 #123 号 PR，并将报告保存到桌面的 `reviews` 文件夹。”

**Claude 的后台操作 (Thinking)**:

1. 调用 `github.get_pull_request(owner="anthropic", repo="sdk", number=123)` 获取 PR 描述。
2. 调用 `github.get_issue_comments` 查看已有讨论。
3. 调用 `github.get_pull_request_files` 获取变更文件列表。
4. 逐个分析代码逻辑... (Claude 内部推理)。
5. 生成一份 Markdown 内容。
6. 调用 `filesystem.write_file(path="/Users/me/Desktop/reviews/pr_123.md", content=...)`。

**Result (结果)**: 桌面上多了一份文件，无需离开对话框。

## 4.4.2 场景二：智能数据分析师

**目标**：无需写 SQL，直接用自然语言查询数据库，结合互联网信息生成商业分析图表。

### 所需组件

* `mcp-server-postgres`: 连接业务数据库（如销售数据）。
* `mcp-server-brave-search`: 搜索外部竞品信息。

### 交互流程

**User**: “分析一下上个季度我们在'无线耳机'品类的销售情况，并与苹果 AirPods 的近期市场表现做对比。”

**Claude 的后台操作**:

1. **内部数据**: 调用 `postgres.query("SELECT sum(amount) FROM sales WHERE category='earphones' AND date > ...")`。
   * *Result*: “销售额 500万，环比增长 10%。”
2. **外部数据**: 调用 `brave.search("Apple AirPods market share Q3 2025")`。
   * *Result*: “AirPods 市场份额下滑 2%...”
3. **综合分析**: 结合内外部数据，生成洞察。
   * “虽然竞品下滑，但我司逆势增长，建议加大营销投入...”

## 4.4.3 场景三：自动化运维

**目标**：当系统报警时，自动查看日志并尝试修复。

### 所需组件

* `mcp-server-sentry`: 获取错误堆栈。
* `mcp-server-ssh`: (假设有此工具) 连接服务器查看日志。
* `mcp-server-slack`: 通知运维团队。

### 交互流程

**User**: “Sentry 上刚报了一个 Critical Error，看看是咋回事。”

**Claude 的后台操作**:

1. 调用 `sentry.get_latest_issue()`。
   * *Error*: "Connection refused on port 6379 (Redis)".
2. **推理**: “这是 Redis 挂了。”
3. 调用 `ssh.execute("systemctl status redis")`。
   * *Output*: "Active: failed".
4. 调用 `slack.send_message(channel="#devops", text="检测到 Redis 服务宕机，建议重启。")`。

## 4.4.4 最佳实践：如何向 Claude 提问

当挂载了多个工具时，Prompt 的质量决定了调用的准确度。

### 明确数据源

* *Bad*: “查一下那个数据。”
* *Good*: “请去 **Postgres 数据库** 查一下...” 或 “请 **Google 搜索** 一下...”

### 赋予权限

如果在构建自己的 Agent 应用：

```xml
<system_prompt>
你是一个拥有数据库(Postgres)和代码库(GitHub)访问权限的全能助手。
在回答问题前，优先尝试使用工具获取真实数据，而不是凭空猜测。
</system_prompt>
```

### 组合使用

不要一次只发一个指令。尝试让 Claude 规划任务： “请先列出数据库里的表结构，然后帮我写一个查询...” Claude 会先调用 `list_tables`，看到结果后，再在同一个回复中生成 SQL 查询。

> **MCP 生态扩展（2026-04）**：Anthropic 联合 Adobe、Blender、Autodesk Fusion、Ableton、Splice 等厂商发布了首批面向创意工作的官方连接器，把上述“组合调用”模式延伸到 3D 建模、音频制作与视觉设计场景——其中 Ableton 连接器以官方产品文档作为答复 grounding，是“文档 RAG over MCP”的代表范式。

***

现在已经体验了使用现成的 Server，但在企业中，往往需要通过 MCP 暴露 **内部的私有 API**。这就需要自己动手编写 MCP Server 了。

➡️ [从零开发 MCP Server](/claude_guide/di-er-bu-fen-gong-ju-pian/04_mcp/4.5_custom.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://yeasy.gitbook.io/claude_guide/di-er-bu-fen-gong-ju-pian/04_mcp/4.4_practice.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
