I created a MCP server that needs to receive an array of objects. The input from AI agent comes correctly, but the MCP returns an error saying about that is expected a string but received an array.
The tool of the MCP server executes a webhook to receive the data and manipulate as needed. The problem is I can’t send as array, just as string.
So, If I understand correctly, your MCP server expects a request from the AI agent, but the AI is sending an array instead of a string.
So you have two options:
1) Make the AI agent convert the array to string and then nothing needs to change on the MCP side:
// In AI agent (Claude/ChatGPT) when calling MCP tool:
const fieldsData = [
{ name: "field1", type: "text" },
{ name: "field2", type: "number" }
];
// Convert to string before sending
return {
fields: JSON.stringify(fieldsData) // Now it's a string
};
2) Or make the MCP server accept the array and work with it:
// In MCP schema - change type to array
{
name: "send_webhook",
inputSchema: {
type: "object",
properties: {
fields: {
type: "array", // Instead of string
items: {
type: "object",
properties: {
name: { type: "string" },
type: { type: "string" }
}
}
}
}
}
}
// In handler - use directly as array
export async function handleWebhook(args: any) {
const fieldsArray = args.fields; // Already an array, no parsing needed
await fetch('webhook-url', {
method: 'POST',
body: JSON.stringify({
fields: fieldsArray
})
});
}
Note: There isn’t enough information to fully assess where and what exactly is breaking, but this is a classic problem with type mismatches between systems. Somewhere in your data flow, you need to make the data type conversion - either on the sending side (AI agent) or receiving side (MCP server).