We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/curvegrid/multibaas-mcp-poc'
If you have feedback or need assistance with the MCP directory API, please join our Discord server
schema.ts•1.82 KiB
// src/common/schema.ts
import { z } from "zod";
import { zodToJsonSchema as originalZodToJsonSchema } from "zod-to-json-schema";
/**
* Traverses a JSON Schema object and ensures all array types have a valid "items" property.
* This is a direct fix for VS Code's strict schema validation that requires all array types
* to have an "items" property.
*
* @param obj The JSON schema object to fix
* @returns The fixed schema
*/
function fixArrayItems(obj: any): any {
if (!obj || typeof obj !== "object") {
return obj;
}
// Fix array type with missing items property
if (obj.type === "array" && !obj.items) {
// Add a default items definition - string type is a safe fallback
obj.items = { type: "string" };
}
// Recursively process all properties
if (!Array.isArray(obj)) {
for (const key in obj) {
if (typeof obj[key] === "object" && obj[key] !== null) {
obj[key] = fixArrayItems(obj[key]);
}
}
} else {
// Process array elements
for (let i = 0; i < obj.length; i++) {
if (typeof obj[i] === "object" && obj[i] !== null) {
obj[i] = fixArrayItems(obj[i]);
}
}
}
return obj;
}
/**
* Enhanced version of zodToJsonSchema that fixes array types for VS Code compatibility.
* This addresses the "tool parameters array type must have items" error in VS Code's MCP schema validation.
*
* @param zodSchema The Zod schema to convert
* @param options Options for the original zodToJsonSchema function
* @returns A VS Code-compatible JSON Schema
*/
export function zodToJsonSchema(
zodSchema: z.ZodType,
options?: Parameters<typeof originalZodToJsonSchema>[1],
) {
// Get the original JSON schema
const jsonSchema = originalZodToJsonSchema(zodSchema, options);
// Fix any array types that don't have items property
return fixArrayItems(jsonSchema);
}