Skip to Content
Code integrationsAnthropic Messages

MCP Server - Anthropic Messages

Claude’s Messages API can connect directly to remote MCP servers through the MCP connector beta. Define the Xweather server in mcp_servers, reference it with an MCP toolset in tools, and pass your combined Xweather API key as the authorization token.

import Anthropic from "@anthropic-ai/sdk"; const client = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY }); const message = await client.beta.messages.create({ model: "claude-sonnet-5", max_tokens: 1024, betas: ["mcp-client-2025-11-20"], mcp_servers: [ { type: "url", url: "https://mcp.api.xweather.com/mcp", name: "xweather", authorization_token: process.env.XWEATHER_API_KEY, }, ], tools: [ { type: "mcp_toolset", mcp_server_name: "xweather", default_config: { enabled: false }, configs: { xweather_get_weather_conditions: { enabled: true }, xweather_get_current_active_weather_alerts: { enabled: true }, xweather_get_current_weather_impacts: { enabled: true }, }, }, ], messages: [ { role: "user", content: "Provide a safety briefing for Austin for the next 6 hours." } ] }); const text = message.content .filter((block) => block.type === "text") .map((block) => block.text) .join("\n"); console.log(text);

Tips

  • The MCP connector is a beta feature and requires the mcp-client-2025-11-20 beta header.
  • Set default_config.enabled to false, then enable only the tools your workflow needs in configs.
  • Each entry in mcp_servers must be referenced by exactly one mcp_toolset in tools.
  • The response content array can contain text, MCP tool-use, and MCP tool-result blocks. Filter by block type before reading fields or logging results.
© 2026 Xweather (opens in a new tab)Terms of Service (opens in a new tab)Privacy Policy (opens in a new tab)