使用说明
MCP服务器
常见问题
MCP客户如何知道使用什么?
MCP客户端协调用户、模型(LLM)和MCP服务器之间的交互。决策是分散的 三个演员:
🧠 1.模型(LLM)——决定 哪个 工具 呼叫
- 分析用户的意图并自主选择工具。
- 工具由MCP服务器公开(如OpenAI函数调用)。
- 该模型可以看到工具定义(名称、输入模式、描述),并决定是否以及何时使用它们。
例子:
用户说:“发送明天下午2点的日历邀请。”
→ 模型调用create_calendar_event().
📦 2.应用程序(主机)-控件 哪个 资源 包括在内
- 资源(例如文档、电子邮件、数据)不会自动包含在内。
- 宿主应用程序决定将哪些资源发送到模型的上下文中。
- 帮助管理令牌限制和隐私。
例子:
客户端应用程序将5个最新的会议记录注入LLM的上下文中。
👤 3.用户--选择 哪个 提示 激活
- 提示是预先构建的消息模板,用于指导模型。
- 用户可以明确地选择如下提示:
- “总结我的收件箱”
- “生成周报”
- 这些可以在UI中呈现为按钮、斜线命令或建议。
⚙️ 幕后:发现与协调
- 客户端向MCP服务器查询可用的:
- 工具 (模型可以调用的函数)
- 资源 (应用程序可以提供给上下文的数据)
- 提示 (用户触发的模板)
- 所选项目将嵌入LLM的系统消息和提示中。
- 模型动态地决定是否:
- 使用提示,
- 利用上下文资源,
- 呼叫工具,
- 或者只是用文字回复。
🧠 示例流程
User: "Create a report based on my last 5 meetings."
↓
→ Application loads 5 meeting transcripts as resources
→ User selects the "Generate Report" prompt
→ LLM uses prompt + resources
→ Model calls tool: summarize_each_meeting()
→ Model composes report from summaries
→ Final report is returned to user
## Concepts
### 1. Tools
- **Purpose**: Executable actions (e.g., send an email, search a database, run a script).
- **Controlled by**: The **model** (LLM decides when to call).
- **Examples**: `generate_invoice`, `search_files`, `send_slack_message`.
### 2. Resources
- **Purpose**: Provide read-only contextual data to inform the model.
- **Controlled by**: The **application** (host decides what’s available in context).
- **Examples**: Documents, calendar events, database records.
### 3. Prompts
- **Purpose**: Pre-configured message templates that guide LLM behavior.
- **Controlled by**: The **user** (user explicitly chooses).
- **Examples**: "Summarize recent meetings", "Draft customer response", "Plan a vacation".
## Useful repositories
- [Spring WebMVC example project](https://github.com/spring-projects/spring-ai-examples/blob/main/model-context-protocol/weather/starter-webmvc-server/README.md)
- [Chat Client](https://docs.spring.io/spring-ai/reference/api/chatclient.html)
- [How to use prompts/ resources](https://github.com/spring-projects/spring-ai-examples/blob/5e31bbad50248f2764f9ce175fd749f7c9b60b6e/model-context-protocol/mcp-annotations-server/src/main/java/org/springframework/ai/mcp/sample/server/McpServerApplication.java)```
