Skip to content

Connect ToolRouter to the xAI API

Give a Grok powered agent one ToolRouter MCP connection for research, SEO, leads, images, video and live data. The xAI Responses API manages the remote MCP connection and tool calls on the server.

This is the API path for a product or bot built with xAI. For Grok chat at grok.com, use Connect to Grok.

What you need

  • An XAI_API_KEY for the xAI Responses API
  • A TOOLROUTER_API_KEY for the ToolRouter MCP server

The xAI Responses API accepts an authorization token for a remote MCP server, but it does not complete ToolRouter OAuth in a browser. Create a named ToolRouter API key in the dashboard and keep both keys on the server.

Python example

Install the OpenAI compatible client in your project, then run:

python
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["XAI_API_KEY"],
    base_url="https://api.x.ai/v1",
)

response = client.responses.create(
    model="grok-4.6",
    input="Audit https://example.com and give me the five highest impact SEO fixes with evidence.",
    tools=[
        {
            "type": "mcp",
            "server_url": "https://api.toolrouter.com/mcp",
            "server_label": "toolrouter",
            "server_description": "Specialist tools for SEO, research, leads, images, video and live data",
            "authorization": os.environ["TOOLROUTER_API_KEY"],
            "allowed_tools": ["discover", "use_tool", "credential_guide"],
        }
    ],
)

print(response.output_text)

One server entry gives the agent access to the ToolRouter catalog. discover finds the right specialist tool, use_tool runs it, and credential_guide explains any provider access a particular tool still needs.

Why limit the exposed tools

xAI injects every exposed MCP tool into the model context when allowed_tools is omitted. ToolRouter exposes a small gateway set that searches the larger catalog, so allowing the three tools above keeps context focused while preserving access to the full catalog.

Security and approval

Keep both API keys in server environment variables. Do not put them in browser code, mobile apps, public repositories or prompts. Paid ToolRouter tools can charge the ToolRouter account, so set an account spend cap and test with free tools first.

Current xAI limitations

xAI documents Remote MCP support in its native SDK, OpenAI compatible Responses API and Speech to Speech API. It also documents that require_approval and connector_id are not currently supported in the OpenAI compatible Responses API, so enforce tool policy and spending limits on the ToolRouter account.

Source: xAI Remote MCP Tools, last checked 30 August 2026.

The request shape was checked against xAI's current documentation. A live xAI request with production keys was not exercised in this release.