Skip to main content

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:
Use for:
  • Local scripts
  • Command-line tools
  • Simple integrations

2. SSE Transport

Server-Sent Events over HTTP:
Use for:
  • Remote services
  • Cloud APIs
  • Webhooks

3. Streamable HTTP

HTTP streaming:
Use for:
  • RESTful APIs
  • Modern web services

Configuration

Basic Setup

Add to settings.json:

Configuration Properties

Environment Variables

Use $VAR_NAME syntax for environment variables:
Variables are resolved from:
  1. Process environment
  2. User’s shell environment
  3. .env files (if supported)

Global MCP Settings

Tool Discovery

Discovery Process

Tool Registration

MCP tools are registered with unique names:
Naming pattern: 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:
  1. Server is trusted:
  2. Tool is read-only:
  3. User allowlisted it:
    • Choose “Always allow” in confirmation dialog
    • Applies to current session

Tool Annotations

MCP tools can provide hints about their behavior:
These help Qwen Code make informed decisions about confirmation and execution.

Examples

GitHub Server

Available Tools:
  • mcp_github_create_or_update_file
  • mcp_github_search_repositories
  • mcp_github_create_repository
  • mcp_github_get_file_contents
  • mcp_github_push_files
  • mcp_github_create_issue
  • mcp_github_create_pull_request
  • mcp_github_fork_repository
  • mcp_github_create_branch

Filesystem Server

Available Tools:
  • mcp_filesystem_read_file
  • mcp_filesystem_read_multiple_files
  • mcp_filesystem_write_file
  • mcp_filesystem_create_directory
  • mcp_filesystem_list_directory
  • mcp_filesystem_move_file
  • mcp_filesystem_search_files
  • mcp_filesystem_get_file_info

Database Server

Available Tools:
  • mcp_postgres_query
  • mcp_postgres_list_tables
  • mcp_postgres_describe_table
  • mcp_postgres_insert
  • mcp_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
Trusted:
  • No confirmation required
  • Use only for verified servers
  • Set trust: true in config

Best Practices

  1. Review Server Code:
    • Inspect server implementation
    • Verify it’s from trusted source
    • Check for suspicious behavior
  2. Limit Permissions:
    • Give minimum necessary access
    • Use environment variables for secrets
    • Don’t store secrets in config
  3. Use Allowlists:
  4. Monitor Activity:
    • Review confirmation prompts
    • Check logs for suspicious calls
    • Disable unused servers
  5. Sandbox if Possible:

Environment Variable Security

Store sensitive data in environment:
Reference in config:

Troubleshooting

Server Not Found

Error: MCP server "my-server" not found Solutions:
  1. Check server name in config
  2. Verify command is in PATH
  3. Use absolute path: /usr/local/bin/server
  4. Check disabled: false

Connection Timeout

Error: Connection to MCP server timed out Solutions:
  1. Increase timeout: "timeout": 60000
  2. Check server starts quickly
  3. Verify network connectivity (for remote servers)
  4. Check server logs

Tool Not Available

Error: Tool "mcp_server_tool" not found Solutions:
  1. Restart Qwen Code (tools discovered on startup)
  2. Check server is enabled
  3. Verify server implements tool
  4. Check for name conflicts

Permission Denied

Error: Permission denied: /path/to/server Solutions:
  1. Make server executable: chmod +x /path/to/server
  2. Check file permissions
  3. Run with correct user

Implementation

Key Files:
  • packages/core/src/tools/mcp-client.ts - Discovery and client
  • packages/core/src/tools/mcp-tool.ts - Tool wrapper
  • packages/core/src/tools/mcp-client-manager.ts - Connection management

Client Manager

Next Steps