Use external tools in chat
Qwen Cloud supports the Model Context Protocol (MCP) through the Responses API. Pass one or more MCP server configurations in the
This example connects to the Fetch MCP service from ModelScope to scrape web content. Before running the code:
A typical response includes two phases: tool listing (the model discovers available tools) and the final output (the model uses those tools and returns a result).
Tool listing output
The response
Tool call and final output
After discovering tools, the model invokes them and produces a final text response. The
Error handling
If the model cannot connect to an MCP server or a tool call fails, the response includes an
MCP tool calls can involve multiple round trips with external servers. Enable streaming to receive tool call progress and model responses in real time. Add
In addition to the standard streaming events, MCP responses emit these event types:
Example with authentication:
MCP is available through the Responses API only. The following models support MCP tool calls:
Two types of charges apply when using MCP:
tools parameter. The model connects to those servers, discovers their tools, and invokes them as needed to fulfill each request.
Getting started
This example connects to the Fetch MCP service from ModelScope to scrape web content. Before running the code:
- Get the SSE endpoint from the Service configuration section of your MCP service on ModelScope. Replace
server_urlwith this endpoint. - If authentication is required, add the token to the
headersfield.
Replace the
server_url in the sample code with the SSE Endpoint that you got from the MCP service platform. Replace the authentication information in headers with the token provided by that platform.- Python
- Node.js
- curl
How it works
1
Define MCP tool configuration
Define an MCP tool configuration with the server's SSE endpoint and optional authentication headers.
2
Pass the configuration
Pass the configuration in the
tools parameter of a Responses API call.3
Model connects and discovers tools
The model connects to the MCP server, discovers available tools, and invokes them to process the input.
4
Receive the response
The response contains the model's final output, including results from the MCP tool calls.
MCP servers are third-party services. Only connect to servers you trust. A malicious MCP server could return harmful content, exfiltrate data through tool descriptions, or incur unexpected costs. Always verify the server source before adding it to your requests.
You can get the SSE endpoint and authentication information for MCP services from platforms such as ModelScope. Only MCP servers using the SSE protocol are supported, with a maximum of 10 per request.
Response structure
A typical response includes two phases: tool listing (the model discovers available tools) and the final output (the model uses those tools and returns a result).
Tool listing output
The response output array begins with an mcp_list_tools item showing the tools the model discovered on the MCP server:
output array includes mcp_call items for each tool invocation, followed by a message item with the synthesized answer:
The actual response depends on the live content fetched by the MCP server. Token usage varies by request.
mcp_call item with error details instead of tool output. Common causes include invalid server_url values, authentication failures, and server timeouts. Check the error field in the response output for diagnostics.
Enable streaming
MCP tool calls can involve multiple round trips with external servers. Enable streaming to receive tool call progress and model responses in real time. Add stream=True (Python), stream: true (Node.js / curl) to your request.
For streaming implementation details, event types, and code examples, see Streaming output.
MCP-specific streaming events
In addition to the standard streaming events, MCP responses emit these event types:
| Event type | Description |
|---|---|
response.mcp_list_tools.done | Tool discovery from an MCP server is complete. |
response.mcp_call.done | An MCP tool call has finished and returned results. |
MCP tool parameters
| Parameter | Required | Description |
|---|---|---|
type | Yes | Set to "mcp". |
server_protocol | Yes | Communication protocol. Only "sse" is supported. |
server_label | Yes | A short label that identifies the MCP server. |
server_description | No | A natural-language description of the server's capabilities. A clear description helps the model decide when to invoke the server's tools and improves tool selection accuracy. Recommended for all MCP servers. |
server_url | Yes | The SSE endpoint URL of the MCP server. |
headers | No | HTTP headers to include when connecting to the MCP server, such as Authorization for authentication. |
Supported models
MCP is available through the Responses API only. The following models support MCP tool calls:
| Model family | Model IDs |
|---|---|
| Qwen-Plus | qwen3.6-plus, qwen3.5-plus, qwen3.5-plus-2026-02-15 |
| Qwen-Flash | qwen3.5-flash, qwen3.5-flash-2026-02-23 |
| Open source Qwen | qwen3.5-397b-a17b, qwen3.5-122b-a10b, qwen3.5-27b, qwen3.5-35b-a3b |
Billing
Two types of charges apply when using MCP:
- Model inference fees: Billed based on the model's token usage.
- MCP server fees: Subject to the billing rules of each MCP server provider.