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:- STDIO (Standard I/O)
- HTTP
- SSE (Server-Sent Events)
Use for: Local processes, command-line toolsThe server:
- Runs as a subprocess
- Communicates via stdin/stdout
- Started on-demand
- Stopped when Qwen Code exits
@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:- 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:- 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:Tool Filtering
Limit which tools are available:Popular MCP Servers
@modelcontextprotocol/server-filesystem
@modelcontextprotocol/server-filesystem
Purpose: Access files outside the workspaceTools:
read_file- Read fileswrite_file- Write fileslist_directory- List filessearch_files- Search content
- Access data directories
- Read configuration files
- Process documents
- Manage assets
@modelcontextprotocol/server-github
@modelcontextprotocol/server-github
Purpose: GitHub API integrationTools:
list_issues- List issuescreate_issue- Create issuescomment_issue- Comment on issueslist_pull_requests- List PRscreate_pull_request- Create PRs- And many more…
- Automate issue management
- Create PRs from changes
- Code review automation
- Project management
@modelcontextprotocol/server-postgres
@modelcontextprotocol/server-postgres
Purpose: PostgreSQL database accessTools:
query- Execute SQL querieslist_tables- List tablesdescribe_table- Get table schema
- Data analysis
- Schema exploration
- Query generation
- Data migration
@modelcontextprotocol/server-slack
@modelcontextprotocol/server-slack
Purpose: Slack integrationTools:
send_message- Send messageslist_channels- List channelssearch_messages- Search history
- Send notifications
- Automate workflows
- Analyze conversations
- Team communication
Building Custom MCP Servers
Node.js Example
Python Example
Advanced Features
Context Providers
MCP servers can provide context (not just tools):Prompts
MCP servers can provide reusable prompts:Sampling
MCP servers can request AI completions:Troubleshooting
Server won't start
Server won't start
Problem: MCP server fails to connect.Solutions:
- Check command is correct:
qwen mcp listshows 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
Tools not available
Tools not available
Problem: MCP tools don’t appear or can’t be used.Solutions:
- Verify server is connected:
/mcp - Check tool filtering:
includeTools/excludeToolsin config - Ensure server implements the tool correctly
- Try removing and re-adding the server
Authentication errors
Authentication errors
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
Slow or hanging
Slow or hanging
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
Permission denied
Permission denied
Problem: MCP tool requires approval even when trusted.Solutions:
- Set
"trust": truein server config - Or use YOLO approval mode:
--approval-mode yolo - Check persistent approvals:
/permissions
Best Practices
- Start with stdio: Use stdio transport for local servers, HTTP for remote
- Set timeouts: Prevent hanging with reasonable timeout values
- Use environment variables: Don’t hardcode secrets in settings
- Filter tools: Only enable tools you need for security
- Trust carefully: Only set
trust: truefor servers you control - Test separately: Verify MCP servers work outside Qwen Code first
- Version control: Commit project-level MCP configs (without secrets)
- Document setup: Create README for team members setting up MCP servers
- Monitor usage: Check logs if servers behave unexpectedly
- 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
