feat: update docs

This commit is contained in:
pomelo-nwu
2025-12-15 19:58:59 +08:00
parent 53486b7fd3
commit 68a0567bf2
5 changed files with 124 additions and 134 deletions

View File

@@ -7,6 +7,5 @@ export default {
}, },
'approval-mode': 'Approval Mode', 'approval-mode': 'Approval Mode',
'token-caching': 'Token Caching', 'token-caching': 'Token Caching',
mcp: 'MCP',
sandbox: 'Sandboxing', sandbox: 'Sandboxing',
}; };

View File

@@ -15,6 +15,7 @@ An MCP server enables the CLI to:
With an MCP server, you can extend the CLIs capabilities to perform actions beyond its built-in features, such as interacting with databases, APIs, custom scripts, or specialized workflows. With an MCP server, you can extend the CLIs capabilities to perform actions beyond its built-in features, such as interacting with databases, APIs, custom scripts, or specialized workflows.
## Core Integration Architecture ## Core Integration Architecture
Qwen Code integrates with MCP servers through a sophisticated discovery and execution system built into the core package (`packages/core/src/tools/`): Qwen Code integrates with MCP servers through a sophisticated discovery and execution system built into the core package (`packages/core/src/tools/`):
### Discovery Layer (`mcp-client.ts`) ### Discovery Layer (`mcp-client.ts`)
@@ -37,6 +38,7 @@ Each discovered MCP tool is wrapped in a `DiscoveredMCPTool` instance that:
- **Maintains connection state** and handles timeouts - **Maintains connection state** and handles timeouts
### Transport Mechanisms ### Transport Mechanisms
The CLI supports three MCP transport types: The CLI supports three MCP transport types:
- **Stdio Transport:** Spawns a subprocess and communicates via stdin/stdout - **Stdio Transport:** Spawns a subprocess and communicates via stdin/stdout
@@ -52,6 +54,7 @@ Qwen Code uses the `mcpServers` configuration in your `settings.json` file t
You can configure MCP servers in your `settings.json` file in two main ways: through the top-level `mcpServers`object for specific server definitions, and through the `mcp` object for global settings that control server discovery and execution. You can configure MCP servers in your `settings.json` file in two main ways: through the top-level `mcpServers`object for specific server definitions, and through the `mcp` object for global settings that control server discovery and execution.
#### Global MCP Settings (`mcp`) #### Global MCP Settings (`mcp`)
The `mcp` object in your `settings.json` allows you to define global rules for all MCP servers. The `mcp` object in your `settings.json` allows you to define global rules for all MCP servers.
- **`mcp.serverCommand`** : A global command to start an MCP server. - **`mcp.serverCommand`** : A global command to start an MCP server.
@@ -70,9 +73,11 @@ The `mcp` object in your `settings.json` allows you to define global rules f
``` ```
#### Server-Specific Configuration (`mcpServers`) #### Server-Specific Configuration (`mcpServers`)
The `mcpServers` object is where you define each individual MCP server you want the CLI to connect to. The `mcpServers` object is where you define each individual MCP server you want the CLI to connect to.
### Configuration Structure ### Configuration Structure
Add an `mcpServers` object to your `settings.json` file: Add an `mcpServers` object to your `settings.json` file:
``` ```
@@ -454,7 +459,6 @@ When confirmation is required, users can choose:
Upon confirmation (or trust bypass): Upon confirmation (or trust bypass):
1. **Parameter preparation:** Arguments are validated against the tools schema 1. **Parameter preparation:** Arguments are validated against the tools schema
2. **MCP call:** The underlying `CallableTool` invokes the server with: 2. **MCP call:** The underlying `CallableTool` invokes the server with:
``` ```
@@ -466,7 +470,6 @@ const functionCalls = [{
3. **Response processing:** Results are formatted for both LLM context and user display 3. **Response processing:** Results are formatted for both LLM context and user display
### 4. Response Handling ### 4. Response Handling
The execution result contains: The execution result contains:
@@ -656,8 +659,6 @@ Here is an example of a valid JSON response from an MCP tool that returns both a
} }
``` ```
When Qwen Code receives this response, it will: When Qwen Code receives this response, it will:
1. Extract all the text and combine it into a single `functionResponse` part for the model. 1. Extract all the text and combine it into a single `functionResponse` part for the model.
@@ -674,7 +675,7 @@ In addition to tools, MCP servers can expose predefined prompts that can be exec
Heres a small example of a stdio MCP server that defines prompts: Heres a small example of a stdio MCP server that defines prompts:
```` ```
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'; import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'; import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import { z } from 'zod'; import { z } from 'zod';
@@ -706,7 +707,7 @@ server.registerPrompt(
const transport = new StdioServerTransport(); const transport = new StdioServerTransport();
await server.connect(transport); await server.connect(transport);
```` ```
This can be included in `settings.json` under `mcpServers` with: This can be included in `settings.json` under `mcpServers` with:
@@ -721,8 +722,6 @@ This can be included in `settings.json` under `mcpServers` with:
} }
``` ```
### Invoking Prompts ### Invoking Prompts
Once a prompt is discovered, you can invoke it using its name as a slash command. The CLI will automatically handle parsing arguments. Once a prompt is discovered, you can invoke it using its name as a slash command. The CLI will automatically handle parsing arguments.
@@ -784,8 +783,6 @@ qwen mcp add my-stdio-server -e API_KEY=123 /path/to/server arg1 arg2 arg3
qwen mcp add python-server python server.py --port 8080 qwen mcp add python-server python server.py --port 8080
``` ```
#### Adding an HTTP server #### Adding an HTTP server
This transport is for servers that use the streamable HTTP transport. This transport is for servers that use the streamable HTTP transport.
@@ -801,8 +798,6 @@ qwen mcp add --transport http http-server https://api.example.com/mcp/
qwen mcp add --transport http secure-http https://api.example.com/mcp/ --header "Authorization: Bearer abc123" qwen mcp add --transport http secure-http https://api.example.com/mcp/ --header "Authorization: Bearer abc123"
``` ```
#### Adding an SSE server #### Adding an SSE server
This transport is for servers that use Server-Sent Events (SSE). This transport is for servers that use Server-Sent Events (SSE).
@@ -818,8 +813,6 @@ qwen mcp add --transport sse sse-server https://api.example.com/sse/
qwen mcp add --transport sse secure-sse https://api.example.com/sse/ --header "Authorization: Bearer abc123" qwen mcp add --transport sse secure-sse https://api.example.com/sse/ --header "Authorization: Bearer abc123"
``` ```
### Listing Servers (`qwen mcp list`) ### Listing Servers (`qwen mcp list`)
To view all MCP servers currently configured, use the `list` command. It displays each servers name, configuration details, and connection status. To view all MCP servers currently configured, use the `list` command. It displays each servers name, configuration details, and connection status.
@@ -838,8 +831,6 @@ qwen mcp list
✗ sse-server: https://api.example.com/sse (sse) - Disconnected ✗ sse-server: https://api.example.com/sse (sse) - Disconnected
``` ```
### Removing a Server (`qwen mcp remove`) ### Removing a Server (`qwen mcp remove`)
To delete a server from your configuration, use the `remove` command with the servers name. To delete a server from your configuration, use the `remove` command with the servers name.