anthropics / anthropics/claude-agent-sdk-typescript

User MCP Tool Results Not Incorporated Into Agent Response

Open
#108 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Shell
Stars
1.8k
Forks
226
PR merge metrics
No merged PRs in 30d

Description

When using SDK MCP servers with claude-agent-sdk, the outer agent calls MCP tools but does not incorporate their results into its response. Instead, the agent generates text based on its training data, ignoring the actual tool outputs.

Environment

- @anthropic-ai/claude-agent-sdk: (current version)
- Node.js: 18.x
- Platform: macOS

Reproduction Steps

1. Create an SDK MCP server with a tool that returns structured data:

import { createSdkMcpServer, tool } from '@anthropic-ai/claude-agent-sdk';
import { z } from 'zod';

const myMcpServer = createSdkMcpServer({
name: 'my-server',
version: '1.0.0',
tools: [
tool(
'get_data',
'Returns specific data',
{ query: z.string() },
async (args) => {
// This returns a specific, verifiable result
return {
content: [{
type: 'text',
text: JSON.stringify({
result: 'UNIQUE_VALUE_12345',
source: 'mcp-tool'
})
}],
};
}
),
],
});

2. Run a query that should use this tool and then use its result:

import { query } from '@anthropic-ai/claude-agent-sdk';

const result = await query({
prompt: 'Call get_data with query "test", then report exactly what it returned.',
options: {
mcpServers: [myMcpServer],
},
});

Expected Behavior

The agent should:
1. Call mcp__my-server__get_data
2. Receive the result { result: 'UNIQUE_VALUE_12345', source: 'mcp-tool' }
3. Include this exact value in its response

Actual Behavior

The agent:
1. Calls the MCP tool (confirmed via internal logging within the tool)
2. Does NOT incorporate the result into its response
3. Generates text based on training data instead
4. May claim "connectivity issues" or similar when no issues exist

Evidence

In our case, we have a discovery tool that uses an internal Claude session to find document URLs. The tool successfully finds:
documentUrl: "https://example.com/actual-document.pdf"

But the outer agent's response contains completely different, hallucinated URLs from its training data, and claims "MCP server connectivity issues prevented storage" despite all servers showing status: connected.

Logs show:
// Tool executes and finds result
{"msg":"Discovery completed","documentUrl":"https://example.com/actual-document.pdf"}

// But agent response contains different URLs and claims issues
"All MCP servers appear to be experiencing connectivity issues..."
[Lists hallucinated URLs not returned by the tool]

Workaround

Using built-in tools (Read, Bash, WebSearch) works correctly - their results ARE incorporated into the agent's response. Only SDK MCP server tool results appear to be lost.

Additional Context

- The tool_call message type is not emitted for MCP tools (only for built-in tools), so toolCallCount stays at 0
- The MCP tools DO execute (internal logs prove it)
- But the results don't flow back into the agent's context for generating the response

---

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.