M
Mastra3d ago
Hro

Cannot call mcp tool directly?

Hi! From an endpoint I am trying to directly call an mcp tool:
const client = c.get("mastra")
const markitdownAgent = client.getAgent('markitdownAgent')
const tools = await markitdownAgent.getTools();

const result = await tools['markitdown_convert_to_markdown'].execute({uri: data});
const client = c.get("mastra")
const markitdownAgent = client.getAgent('markitdownAgent')
const tools = await markitdownAgent.getTools();

const result = await tools['markitdown_convert_to_markdown'].execute({uri: data});
This results in a validation error at the pydantic level. Changing anything in the execute results in a validation error on the zod level. When I use the playground to invoke this exact same mcp it works flawlessly? Any clue to how this is?
5 Replies
Mastra Triager
📝 Created GitHub issue: https://github.com/mastra-ai/mastra/issues/10865 🔍 If you're experiencing an error, please provide a minimal reproducible example whenever possible to help us resolve it quickly. 🙏 Thank you for helping us improve Mastra!
Abhi Aiyer
Abhi Aiyer3d ago
are you complying with the schema of that tool? What versions are you on? In 0.x tool args were nested in the “context” key So execute({ context: {} })
Hro
HroOP3d ago
I will try that tomorrow. If I passed anything but .execute({uri: data}) it would throw a validation error so I assumed it was correct.
Abhi Aiyer
Abhi Aiyer3d ago
ill do a repro for you real quick In 0.x
await tools?.['weatherTool']?.execute?.({
context: { location: 'New York' },
runtimeContext: new RuntimeContext()
});
await tools?.['weatherTool']?.execute?.({
context: { location: 'New York' },
runtimeContext: new RuntimeContext()
});
In 1.x
await tools?.['weatherTool']?.execute?.({ location: 'New York' });
await tools?.['weatherTool']?.execute?.({ location: 'New York' });
pydantic level would be the MCP server youre using ?
Hro
HroOP3d ago
markitdown mcp I'll give it a try thanks

Did you find this page helpful?