docs/users/features/mcp.md
Qwen Code can connect to external tools and data sources through the Model Context Protocol (MCP). MCP servers give Qwen Code access to your tools, databases, and APIs.
With MCP servers connected, you can ask Qwen Code to:
[!tip]
If you’re looking for the “one command to get started”, jump to Quick start.
Qwen Code loads MCP servers from mcpServers in your settings.json. You can configure servers either:
settings.json directlyqwen mcp commands (see CLI reference)qwen mcp add --transport http my-server http://localhost:3000/mcp
qwen mcp
Most users only need these two scopes:
.qwen/settings.json in your project root~/.qwen/settings.json across all projects on your machineWrite to user scope:
qwen mcp add --scope user --transport http my-server http://localhost:3000/mcp
[!tip]
For advanced configuration layers (system defaults/system settings and precedence rules), see Settings.
| Transport | When to use | JSON field(s) |
|---|---|---|
http | Recommended for remote services; works well for cloud MCP servers | httpUrl (+ optional headers) |
sse | Legacy/deprecated servers that only support Server-Sent Events | url (+ optional headers) |
stdio | Local process (scripts, CLIs, Docker) on your machine | command, args (+ optional cwd, env) |
[!note]
If a server supports both, prefer HTTP over SSE.
settings.json vs qwen mcp addBoth approaches produce the same mcpServers entries in your settings.json—use whichever you prefer.
JSON (.qwen/settings.json):
{
"mcpServers": {
"pythonTools": {
"command": "python",
"args": ["-m", "my_mcp_server", "--port", "8080"],
"cwd": "./mcp-servers/python",
"env": {
"DATABASE_URL": "$DB_CONNECTION_STRING",
"API_KEY": "${EXTERNAL_API_KEY}"
},
"timeout": 15000
}
}
}
CLI (writes to project scope by default):
qwen mcp add pythonTools -e DATABASE_URL=$DB_CONNECTION_STRING -e API_KEY=$EXTERNAL_API_KEY \
--timeout 15000 python -m my_mcp_server --port 8080
JSON:
{
"mcpServers": {
"httpServerWithAuth": {
"httpUrl": "http://localhost:3000/mcp",
"headers": {
"Authorization": "Bearer your-api-token"
},
"timeout": 5000
}
}
}
CLI:
qwen mcp add --transport http httpServerWithAuth http://localhost:3000/mcp \
--header "Authorization: Bearer your-api-token" --timeout 5000
JSON:
{
"mcpServers": {
"sseServer": {
"url": "http://localhost:8080/sse",
"timeout": 30000
}
}
}
CLI:
qwen mcp add --transport sse sseServer http://localhost:8080/sse --timeout 30000
trust: true): bypasses confirmation prompts for that server (use sparingly).Qwen Code supports OAuth 2.0 authentication for MCP servers. This is useful when accessing remote servers that require authentication.
When you add an MCP server with OAuth credentials, Qwen Code will automatically handle the authentication flow:
qwen mcp add --transport sse oauth-server https://api.example.com/sse/ \
--oauth-client-id your-client-id \
--oauth-redirect-uri https://your-server.com/oauth/callback \
--oauth-authorization-url https://provider.example.com/authorize \
--oauth-token-url https://provider.example.com/token
The OAuth flow requires a redirect URI where the authorization provider sends the authentication code.
Local development: By default, Qwen Code uses http://localhost:7777/oauth/callback. This works when running Qwen Code on your local machine with a local browser.
Remote/cloud deployments: When running Qwen Code on remote servers, cloud IDEs, or web terminals, the default localhost redirect will NOT work. You MUST configure --oauth-redirect-uri to point to a publicly accessible URL that can receive the OAuth callback.
Example for remote servers:
qwen mcp add --transport sse remote-server https://api.example.com/sse/ \
--oauth-redirect-uri https://your-remote-server.example.com/oauth/callback
You can also configure OAuth by editing settings.json directly:
{
"mcpServers": {
"oauthServer": {
"url": "https://api.example.com/sse/",
"oauth": {
"enabled": true,
"clientId": "your-client-id",
"clientSecret": "your-client-secret",
"authorizationUrl": "https://provider.example.com/authorize",
"tokenUrl": "https://provider.example.com/token",
"redirectUri": "https://your-server.com/oauth/callback",
"scopes": ["read", "write"]
}
}
}
}
OAuth configuration properties:
| Property | Description |
|---|---|
enabled | Enable OAuth for this server (boolean) |
clientId | OAuth client identifier (string, optional with dynamic registration) |
clientSecret | OAuth client secret (string, optional for public clients) |
authorizationUrl | OAuth authorization endpoint (string, auto-discovered if omitted) |
tokenUrl | OAuth token endpoint (string, auto-discovered if omitted) |
scopes | Required OAuth scopes (array of strings) |
redirectUri | Custom redirect URI (string). Critical for remote deployments. Defaults to http://localhost:7777/oauth/callback |
tokenParamName | Query parameter name for tokens in SSE URLs (string) |
audiences | Audiences the token is valid for (array of strings) |
OAuth tokens are automatically:
~/.qwen/mcp-oauth-tokens.jsonUse the /mcp auth command within Qwen Code to manage OAuth authentication interactively.
Use includeTools / excludeTools to restrict tools exposed by a server (from Qwen Code’s perspective).
Example: include only a few tools:
{
"mcpServers": {
"filteredServer": {
"command": "python",
"args": ["-m", "my_mcp_server"],
"includeTools": ["safe_tool", "file_reader", "data_processor"],
"timeout": 30000
}
}
}
The mcp object in your settings.json defines global rules for all MCP servers:
mcp.allowed: allow-list of MCP server names (keys in mcpServers)mcp.excluded: deny-list of MCP server namesExample:
{
"mcp": {
"allowed": ["my-trusted-server"],
"excluded": ["experimental-server"]
}
}
qwen mcp list: verify the URL/command is correct, then increase timeout.command path, and double-check cwd/env.settings.json structuremcpServers)Add an mcpServers object to your settings.json file:
// ... file contains other config objects
{
"mcpServers": {
"serverName": {
"command": "path/to/server",
"args": ["--arg1", "value1"],
"env": {
"API_KEY": "$MY_API_TOKEN"
},
"cwd": "./server-directory",
"timeout": 30000,
"trust": false
}
}
}
Configuration properties:
Required (one of the following):
| Property | Description |
|---|---|
command | Path to the executable for Stdio transport |
url | SSE endpoint URL (e.g., "http://localhost:8080/sse") |
httpUrl | HTTP streaming endpoint URL |
Optional:
| Property | Type/Default | Description |
|---|---|---|
args | array | Command-line arguments for Stdio transport |
headers | object | Custom HTTP headers when using url or httpUrl |
env | object | Environment variables for the server process. Values can reference environment variables using $VAR_NAME or ${VAR_NAME} syntax |
cwd | string | Working directory for Stdio transport |
timeout | number | |
| (default: 600,000) | Request timeout in milliseconds (default: 600,000ms = 10 minutes) | |
trust | boolean | |
| (default: false) | When true, bypasses all tool call confirmations for this server (default: false) | |
includeTools | array | 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 | array | 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. | ||
targetAudience | string | The OAuth Client ID allowlisted on the IAP-protected application you are trying to access. Used with authProviderType: 'service_account_impersonation'. |
targetServiceAccount | string | The email address of the Google Cloud Service Account to impersonate. Used with authProviderType: 'service_account_impersonation'. |
<a id="qwen-mcp-cli"></a>
qwen mcpYou can always configure MCP servers by manually editing settings.json, but the CLI is usually faster.
qwen mcp add)qwen mcp add [options] <name> <commandOrUrl> [args...]
| Argument/Option | Description | Default | Example |
|---|---|---|---|
<name> | A unique name for the server. | — | example-server |
<commandOrUrl> | The command to execute (for stdio) or the URL (for http/sse). | — | /usr/bin/python or http://localhost:8 |
[args...] | Optional arguments for a stdio command. | — | --port 5000 |
-s, --scope | Configuration scope (user or project). | project | -s user |
-t, --transport | Transport type (stdio, sse, http). | stdio | -t sse |
-e, --env | Set environment variables. | — | -e KEY=value |
-H, --header | Set HTTP headers for SSE and HTTP transports. | — | -H "X-Api-Key: abc123" |
--timeout | Set connection timeout in milliseconds. | — | --timeout 30000 |
--trust | Trust the server (bypass all tool call confirmation prompts). | — (false) | --trust |
--description | Set the description for the server. | — | --description "Local tools" |
--include-tools | A comma-separated list of tools to include. | all tools included | --include-tools mytool,othertool |
--exclude-tools | A comma-separated list of tools to exclude. | none | --exclude-tools mytool |
--oauth-client-id | OAuth client ID for MCP server authentication. | — | --oauth-client-id your-client-id |
--oauth-client-secret | OAuth client secret for MCP server authentication. | — | --oauth-client-secret your-client-secret |
--oauth-redirect-uri | OAuth redirect URI for authentication callback. | http://localhost:7777/oauth/callback | --oauth-redirect-uri https://your-server.com/oauth/callback |
--oauth-authorization-url | OAuth authorization URL. | — | --oauth-authorization-url https://provider.example.com/authorize |
--oauth-token-url | OAuth token URL. | — | --oauth-token-url https://provider.example.com/token |
--oauth-scopes | OAuth scopes (comma-separated). | — | --oauth-scopes scope1,scope2 |
--oauth-*flags apply only to--transport sseand--transport http. Combining them with--transport stdiois rejected.
qwen mcp remove)qwen mcp remove <name>