@@ -15,6 +15,19 @@ import { z } from "zod";
1515import { createTool } from "../schema-utils.js" ;
1616
1717export 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