We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/chrisdoc/hevy-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server
json-parser.ts•689 B
/**
* Preprocessor to handle MCP clients that send JSON-stringified arrays
* instead of native arrays for complex parameters.
*
* This is used with Zod's z.preprocess to handle cases where MCP clients
* serialize complex nested structures as JSON strings.
*
* @param val - The value to potentially parse
* @returns The parsed array if val is a valid JSON string, otherwise returns val unchanged
*/
export function parseJsonArray(val: unknown): unknown {
// Handle case where MCP client sends JSON string instead of array
if (typeof val === "string") {
try {
return JSON.parse(val);
} catch {
// Let Zod validation handle the error
return val;
}
}
return val;
}