▲HIGHLAND DOCS

MCP for Grok

xAI's API can connect to remote MCP servers during a response: Grok lists the Highland tools, calls them and answers with the results. Your code only sends the server URL and auth.

Endpointhttps://api.x.ai/v1/responses
Modelgrok-4.7 (any Grok model with tool use)
Tool type"mcp" with server_url, server_label, allowed_tools, headers

xAI SDK (Python)

python (xai-sdk)
# pip install xai-sdk
import os
from xai_sdk import Client
from xai_sdk.chat import user
from xai_sdk.tools import mcp

client = Client(api_key=os.environ["XAI_API_KEY"])

chat = client.chat.create(
    model="grok-4.7",
    tools=[mcp(
        server_url="https://api.highlnd-intel.group/mcp",
        server_label="highland",
        extra_headers={"Authorization": f"Bearer {os.environ['HIGHLAND_KEY']}"},
        allowed_tool_names=["dns-lookup", "mail-auth", "rdap-lookup"],
    )],
)
chat.append(user("Who runs example.com and is its email protected against spoofing?"))
response = chat.sample()
print(response.content)

Responses API (curl)

curl
curl -s https://api.x.ai/v1/responses \
  -H "authorization: Bearer $XAI_API_KEY" \
  -H "content-type: application/json" \
  -d '{
    "model": "grok-4.7",
    "input": [{"role": "user", "content": "Check the security headers of https://example.com"}],
    "tools": [{
      "type": "mcp",
      "server_url": "https://api.highlnd-intel.group/mcp",
      "server_label": "highland",
      "allowed_tools": ["header-audit", "https-redirect"],
      "headers": {"Authorization": "Bearer '"$HIGHLAND_KEY"'"}
    }]
  }'

OpenAI-compatible SDK

The xAI API is compatible with the OpenAI SDK, so the Responses example for OpenAI works with two changes:

python
from openai import OpenAI
client = OpenAI(api_key=os.environ["XAI_API_KEY"], base_url="https://api.x.ai/v1")
resp = client.responses.create(
    model="grok-4.7",
    tools=[{"type": "mcp", "server_label": "highland", "server_url": "https://api.highlnd-intel.group/mcp",
            "headers": {"Authorization": f"Bearer {os.environ['HIGHLAND_KEY']}"}}],
    input="Translate 'payment received' into French and Spanish",
)
print(resp.output_text)

Tips

  • Always pass allowed_tools / allowed_tool_names for a focused task. It cuts input tokens and stops Grok picking an unrelated tool.
  • Tool calls are billed to your Highland key, model tokens to your xAI account.
  • If a call returns insufficient_credits, Grok sees the error text and will say so: top up.