The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
fix(mcp): Remove jsonSchema wrapper from tool inputSchema for MCP compatibility (#15349)
Kenny Vaneetvelde7f911913c7ce
diff --git a/packages/twenty-server/src/engine/core-modules/ai/services/__tests__/mcp.service.spec.ts b/packages/twenty-server/src/engine/core-modules/ai/services/__tests__/mcp.service.spec.tsindex 482457d7678..9d21d3b3f5e 100644--- a/packages/twenty-server/src/engine/core-modules/ai/services/__tests__/mcp.service.spec.ts+++ b/packages/twenty-server/src/engine/core-modules/ai/services/__tests__/mcp.service.spec.ts@@ -330,7 +330,7 @@ describe('McpService', () => {{name: 'testTool',description: 'Test tool',- inputSchema: jsonSchema({ type: 'object', properties: {} }),+ inputSchema: { type: 'object', properties: {} },},],}),diff --git a/packages/twenty-server/src/engine/core-modules/ai/services/mcp.service.ts b/packages/twenty-server/src/engine/core-modules/ai/services/mcp.service.tsindex 44644228489..ce1eefd9571 100644--- a/packages/twenty-server/src/engine/core-modules/ai/services/mcp.service.ts+++ b/packages/twenty-server/src/engine/core-modules/ai/services/mcp.service.ts@@ -212,11 +212,23 @@ export class McpService {private handleToolsListing(id: string | number, toolSet: ToolSet) {const toolsArray = Object.entries(toolSet).filter(([, def]) => !!def.inputSchema)- .map(([name, def]) => ({- name,- description: def.description,- inputSchema: def.inputSchema,- }));+ .map(([name, def]) => {+ // Unwrap the AI SDK's jsonSchema wrapper if present+ // The AI SDK serializes schemas as { jsonSchema: {...} } but MCP expects {...} directly+ const inputSchema = def.inputSchema;+ const unwrappedSchema =+ inputSchema &&+ typeof inputSchema === 'object' &&+ 'jsonSchema' in inputSchema+ ? inputSchema.jsonSchema+ : inputSchema;++ return {+ name,+ description: def.description,+ inputSchema: unwrappedSchema,+ };+ });return wrapJsonRpcResponse(id, {result: {