Parse tool args from CLI as JsonValue instead of just strings
This commit is contained in:
parent
cfc17e57d5
commit
99b962d445
1 changed files with 79 additions and 15 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue