Skip to content

[BUG] Claude Code SDK: SDK MCP server faills to connect due to closed stream #6710

@codylund

Description

@codylund

Environment

  • Platform (select one):
    • Anthropic API
    • AWS Bedrock
    • Google Vertex AI
    • Other: Claude Code SDK
  • Claude CLI version: 1.0.96
  • Operating System: macOS 15.1
  • Terminal: Terminal App

Bug Description

The new SDK MCP server type does not work with basic string prompts.
Running with DEBUG=true, I see the following error:

[ERROR] MCP server "test" Failed to connect SDK MCP server: Error: Stream closed

Steps to Reproduce

Below is a basic sample:

import { createSdkMcpServer, query, tool } from "@anthropic-ai/claude-code";
import { z } from "zod";

const mcp = createSdkMcpServer({
  name: "test",
  tools: [
    tool(
      "add",
      "Add two numbers",
      {
        a: z.number(),
        b: z.number(),
      },
      async ({ a, b }) => {
        return {
          content: [
            {
              type: "text",
              text: `${a + b}`,
            },
          ],
        };
      }
    ),
  ],
});

for await (const message of query({
  //prompt: generateMessages(),
  prompt: "Use the tool to add 1 and 2 and return the result.",
  options: {
    mcpServers: {
      test: mcp,
    },
    allowedTools: ["mcp__test__add"],
  },
})) {
  console.log(JSON.stringify(message));
}

Expected Behavior

Prompt should run with successful connection and access to the SDK MCP server.

Actual Behavior

Claude CLI process exits with an error.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions