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:
``` ```
@@ -112,7 +117,7 @@ Each server configuration supports the following properties:
- **`trust`** (boolean): When `true`, bypasses all tool call confirmations for this server (default: `false`) - **`trust`** (boolean): When `true`, bypasses all tool call confirmations for this server (default: `false`)
- **`includeTools`** : List of tool names to include from this MCP server. When specified, only the tools listed here will be available from this server (allowlist behavior). If not specified, all tools from the server are enabled by default. - **`includeTools`** : List of tool names to include from this MCP server. When specified, only the tools listed here will be available from this server (allowlist behavior). If not specified, all tools from the server are enabled by default.
- **`excludeTools`** : List of tool names to exclude from this MCP server. Tools listed here will not be available to the model, even if they are exposed by the server.  - **`excludeTools`** : List of tool names to exclude from this MCP server. Tools listed here will not be available to the model, even if they are exposed by the server. 
- **Note:** `excludeTools` takes precedence over `includeTools` - if a tool is in both lists, it will be excluded. - **Note:** `excludeTools` takes precedence over `includeTools` - if a tool is in both lists, it will be excluded.
- **`targetAudience`** : The OAuth Client ID allowlisted on the IAP-protected application you are trying to access. Used with `authProviderType: 'service_account_impersonation'`. - **`targetAudience`** : The OAuth Client ID allowlisted on the IAP-protected application you are trying to access. Used with `authProviderType: 'service_account_impersonation'`.
- **`targetServiceAccount`** : The email address of the Google Cloud Service Account to impersonate. Used with `authProviderType: 'service_account_impersonation'`. - **`targetServiceAccount`** : The email address of the Google Cloud Service Account to impersonate. Used with `authProviderType: 'service_account_impersonation'`.
@@ -206,9 +211,9 @@ OAuth tokens are automatically:
You can specify the authentication provider type using the `authProviderType` property: You can specify the authentication provider type using the `authProviderType` property:
- **`authProviderType`** : Specifies the authentication provider. Can be one of the following: - **`authProviderType`** : Specifies the authentication provider. Can be one of the following:
- **`dynamic_discovery`** (default): The CLI will automatically discover the OAuth configuration from the server. - **`dynamic_discovery`** (default): The CLI will automatically discover the OAuth configuration from the server.
- **`google_credentials`**: The CLI will use the Google Application Default Credentials (ADC) to authenticate with the server. When using this provider, you must specify the required scopes. - **`google_credentials`**: The CLI will use the Google Application Default Credentials (ADC) to authenticate with the server. When using this provider, you must specify the required scopes.
- **`service_account_impersonation`**: The CLI will impersonate a Google Cloud Service Account to authenticate with the server. This is useful for accessing IAP-protected services (this was specifically designed for Cloud Run services). - **`service_account_impersonation`**: The CLI will impersonate a Google Cloud Service Account to authenticate with the server. This is useful for accessing IAP-protected services (this was specifically designed for Cloud Run services).
#### Google Credentials #### Google Credentials
@@ -368,9 +373,9 @@ For each configured server in `mcpServers`:
1. **Status tracking begins:** Server status is set to `CONNECTING` 1. **Status tracking begins:** Server status is set to `CONNECTING`
2. **Transport selection:** Based on configuration properties: 2. **Transport selection:** Based on configuration properties:
- `httpUrl` → `StreamableHTTPClientTransport` - `httpUrl` → `StreamableHTTPClientTransport`
- `url` → `SSEClientTransport` - `url` → `SSEClientTransport`
- `command` → `StdioClientTransport` - `command` → `StdioClientTransport`
3. **Connection establishment:** The MCP client attempts to connect with the configured timeout 3. **Connection establishment:** The MCP client attempts to connect with the configured timeout
4. **Error handling:** Connection failures are logged and the server status is set to `DISCONNECTED` 4. **Error handling:** Connection failures are logged and the server status is set to `DISCONNECTED`
@@ -382,8 +387,8 @@ Upon successful connection:
2. **Schema validation:** Each tools function declaration is validated 2. **Schema validation:** Each tools function declaration is validated
3. **Tool filtering:** Tools are filtered based on `includeTools` and `excludeTools` configuration 3. **Tool filtering:** Tools are filtered based on `includeTools` and `excludeTools` configuration
4. **Name sanitization:** Tool names are cleaned to meet Qwen API requirements: 4. **Name sanitization:** Tool names are cleaned to meet Qwen API requirements:
- Invalid characters (non-alphanumeric, underscore, dot, hyphen) are replaced with underscores - Invalid characters (non-alphanumeric, underscore, dot, hyphen) are replaced with underscores
- Names longer than 63 characters are truncated with middle replacement (`___`) - Names longer than 63 characters are truncated with middle replacement (`___`)
### 3. Conflict Resolution ### 3. Conflict Resolution
@@ -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.