Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 30 additions & 18 deletions mcpServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,35 @@ dotenv.config({ path: path.resolve(__dirname, ".env") });

const SERVER_NAME = "webex-messaging-mcp-server";

/**
* Convert a single JSON Schema type definition to a Zod type (recursive)
*/
function jsonSchemaTypeToZod(prop) {
if (!prop || typeof prop !== 'object') {
return z.any();
}

if (prop.type === 'string') {
return z.string();
} else if (prop.type === 'number') {
return z.number();
} else if (prop.type === 'integer') {
return z.number().int();
} else if (prop.type === 'boolean') {
return z.boolean();
} else if (prop.type === 'array') {
const itemSchema = prop.items ? jsonSchemaTypeToZod(prop.items) : z.any();
return z.array(itemSchema);
} else if (prop.type === 'object') {
if (prop.properties) {
return z.object(convertJsonSchemaToZod(prop.properties, prop.required || []));
}
return z.record(z.any());
} else {
return z.string();
}
}

/**
* Convert JSON Schema properties to Zod schema format
* Required by MCP SDK v1.17.4 for proper parameter validation
Expand All @@ -33,24 +62,7 @@ function convertJsonSchemaToZod(properties, required = []) {
const zodSchema = {};

for (const [key, prop] of Object.entries(properties)) {
let zodType;

if (prop.type === 'string') {
zodType = z.string();
} else if (prop.type === 'number') {
zodType = z.number();
} else if (prop.type === 'integer') {
zodType = z.number().int();
} else if (prop.type === 'boolean') {
zodType = z.boolean();
} else if (prop.type === 'array') {
zodType = z.array(z.any());
} else if (prop.type === 'object') {
zodType = z.object({});
} else {
// Default to string for unknown types
zodType = z.string();
}
let zodType = jsonSchemaTypeToZod(prop);

// Make optional if not in required array
if (!required.includes(key)) {
Expand Down
Loading
Loading