From ec5c98407574b9e2b7abf6fb686623ac9330c822 Mon Sep 17 00:00:00 2001 From: Praveen K B Date: Fri, 20 Nov 2026 12:41:28 +0530 Subject: [PATCH 1/3] fix: normalize tool schemas for OpenAI and Anthropic compatibility --- .cursor-plugin/plugin.json | 2 +- package-lock.json | 4 +- package.json | 2 +- server.json | 4 +- src/bootstrap.ts | 2 +- src/remote-tools.ts | 82 +++++++++++++++++++++++++++++++++++++- test/remote_tools.test.ts | 52 +++++++++++++++++++++++- 7 files changed, 139 insertions(+), 9 deletions(-) diff --git a/.cursor-plugin/plugin.json b/.cursor-plugin/plugin.json index c2d4111..ef7b83e 100644 --- a/.cursor-plugin/plugin.json +++ b/.cursor-plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "parseable", "displayName": "Parseable", - "version": "0.3.3", + "version": "0.3.4", "description": "Query and manage Parseable logs, metrics, datasets, and alerts from Cursor.", "author": { "name": "Parseable" diff --git a/package-lock.json b/package-lock.json index df45ef4..9e55999 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@parseable/parseable-mcp-server", - "version": "0.3.3", + "version": "0.3.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@parseable/parseable-mcp-server", - "version": "0.3.3", + "version": "0.3.4", "license": "Apache-2.0", "dependencies": { "@hono/node-server": "^2.0.12", diff --git a/package.json b/package.json index 4b0d83b..65cd404 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@parseable/parseable-mcp-server", - "version": "0.3.3", + "version": "0.3.4", "mcpName": "io.github.parseablehq/parseable-mcp-server", "description": "Model Context Protocol server for Parseable. Lets LLMs discover and query Parseable datasets.", "repository": { diff --git a/server.json b/server.json index 153a2a0..5acb588 100644 --- a/server.json +++ b/server.json @@ -7,12 +7,12 @@ "url": "https://github.com/parseablehq/parseable-mcp-server", "source": "github" }, - "version": "0.3.3", + "version": "0.3.4", "packages": [ { "registryType": "npm", "identifier": "@parseable/parseable-mcp-server", - "version": "0.3.3", + "version": "0.3.4", "transport": { "type": "stdio" } diff --git a/src/bootstrap.ts b/src/bootstrap.ts index e7e13a7..583611c 100644 --- a/src/bootstrap.ts +++ b/src/bootstrap.ts @@ -10,7 +10,7 @@ import { PARSEABLE_ICON_DATA_URI } from "./icon.js"; import { getRemoteTools } from "./remote-tools.js"; import { filterToolsForProfile, type ToolProfile, toolAllowed } from "./tool-profile.js"; -const SERVER_VERSION = "0.3.3"; +const SERVER_VERSION = "0.3.4"; function toolError(message: string): CallToolResult { return { isError: true, content: [{ type: "text", text: message }] }; diff --git a/src/remote-tools.ts b/src/remote-tools.ts index a19f4e5..3095b7f 100644 --- a/src/remote-tools.ts +++ b/src/remote-tools.ts @@ -54,6 +54,85 @@ function cacheKey(client: ParseableClient): string { return createHash("sha256").update(identity).digest("hex"); } +function isSchema(value: unknown): value is Record { + return typeof value === "object" && value !== null && !Array.isArray(value); +} + +function schemaList(value: unknown): Record[] { + return Array.isArray(value) ? value.filter(isSchema) : []; +} + +function requiredFields(schema: Record): string[] { + return Array.isArray(schema.required) + ? schema.required.filter((field): field is string => typeof field === "string") + : []; +} + +function mergeProperty(existing: unknown, incoming: unknown): unknown { + if (existing === undefined || JSON.stringify(existing) === JSON.stringify(incoming)) { + return incoming; + } + const alternatives = + isSchema(existing) && Array.isArray(existing.anyOf) ? [...existing.anyOf] : [existing]; + if (!alternatives.some((value) => JSON.stringify(value) === JSON.stringify(incoming))) { + alternatives.push(incoming); + } + return { anyOf: alternatives }; +} + +/** + * Keep advertised MCP tools compatible with function-calling providers that + * require an object root and reject top-level JSON Schema combinators. + */ +export function normalizeInputSchema(input: RemoteTool["inputSchema"]): RemoteTool["inputSchema"] { + const source = input as Record; + const unionBranches = [...schemaList(source.oneOf), ...schemaList(source.anyOf)]; + const intersectionBranches = schemaList(source.allOf); + if (unionBranches.length === 0 && intersectionBranches.length === 0) return input; + + const properties: Record = isSchema(source.properties) + ? { ...source.properties } + : {}; + for (const branch of [...unionBranches, ...intersectionBranches]) { + const branchProperties = isSchema(branch.properties) ? branch.properties : {}; + for (const [name, propertySchema] of Object.entries(branchProperties)) { + properties[name] = mergeProperty(properties[name], propertySchema); + } + } + + const required = new Set(requiredFields(source)); + for (const branch of intersectionBranches) { + for (const field of requiredFields(branch)) required.add(field); + } + if (unionBranches.length > 0) { + const common = new Set(requiredFields(unionBranches[0])); + for (const branch of unionBranches.slice(1)) { + const branchRequired = new Set(requiredFields(branch)); + for (const field of common) { + if (!branchRequired.has(field)) common.delete(field); + } + } + for (const field of common) required.add(field); + } + + const { + oneOf: _oneOf, + anyOf: _anyOf, + allOf: _allOf, + enum: _enum, + const: _const, + not: _not, + required: _required, + ...base + } = source; + return { + ...base, + type: "object", + properties, + ...(required.size > 0 ? { required: [...required] } : {}), + } as RemoteTool["inputSchema"]; +} + function validateTool(value: unknown): RemoteTool { if (!value || typeof value !== "object" || Array.isArray(value)) { throw new Error("Parseable tool registry contains a non-object tool."); @@ -70,7 +149,8 @@ function validateTool(value: unknown): RemoteTool { ) { throw new Error(`Parseable tool ${tool.name} has an invalid inputSchema.`); } - return tool as unknown as RemoteTool; + const validated = tool as unknown as RemoteTool; + return { ...validated, inputSchema: normalizeInputSchema(validated.inputSchema) }; } function validateRegistry(value: unknown): RemoteTool[] { diff --git a/test/remote_tools.test.ts b/test/remote_tools.test.ts index c0d12c2..3306c13 100644 --- a/test/remote_tools.test.ts +++ b/test/remote_tools.test.ts @@ -1,6 +1,11 @@ import { afterEach, describe, expect, it, vi } from "vitest"; import type { ParseableClient } from "../src/client.js"; -import { clearToolRegistryCache, getRemoteTools, parseCacheMaxAge } from "../src/remote-tools.js"; +import { + clearToolRegistryCache, + getRemoteTools, + normalizeInputSchema, + parseCacheMaxAge, +} from "../src/remote-tools.js"; function mockClient(fetchToolRegistry: ReturnType, apiKey = "key") { return { @@ -28,6 +33,51 @@ afterEach(() => { }); describe("remote tool registry", () => { + it("normalizes top-level unions for function-calling providers", () => { + expect( + normalizeInputSchema({ + type: "object", + anyOf: [ + { + type: "object", + properties: { dataset: { type: "string" }, query: { type: "string" } }, + required: ["dataset", "query"], + }, + { + type: "object", + properties: { dataset: { type: "string" }, trace_id: { type: "string" } }, + required: ["dataset", "trace_id"], + }, + ], + }), + ).toEqual({ + type: "object", + properties: { + dataset: { type: "string" }, + query: { type: "string" }, + trace_id: { type: "string" }, + }, + required: ["dataset"], + }); + }); + + it("keeps conflicting union field types below the object root", () => { + expect( + normalizeInputSchema({ + type: "object", + oneOf: [ + { type: "object", properties: { limit: { type: "integer" } } }, + { type: "object", properties: { limit: { type: "string" } } }, + ], + }), + ).toEqual({ + type: "object", + properties: { + limit: { anyOf: [{ type: "integer" }, { type: "string" }] }, + }, + }); + }); + it("validates and caches registry per credential scope", async () => { const fetchRegistry = vi.fn().mockResolvedValue({ notModified: false, From c182e9e6f4c77b2adb5f780dc24bc1d063dc9971 Mon Sep 17 00:00:00 2001 From: Praveen K B Date: Fri, 20 Nov 2026 12:48:58 +0530 Subject: [PATCH 2/3] fix: Fixed review comments --- src/remote-tools.ts | 36 ++++++++++++++++----- test/remote_tools.test.ts | 66 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 7 deletions(-) diff --git a/src/remote-tools.ts b/src/remote-tools.ts index 3095b7f..c5cb52d 100644 --- a/src/remote-tools.ts +++ b/src/remote-tools.ts @@ -68,16 +68,22 @@ function requiredFields(schema: Record): string[] { : []; } -function mergeProperty(existing: unknown, incoming: unknown): unknown { +function mergeProperty( + existing: unknown, + incoming: unknown, + combinator: "anyOf" | "allOf", +): unknown { if (existing === undefined || JSON.stringify(existing) === JSON.stringify(incoming)) { return incoming; } const alternatives = - isSchema(existing) && Array.isArray(existing.anyOf) ? [...existing.anyOf] : [existing]; + isSchema(existing) && Array.isArray(existing[combinator]) + ? [...(existing[combinator] as unknown[])] + : [existing]; if (!alternatives.some((value) => JSON.stringify(value) === JSON.stringify(incoming))) { alternatives.push(incoming); } - return { anyOf: alternatives }; + return { [combinator]: alternatives }; } /** @@ -86,17 +92,33 @@ function mergeProperty(existing: unknown, incoming: unknown): unknown { */ export function normalizeInputSchema(input: RemoteTool["inputSchema"]): RemoteTool["inputSchema"] { const source = input as Record; - const unionBranches = [...schemaList(source.oneOf), ...schemaList(source.anyOf)]; - const intersectionBranches = schemaList(source.allOf); + const unionBranches = [...schemaList(source.oneOf), ...schemaList(source.anyOf)].map((branch) => + normalizeInputSchema(branch as RemoteTool["inputSchema"]), + ); + const intersectionBranches = schemaList(source.allOf).map((branch) => + normalizeInputSchema(branch as RemoteTool["inputSchema"]), + ); if (unionBranches.length === 0 && intersectionBranches.length === 0) return input; const properties: Record = isSchema(source.properties) ? { ...source.properties } : {}; - for (const branch of [...unionBranches, ...intersectionBranches]) { + + const unionProperties: Record = {}; + for (const branch of unionBranches) { + const branchProperties = isSchema(branch.properties) ? branch.properties : {}; + for (const [name, propertySchema] of Object.entries(branchProperties)) { + unionProperties[name] = mergeProperty(unionProperties[name], propertySchema, "anyOf"); + } + } + for (const [name, propertySchema] of Object.entries(unionProperties)) { + properties[name] = mergeProperty(properties[name], propertySchema, "allOf"); + } + + for (const branch of intersectionBranches) { const branchProperties = isSchema(branch.properties) ? branch.properties : {}; for (const [name, propertySchema] of Object.entries(branchProperties)) { - properties[name] = mergeProperty(properties[name], propertySchema); + properties[name] = mergeProperty(properties[name], propertySchema, "allOf"); } } diff --git a/test/remote_tools.test.ts b/test/remote_tools.test.ts index 3306c13..8c049e9 100644 --- a/test/remote_tools.test.ts +++ b/test/remote_tools.test.ts @@ -78,6 +78,72 @@ describe("remote tool registry", () => { }); }); + it("preserves fields and requirements from unions nested inside intersections", () => { + expect( + normalizeInputSchema({ + type: "object", + allOf: [ + { + anyOf: [ + { + type: "object", + properties: { + dataset: { type: "string" }, + query: { type: "string" }, + }, + required: ["dataset", "query"], + }, + { + type: "object", + properties: { + dataset: { type: "string" }, + trace_id: { type: "string" }, + }, + required: ["dataset", "trace_id"], + }, + ], + }, + ], + }), + ).toEqual({ + type: "object", + properties: { + dataset: { type: "string" }, + query: { type: "string" }, + trace_id: { type: "string" }, + }, + required: ["dataset"], + }); + }); + + it("intersects constraints for the same property across allOf branches", () => { + expect( + normalizeInputSchema({ + type: "object", + allOf: [ + { + type: "object", + properties: { limit: { type: "integer", minimum: 0 } }, + }, + { + type: "object", + properties: { limit: { type: "integer", maximum: 100 } }, + }, + ], + }), + ).toEqual({ + type: "object", + properties: { + limit: { + allOf: [ + { type: "integer", minimum: 0 }, + { type: "integer", maximum: 100 }, + ], + }, + }, + }); + }); + it("validates and caches registry per credential scope", async () => { const fetchRegistry = vi.fn().mockResolvedValue({ notModified: false, From 71fcd70ca2325ee030f227a36542538bfde7a97b Mon Sep 17 00:00:00 2001 From: Praveen K B Date: Fri, 20 Nov 2026 12:52:24 +0530 Subject: [PATCH 3/3] fix: Fixed review comments --- src/remote-tools.ts | 2 +- test/remote_tools.test.ts | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/remote-tools.ts b/src/remote-tools.ts index c5cb52d..2bd2232 100644 --- a/src/remote-tools.ts +++ b/src/remote-tools.ts @@ -77,7 +77,7 @@ function mergeProperty( return incoming; } const alternatives = - isSchema(existing) && Array.isArray(existing[combinator]) + isSchema(existing) && Object.keys(existing).length === 1 && Array.isArray(existing[combinator]) ? [...(existing[combinator] as unknown[])] : [existing]; if (!alternatives.some((value) => JSON.stringify(value) === JSON.stringify(incoming))) { diff --git a/test/remote_tools.test.ts b/test/remote_tools.test.ts index 8c049e9..d9a8021 100644 --- a/test/remote_tools.test.ts +++ b/test/remote_tools.test.ts @@ -144,6 +144,41 @@ describe("remote tool registry", () => { }); }); + it("keeps sibling constraints when extending a property that already has allOf", () => { + expect( + normalizeInputSchema({ + type: "object", + properties: { + limit: { + type: "integer", + minimum: 0, + allOf: [{ maximum: 100 }], + }, + }, + allOf: [ + { + type: "object", + properties: { limit: { multipleOf: 2 } }, + }, + ], + }), + ).toEqual({ + type: "object", + properties: { + limit: { + allOf: [ + { + type: "integer", + minimum: 0, + allOf: [{ maximum: 100 }], + }, + { multipleOf: 2 }, + ], + }, + }, + }); + }); + it("validates and caches registry per credential scope", async () => { const fetchRegistry = vi.fn().mockResolvedValue({ notModified: false,