Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .cursor-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions server.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }] };
Expand Down
104 changes: 103 additions & 1 deletion src/remote-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,107 @@ function cacheKey(client: ParseableClient): string {
return createHash("sha256").update(identity).digest("hex");
}

function isSchema(value: unknown): value is Record<string, unknown> {
return typeof value === "object" && value !== null && !Array.isArray(value);
}

function schemaList(value: unknown): Record<string, unknown>[] {
return Array.isArray(value) ? value.filter(isSchema) : [];
}

function requiredFields(schema: Record<string, unknown>): string[] {
return Array.isArray(schema.required)
? schema.required.filter((field): field is string => typeof field === "string")
: [];
}

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) && Object.keys(existing).length === 1 && Array.isArray(existing[combinator])
? [...(existing[combinator] as unknown[])]
: [existing];
if (!alternatives.some((value) => JSON.stringify(value) === JSON.stringify(incoming))) {
alternatives.push(incoming);
}
return { [combinator]: 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<string, unknown>;
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<string, unknown> = isSchema(source.properties)
? { ...source.properties }
: {};

const unionProperties: Record<string, unknown> = {};
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, "allOf");
}
}

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.");
Expand All @@ -70,7 +171,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[] {
Expand Down
153 changes: 152 additions & 1 deletion test/remote_tools.test.ts
Original file line number Diff line number Diff line change
@@ -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<typeof vi.fn>, apiKey = "key") {
return {
Expand Down Expand Up @@ -28,6 +33,152 @@ 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("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("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,
Expand Down
Loading