@@ -19,7 +19,7 @@ import { dotGenaiscriptPath } from "./workdir.js";
1919import { YAMLStringify } from "./yaml.js" ;
2020import { resolvePromptInjectionDetector } from "./contentsafety.js" ;
2121import { genaiscriptDebug } from "./debug.js" ;
22- import type { McpClient , McpServerConfig , ToolCallback } from "./types.js" ;
22+ import type { JSONSchemaObject , McpClient , McpServerConfig , ToolCallback } from "./types.js" ;
2323import { Client } from "@modelcontextprotocol/sdk/client/index.js" ;
2424import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js" ;
2525
@@ -68,6 +68,16 @@ function resolveMcpEnv(_env: Record<string, string>) {
6868 return res ;
6969}
7070
71+ function patchInputSchema ( inputSchema : any ) : any {
72+ const res = structuredClone ( inputSchema ) ;
73+ delete res [ "$schema" ] ;
74+ if ( res . type === "object" ) {
75+ if ( ! res . properties ) res . properties = { } ;
76+ if ( ! res . required ) res . required = [ ] ;
77+ }
78+ return res ;
79+ }
80+
7181export class McpClientManager extends EventTarget implements AsyncDisposable {
7282 private _clients : McpClient [ ] = [ ] ;
7383 constructor ( ) {
@@ -143,7 +153,7 @@ export class McpClientManager extends EventTarget implements AsyncDisposable {
143153 name : t . name ,
144154 description : t . description ,
145155 // eslint-disable-next-line @typescript-eslint/no-explicit-any
146- inputSchema : t . inputSchema as any ,
156+ inputSchema : patchInputSchema ( t . inputSchema ) ,
147157 } ) satisfies McpToolReference ,
148158 ) ;
149159 } ;
@@ -214,7 +224,7 @@ export class McpClientManager extends EventTarget implements AsyncDisposable {
214224 name : disableToolIdMangling ? name : `${ id } _${ name } ` ,
215225 description,
216226 // eslint-disable-next-line @typescript-eslint/no-explicit-any
217- parameters : inputSchema as any ,
227+ parameters : patchInputSchema ( inputSchema ) ,
218228 } ,
219229 options : toolOptions ,
220230 generator,
0 commit comments