@@ -2,6 +2,16 @@ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
22import { Tool } from "@modelcontextprotocol/sdk/types.js" ;
33import { McpResponse } from "./types.js" ;
44
5+ // JSON value type matching the client utils
6+ type JsonValue =
7+ | string
8+ | number
9+ | boolean
10+ | null
11+ | undefined
12+ | JsonValue [ ]
13+ | { [ key : string ] : JsonValue } ;
14+
515type JsonSchemaType = {
616 type : "string" | "number" | "integer" | "boolean" | "array" | "object" ;
717 description ?: string ;
@@ -20,7 +30,7 @@ export async function listTools(client: Client): Promise<McpResponse> {
2030 }
2131}
2232
23- function convertParameterValue ( value : string , schema : JsonSchemaType ) : unknown {
33+ function convertParameterValue ( value : string , schema : JsonSchemaType ) : JsonValue {
2434 if ( ! value ) {
2535 return value ;
2636 }
@@ -35,7 +45,7 @@ function convertParameterValue(value: string, schema: JsonSchemaType): unknown {
3545
3646 if ( schema . type === "object" || schema . type === "array" ) {
3747 try {
38- return JSON . parse ( value ) ;
48+ return JSON . parse ( value ) as JsonValue ;
3949 } catch ( error ) {
4050 return value ;
4151 }
@@ -47,8 +57,8 @@ function convertParameterValue(value: string, schema: JsonSchemaType): unknown {
4757function convertParameters (
4858 tool : Tool ,
4959 params : Record < string , string > ,
50- ) : Record < string , unknown > {
51- const result : Record < string , unknown > = { } ;
60+ ) : Record < string , JsonValue > {
61+ const result : Record < string , JsonValue > = { } ;
5262 const properties = tool . inputSchema . properties || { } ;
5363
5464 for ( const [ key , value ] of Object . entries ( params ) ) {
@@ -68,18 +78,29 @@ function convertParameters(
6878export async function callTool (
6979 client : Client ,
7080 name : string ,
71- args : Record < string , string > ,
81+ args : Record < string , JsonValue > ,
7282) : Promise < McpResponse > {
7383 try {
7484 const toolsResponse = await listTools ( client ) ;
7585 const tools = toolsResponse . tools as Tool [ ] ;
7686 const tool = tools . find ( ( t ) => t . name === name ) ;
7787
78- let convertedArgs : Record < string , unknown > = args ;
88+ let convertedArgs : Record < string , JsonValue > = args ;
7989
8090 if ( tool ) {
81- // Convert parameters based on the tool's schema
82- convertedArgs = convertParameters ( tool , args ) ;
91+ // Convert parameters based on the tool's schema, but only for string values
92+ // since we now accept pre-parsed values from the CLI
93+ const stringArgs : Record < string , string > = { } ;
94+ for ( const [ key , value ] of Object . entries ( args ) ) {
95+ if ( typeof value === 'string' ) {
96+ stringArgs [ key ] = value ;
97+ }
98+ }
99+
100+ if ( Object . keys ( stringArgs ) . length > 0 ) {
101+ const convertedStringArgs = convertParameters ( tool , stringArgs ) ;
102+ convertedArgs = { ...args , ...convertedStringArgs } ;
103+ }
83104 }
84105
85106 const response = await client . callTool ( {
0 commit comments