@@ -15,6 +15,17 @@ import { z } from "zod";
1515import { createTool } from "../schema-utils.js" ;
1616
1717export function createSnippetTools ( client : IterableClient ) : Tool [ ] {
18+ // The union type (string | number) causes Cursor to reject the (valid) JSON schema
19+ const identifier : z . ZodString = z
20+ . string ( )
21+ . describe (
22+ "Snippet ID or name (stringified). Provide either a snippet name (string) or snippet ID (as a string)."
23+ ) ;
24+
25+ function maybeConvertNumericString ( value : string ) : string | number {
26+ return / ^ \d + $ / . test ( value ) ? Number ( value ) : value ;
27+ }
28+
1829 return [
1930 createTool ( {
2031 name : "get_snippets" ,
@@ -33,22 +44,32 @@ export function createSnippetTools(client: IterableClient): Tool[] {
3344 createTool ( {
3445 name : "get_snippet" ,
3546 description : "Get a snippet by ID (numeric) or name (string)" ,
36- schema : GetSnippetParamsSchema ,
37- execute : ( params ) => client . getSnippet ( params ) ,
47+ schema : GetSnippetParamsSchema . extend ( { identifier } ) ,
48+ execute : ( { identifier } ) =>
49+ client . getSnippet ( {
50+ identifier : maybeConvertNumericString ( identifier ) ,
51+ } ) ,
3852 } ) ,
3953
4054 createTool ( {
4155 name : "update_snippet" ,
4256 description : "Update a snippet by ID (numeric) or name (string)" ,
43- schema : UpdateSnippetParamsSchema ,
44- execute : ( params ) => client . updateSnippet ( params ) ,
57+ schema : UpdateSnippetParamsSchema . extend ( { identifier } ) ,
58+ execute : ( params ) =>
59+ client . updateSnippet ( {
60+ ...params ,
61+ identifier : maybeConvertNumericString ( params . identifier ) ,
62+ } ) ,
4563 } ) ,
4664
4765 createTool ( {
4866 name : "delete_snippet" ,
4967 description : "Delete a snippet by ID (numeric) or name (string)" ,
50- schema : DeleteSnippetParamsSchema ,
51- execute : ( params ) => client . deleteSnippet ( params ) ,
68+ schema : DeleteSnippetParamsSchema . extend ( { identifier } ) ,
69+ execute : ( { identifier } ) =>
70+ client . deleteSnippet ( {
71+ identifier : maybeConvertNumericString ( identifier ) ,
72+ } ) ,
5273 } ) ,
5374 ] ;
5475}
0 commit comments