Skip to content

Commit f6c6fa0

Browse files
authored
Work around schema parsing issue in Cursor (#18)
1 parent d93fb82 commit f6c6fa0

File tree

3 files changed

+35
-12
lines changed

3 files changed

+35
-12
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
},
7272
"dependencies": {
7373
"@alcyone-labs/zod-to-json-schema": "4.0.10",
74-
"@iterable/api": "0.5.0",
74+
"@iterable/api": "0.5.1",
7575
"@modelcontextprotocol/sdk": "1.18.1",
7676
"@primno/dpapi": "2.0.1",
7777
"@types/json-schema": "7.0.15",

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tools/snippets.ts

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@ import { z } from "zod";
1515
import { createTool } from "../schema-utils.js";
1616

1717
export function createSnippetTools(client: IterableClient): Tool[] {
18+
// WORKAROUND: Cursor rejects valid JSON Schema with "type": ["string", "number"].
19+
// We accept strings only and convert numeric strings back to numbers.
20+
// See: https://github.com/cursor/cursor/issues/3778
21+
const identifier: z.ZodString = z
22+
.string()
23+
.describe(
24+
"Snippet ID or name (stringified). Provide either a snippet name (string) or snippet ID (as a string)."
25+
);
26+
27+
function maybeConvertNumericString(value: string): string | number {
28+
return /^\d+$/.test(value) ? Number(value) : value;
29+
}
30+
1831
return [
1932
createTool({
2033
name: "get_snippets",
@@ -33,22 +46,32 @@ export function createSnippetTools(client: IterableClient): Tool[] {
3346
createTool({
3447
name: "get_snippet",
3548
description: "Get a snippet by ID (numeric) or name (string)",
36-
schema: GetSnippetParamsSchema,
37-
execute: (params) => client.getSnippet(params),
49+
schema: GetSnippetParamsSchema.extend({ identifier }),
50+
execute: ({ identifier }) =>
51+
client.getSnippet({
52+
identifier: maybeConvertNumericString(identifier),
53+
}),
3854
}),
3955

4056
createTool({
4157
name: "update_snippet",
4258
description: "Update a snippet by ID (numeric) or name (string)",
43-
schema: UpdateSnippetParamsSchema,
44-
execute: (params) => client.updateSnippet(params),
59+
schema: UpdateSnippetParamsSchema.extend({ identifier }),
60+
execute: (params) =>
61+
client.updateSnippet({
62+
...params,
63+
identifier: maybeConvertNumericString(params.identifier),
64+
}),
4565
}),
4666

4767
createTool({
4868
name: "delete_snippet",
4969
description: "Delete a snippet by ID (numeric) or name (string)",
50-
schema: DeleteSnippetParamsSchema,
51-
execute: (params) => client.deleteSnippet(params),
70+
schema: DeleteSnippetParamsSchema.extend({ identifier }),
71+
execute: ({ identifier }) =>
72+
client.deleteSnippet({
73+
identifier: maybeConvertNumericString(identifier),
74+
}),
5275
}),
5376
];
5477
}

0 commit comments

Comments
 (0)