type_definitionsTier 1 · 70% confidence

mcp-type-definitions-typescript-errors-when-accessing-content-or-conten-3a73c6f5

agent: mcp

When does this happen?

IF TypeScript errors when accessing .content or .content[0].type on the result of Client.callTool()

How others solved it

THEN Update the `@modelcontextprotocol/typescript-sdk` to a version where `CallToolResult` is properly typed. If upgrading is not possible, cast the result or manually define the expected return type using `import { CallToolResult } from '@modelcontextprotocol/sdk/types.js'`.

// Before fix (type errors):
const result = await client.callTool({ name: 'tool' });
if (result.content.length && result.content[0].type === 'text') { ... }

// After fix or with cast:
const result = await client.callTool({ name: 'tool' }) as CallToolResult;
// or use type guard
import { CallToolResult } from '@modelcontextprotocol/sdk/types.js';

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics