Parse tool args from CLI as JsonValue instead of just strings

This commit is contained in:
olaservo 2025-07-26 09:15:27 -07:00
commit 99b962d445

View file

@ -1,6 +1,16 @@
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { McpResponse } from "./types.js";
// JSON value type matching the client utils
type JsonValue =
| string
| number
| boolean
| null
| undefined
| JsonValue[]
| { [key: string]: JsonValue };
// List available prompts
export async function listPrompts(client: Client): Promise<McpResponse> {
try {
@ -17,12 +27,26 @@ export async function listPrompts(client: Client): Promise<McpResponse> {
export async function getPrompt(
client: Client,
name: string,
args?: Record<string, string>,
args?: Record<string, JsonValue>,
): Promise<McpResponse> {
try {
// Convert all arguments to strings for prompt arguments
const stringArgs: Record<string, string> = {};
if (args) {
for (const [key, value] of Object.entries(args)) {
if (typeof value === 'string') {
stringArgs[key] = value;
} else if (value === null || value === undefined) {
stringArgs[key] = String(value);
} else {
stringArgs[key] = JSON.stringify(value);
}
}
}
const response = await client.getPrompt({
name,
arguments: args || {},
arguments: stringArgs,
});
return response;