Repository Public
1<!-- source: https://docs.x.ai/developers/tools/remote-mcp (from https://docs.x.ai/llms-full.txt, retrieved 2026-09-19T05:28:55Z) -->2#### Tools34# Remote MCP Tools56Remote MCP Tools allow Grok to connect to external MCP (Model Context Protocol) servers, extending its capabilities with custom tools from third parties or your own implementations. Simply specify a server URL and optional configuration - xAI manages the MCP server connection and interaction on your behalf.78## SDK Support910Remote MCP tools are supported in the xAI native SDK, the OpenAI compatible Responses API, and the [Speech to Speech API](/developers/model-capabilities/audio/speech-to-speech#remote-mcp-tools).1112> [!NOTE]13>14> The `require_approval` and `connector_id` parameters in the OpenAI Responses API are not currently supported.1516## Configuration1718To use remote MCP tools, you need to configure the connection to your MCP server in the tools array of your request.1920| Parameter | Required | Description |21|-----------|-------------------|-------------|22| `server_url` | Yes | The URL of the MCP server to connect to. Only Streaming HTTP and SSE transports are supported. |23| `server_label` | Yes | A label to identify the server (used for tool call prefixing) |24| `server_description` | No | A description of what the server provides |25| `allowed_tools` | No | List of specific tool names to allow (empty allows all). The xAI native SDK uses the parameter name `allowed_tool_names`. |26| `authorization` | No | A token that will be set in the Authorization header on requests to the MCP server |27| `headers` | No | Additional headers to include in requests. The xAI native SDK uses the parameter name `extra_headers`. |2829### Basic MCP Tool Usage3031```pythonXAI32import os3334from xai_sdk import Client35from xai_sdk.chat import user36from xai_sdk.tools import mcp3738client = Client(api_key=os.getenv("XAI_API_KEY"))39chat = client.chat.create(40 model="grok-4.6",41 tools=[42 mcp(server_url="https://mcp.deepwiki.com/mcp", server_label="deepwiki"),43 ],44 include=["verbose_streaming"],45)4647chat.append(user("What can you do with https://github.com/xai-org/xai-sdk-python?"))4849is_thinking = True50for response, chunk in chat.stream():51 # View the server-side tool calls as they are being made in real-time52 for tool_call in chunk.tool_calls:53 print(f"\\nCalling tool: {tool_call.function.name} with arguments: {tool_call.function.arguments}")54 if response.usage.reasoning_tokens and is_thinking:55 print(f"\\rThinking... ({response.usage.reasoning_tokens} tokens)", end="", flush=True)56 if chunk.content and is_thinking:57 print("\\n\\nFinal Response:")58 is_thinking = False59 if chunk.content and not is_thinking:60 print(chunk.content, end="", flush=True)6162print("\\n\\nUsage:")63print(response.usage)64print(response.server_side_tool_usage)65print("\\n\\nServer Side Tool Calls:")66print(response.tool_calls)67```6869```pythonOpenAISDK70import os71from openai import OpenAI7273api_key = os.getenv("XAI_API_KEY")74client = OpenAI(75 api_key=api_key,76 base_url="https://api.x.ai/v1",77)7879response = client.responses.create(80 model="grok-4.6",81 input=[82 {83 "role": "user",84 "content": "What can you do with https://github.com/xai-org/xai-sdk-python?",85 },86 ],87 tools=[88 {89 "type": "mcp",90 "server_url": "https://mcp.deepwiki.com/mcp",91 "server_label": "deepwiki",92 }93 ],94)9596print(response)97```9899```pythonRequests100import os101import requests102103url = "https://api.x.ai/v1/responses"104headers = {105 "Content-Type": "application/json",106 "Authorization": f"Bearer {os.getenv('XAI_API_KEY')}"107}108payload = {109 "model": "grok-4.6",110 "input": [111 {112 "role": "user",113 "content": "What can you do with https://github.com/xai-org/xai-sdk-python?"114 }115 ],116 "tools": [117 {118 "type": "mcp",119 "server_url": "https://mcp.deepwiki.com/mcp",120 "server_label": "deepwiki",121 }122 ]123}124response = requests.post(url, headers=headers, json=payload)125print(response.json())126```127128```bash129curl https://api.x.ai/v1/responses \\130 -H "Content-Type: application/json" \\131 -H "Authorization: Bearer $XAI_API_KEY" \\132 -d '{133 "model": "grok-4.6",134 "input": [135 {136 "role": "user",137 "content": "What can you do with https://github.com/xai-org/xai-sdk-python?"138 }139 ],140 "tools": [141 {142 "type": "mcp",143 "server_url": "https://mcp.deepwiki.com/mcp",144 "server_label": "deepwiki"145 }146 ]147}'148```149150## Tool Enablement and Access Control151152When you configure a Remote MCP Tool without specifying `allowed_tools`, all tool definitions exposed by the MCP server are automatically injected into the model's context. This means the model gains access to every tool that the MCP server provides, allowing it to use any of them during the conversation.153154For example, if an MCP server exposes 10 different tools and you don't specify `allowed_tools`, all 10 tool definitions will be available to the model. The model can then choose to call any of these tools based on the user's request and the tool descriptions.155156Use the `allowed_tools` parameter to selectively enable only specific tools from an MCP server. This can give you several key benefits:157158* **Better Performance**: Reduce context overhead by limiting tool definitions the model needs to consider159* **Reduced Risk**: For example, restrict access to tools that only perform read-only operations to prevent the model from modifying data160161```pythonXAI162# Enable only specific tools from a server with many available tools163mcp(164 server_url="https://comprehensive-tools.example.com/mcp",165 allowed_tool_names=["search_database", "format_data"]166)167```168169Instead of giving the model access to every tool the server offers, this approach keeps Grok focused and efficient while ensuring it has exactly the capabilities it needs.170171## Multi-Server Support172173Enable multiple MCP servers simultaneously to create a rich ecosystem of specialized tools:174175```pythonXAI176chat = client.chat.create(177 model="grok-4.6",178 tools=[179 mcp(server_url="https://mcp.deepwiki.com/mcp", server_label="deepwiki"),180 mcp(server_url="https://your-custom-tools.com/mcp", server_label="custom"),181 mcp(server_url="https://api.example.com/tools", server_label="api-tools"),182 ],183)184```185186Each server can provide different capabilities - documentation tools, API integrations, custom business logic, or specialized data processing - all accessible within a single conversation.187188## Best Practices189190* **Provide clear server metadata**: Use descriptive `server_label` and `server_description` when configuring multiple MCP servers to help the model understand each server's purpose and select the right tools191* **Filter tools appropriately**: Use `allowed_tools` to restrict access to only necessary tools, especially when servers have many tools since the model must keep all available tool definitions in context192* **Use secure connections**: Always use HTTPS URLs and implement proper authentication mechanisms on your MCP server193* **Provide Examples**: While the model can generally figure out what tools to use based on the tool descriptions and the user request it may help to provide examples in the prompt194