Skip to main content

Overview

The Model Context Protocol (MCP) is an open standard that allows AI assistants to connect to external data sources and tools. Qwen Code supports MCP, enabling you to:
  • Add custom tools from MCP servers
  • Access external data (databases, APIs, filesystems)
  • Integrate services (GitHub, Slack, Jira, etc.)
  • Build extensions without modifying Qwen Code
  • Share tools across different AI assistants
MCP is an open standard by Anthropic. Learn more at modelcontextprotocol.io

Quick Start

Add an MCP Server

List MCP Servers

Remove an MCP Server

MCP Transports

Qwen Code supports three MCP transport types:
Use for: Local processes, command-line tools
The server:
  • Runs as a subprocess
  • Communicates via stdin/stdout
  • Started on-demand
  • Stopped when Qwen Code exits
Example servers:
  • @modelcontextprotocol/server-filesystem
  • @modelcontextprotocol/server-github
  • @modelcontextprotocol/server-postgres
  • Custom Node.js/Python servers

Configuration

Settings File

MCP servers are configured in your settings:

Command Line Options

Using MCP Tools

Once configured, MCP tools are available to the AI:

Tool Discovery

The AI automatically discovers available tools:
Shows:
  • Connected servers
  • Available tools from each server
  • Tool descriptions and parameters
  • Connection status

Manual Tool Invocation

You can request specific MCP tools:

Approval and Security

First-Use Approval

By default, MCP tools require approval on first use:
Choices:
  • Allow: Execute once
  • Reject: Skip this call
  • Always Allow Server: Trust all tools from this server
  • Always Allow Tool: Trust this specific tool

Trusted Servers

Mark servers as trusted to skip approval:
Only trust MCP servers you control or from reputable sources. MCP tools can read/write files, make network requests, and execute code.

Tool Filtering

Limit which tools are available:
Purpose: Access files outside the workspace
Tools:
  • read_file - Read files
  • write_file - Write files
  • list_directory - List files
  • search_files - Search content
Use cases:
  • Access data directories
  • Read configuration files
  • Process documents
  • Manage assets
Purpose: GitHub API integration
Tools:
  • list_issues - List issues
  • create_issue - Create issues
  • comment_issue - Comment on issues
  • list_pull_requests - List PRs
  • create_pull_request - Create PRs
  • And many more…
Use cases:
  • Automate issue management
  • Create PRs from changes
  • Code review automation
  • Project management
Purpose: PostgreSQL database access
Tools:
  • query - Execute SQL queries
  • list_tables - List tables
  • describe_table - Get table schema
Use cases:
  • Data analysis
  • Schema exploration
  • Query generation
  • Data migration
Purpose: Slack integration
Tools:
  • send_message - Send messages
  • list_channels - List channels
  • search_messages - Search history
Use cases:
  • Send notifications
  • Automate workflows
  • Analyze conversations
  • Team communication

Building Custom MCP Servers

Node.js Example

Build and use:

Python Example

Use:

Advanced Features

Context Providers

MCP servers can provide context (not just tools):
Qwen Code automatically includes this context when relevant.

Prompts

MCP servers can provide reusable prompts:
Invoke MCP prompts:

Sampling

MCP servers can request AI completions:
This allows MCP servers to use AI for their own logic.

Troubleshooting

Problem: MCP server fails to connect.Solutions:
  • Check command is correct: qwen mcp list shows command
  • Verify dependencies installed: npm list -g @modelcontextprotocol/server-*
  • Check environment variables are set
  • Look at debug logs: DEBUG=qwen:mcp qwen
  • Test server manually: npx @modelcontextprotocol/server-github --help
Problem: MCP tools don’t appear or can’t be used.Solutions:
  • Verify server is connected: /mcp
  • Check tool filtering: includeTools/excludeTools in config
  • Ensure server implements the tool correctly
  • Try removing and re-adding the server
Problem: MCP server can’t authenticate to external service.Solutions:
  • Check environment variables: echo $GITHUB_TOKEN
  • Verify token has correct permissions
  • Use ${VAR} syntax in settings for env var expansion
  • Check headers are correctly configured
Problem: MCP tool calls are very slow.Solutions:
  • Increase timeout: "timeout": 60000
  • Check server performance
  • Use HTTP transport for remote servers (not stdio)
  • Enable streaming responses if supported
Problem: MCP tool requires approval even when trusted.Solutions:
  • Set "trust": true in server config
  • Or use YOLO approval mode: --approval-mode yolo
  • Check persistent approvals: /permissions

Best Practices

  1. Start with stdio: Use stdio transport for local servers, HTTP for remote
  2. Set timeouts: Prevent hanging with reasonable timeout values
  3. Use environment variables: Don’t hardcode secrets in settings
  4. Filter tools: Only enable tools you need for security
  5. Trust carefully: Only set trust: true for servers you control
  6. Test separately: Verify MCP servers work outside Qwen Code first
  7. Version control: Commit project-level MCP configs (without secrets)
  8. Document setup: Create README for team members setting up MCP servers
  9. Monitor usage: Check logs if servers behave unexpectedly
  10. Update regularly: Keep MCP SDK and servers up to date

Examples

Database Analysis

GitHub Automation

Custom Integration

Next Steps

MCP SDK Documentation

Learn to build custom MCP servers

Approval Modes

Control MCP tool permissions

Configuration

Advanced MCP configuration

Examples

Browse MCP server examples