MCP Server Tools
Model Context Protocol (MCP) servers extend Qwen Code’s capabilities by providing access to external tools, APIs, and data sources.Overview
MCP servers act as bridges between Qwen Code and external systems, allowing the AI to:- Discover tools: List available tools with schemas
- Execute tools: Call tools with structured parameters
- Access resources: Read data from external sources
- Extend functionality: Add custom capabilities without modifying Qwen Code
Architecture
Integration Flow
Transport Mechanisms
Qwen Code supports three transport types:1. Stdio Transport
Communicates via standard input/output:- Local scripts
- Command-line tools
- Simple integrations
2. SSE Transport
Server-Sent Events over HTTP:- Remote services
- Cloud APIs
- Webhooks
3. Streamable HTTP
HTTP streaming:- RESTful APIs
- Modern web services
Configuration
Basic Setup
Add tosettings.json:
Configuration Properties
Environment Variables
Use$VAR_NAME syntax for environment variables:
- Process environment
- User’s shell environment
.envfiles (if supported)
Global MCP Settings
Tool Discovery
Discovery Process
Tool Registration
MCP tools are registered with unique names:mcp_{serverName}_{toolName}
This prevents conflicts between:
- Built-in tools
- Different MCP servers
- Tools with same names
Tool Execution
Execution Flow
Confirmation
MCP tools require confirmation unless:-
Server is trusted:
-
Tool is read-only:
-
User allowlisted it:
- Choose “Always allow” in confirmation dialog
- Applies to current session
Tool Annotations
MCP tools can provide hints about their behavior:Examples
GitHub Server
mcp_github_create_or_update_filemcp_github_search_repositoriesmcp_github_create_repositorymcp_github_get_file_contentsmcp_github_push_filesmcp_github_create_issuemcp_github_create_pull_requestmcp_github_fork_repositorymcp_github_create_branch
Filesystem Server
mcp_filesystem_read_filemcp_filesystem_read_multiple_filesmcp_filesystem_write_filemcp_filesystem_create_directorymcp_filesystem_list_directorymcp_filesystem_move_filemcp_filesystem_search_filesmcp_filesystem_get_file_info
Database Server
mcp_postgres_querymcp_postgres_list_tablesmcp_postgres_describe_tablemcp_postgres_insertmcp_postgres_update
Custom Server
Creating MCP Servers
Server Structure
MCP servers follow a standard protocol:Tool Schema
Define tools with JSON Schema:Response Format
Return results in MCP format:Security
Trust Levels
Untrusted (default):- Requires confirmation for each tool use
- Shows tool name and parameters
- User can allowlist specific tools
- No confirmation required
- Use only for verified servers
- Set
trust: truein config
Best Practices
-
Review Server Code:
- Inspect server implementation
- Verify it’s from trusted source
- Check for suspicious behavior
-
Limit Permissions:
- Give minimum necessary access
- Use environment variables for secrets
- Don’t store secrets in config
-
Use Allowlists:
-
Monitor Activity:
- Review confirmation prompts
- Check logs for suspicious calls
- Disable unused servers
-
Sandbox if Possible:
Environment Variable Security
Store sensitive data in environment:Troubleshooting
Server Not Found
Error:MCP server "my-server" not found
Solutions:
- Check server name in config
- Verify command is in PATH
- Use absolute path:
/usr/local/bin/server - Check
disabled: false
Connection Timeout
Error:Connection to MCP server timed out
Solutions:
- Increase timeout:
"timeout": 60000 - Check server starts quickly
- Verify network connectivity (for remote servers)
- Check server logs
Tool Not Available
Error:Tool "mcp_server_tool" not found
Solutions:
- Restart Qwen Code (tools discovered on startup)
- Check server is enabled
- Verify server implements tool
- Check for name conflicts
Permission Denied
Error:Permission denied: /path/to/server
Solutions:
- Make server executable:
chmod +x /path/to/server - Check file permissions
- Run with correct user
Implementation
Key Files:packages/core/src/tools/mcp-client.ts- Discovery and clientpackages/core/src/tools/mcp-tool.ts- Tool wrapperpackages/core/src/tools/mcp-client-manager.ts- Connection management
Client Manager
Next Steps
- Tools System - Tools architecture
- File System Tools - Built-in file operations
- Shell Tool - Shell command execution
- Configuration System - MCP configuration
