Describe the problem/error/question
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.
What is the error message (if any)?
Error: [ { “code”: “invalid_type”, “expected”: “string”, “received”: “array”, “path”: [ “fields” ], “message”: “Expected string, received array” } ]
Information on your n8n setup
- n8n version: 1.99.1
- Database (default: SQLite): Postgres
- n8n EXECUTIONS_PROCESS setting (default: own, main):
- Running n8n via (Docker, npm, n8n cloud, desktop app): Digital Ocean
- Operating system: Linux
Hi,
Looking at your error - classic type mismatch between MCP and n8n.
Keep MCP schema as “string”, parse it inside the handler:
const fieldsArray = JSON.parse(args.fields); // Parse string to array
// Send to n8n
body: JSON.stringify({
fields: fieldsArray
})
Alternative: If you want to keep array in MCP, stringify before sending:
body: JSON.stringify({
fields: JSON.stringify(args.fields)
})
First approach is cleaner. The AI sends it as string, you parse it, then send proper array to n8n.
I tried this approach, but when I try to parse or stringify the content, it makes the MCP inaccessible.
This should be in the agent or in the tool inside MCP server?
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).