Skip to content

Commit ef11c36

Browse files
authored
Merge pull request #647 from olaservo/parse-tool-arg
Parse tool args from CLI as JsonValue instead of just strings
2 parents f94f2d8 + 9da9f01 commit ef11c36

File tree

8 files changed

+703
-78
lines changed

8 files changed

+703
-78
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ client/tsconfig.app.tsbuildinfo
99
client/tsconfig.node.tsbuildinfo
1010
cli/build
1111
test-output
12+
tool-test-output
1213
# symlinked by `npm run link:sdk`:
1314
sdk
1415
client/playwright-report/

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,9 @@ npx @modelcontextprotocol/inspector --cli node build/index.js --method tools/lis
395395
# Call a specific tool
396396
npx @modelcontextprotocol/inspector --cli node build/index.js --method tools/call --tool-name mytool --tool-arg key=value --tool-arg another=value2
397397

398+
# Call a tool with JSON arguments
399+
npx @modelcontextprotocol/inspector --cli node build/index.js --method tools/call --tool-name mytool --tool-arg 'options={"format": "json", "max_tokens": 100}'
400+
398401
# List available resources
399402
npx @modelcontextprotocol/inspector --cli node build/index.js --method resources/list
400403

cli/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
"scripts": {
1818
"build": "tsc",
1919
"postbuild": "node scripts/make-executable.js",
20-
"test": "node scripts/cli-tests.js"
20+
"test": "node scripts/cli-tests.js && node scripts/cli-tool-tests.js",
21+
"test:cli": "node scripts/cli-tests.js",
22+
"test:cli-tools": "node scripts/cli-tool-tests.js"
2123
},
2224
"devDependencies": {},
2325
"dependencies": {

cli/scripts/cli-tests.js

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ console.log(`${colors.BLUE}- Environment variables (-e)${colors.NC}`);
3737
console.log(`${colors.BLUE}- Config file (--config)${colors.NC}`);
3838
console.log(`${colors.BLUE}- Server selection (--server)${colors.NC}`);
3939
console.log(`${colors.BLUE}- Method selection (--method)${colors.NC}`);
40-
console.log(
41-
`${colors.BLUE}- Tool-related options (--tool-name, --tool-arg)${colors.NC}`,
42-
);
4340
console.log(`${colors.BLUE}- Resource-related options (--uri)${colors.NC}`);
4441
console.log(
4542
`${colors.BLUE}- Prompt-related options (--prompt-name, --prompt-args)${colors.NC}`,
@@ -533,65 +530,6 @@ async function runTests() {
533530
"tools/list",
534531
);
535532

536-
console.log(
537-
`\n${colors.YELLOW}=== Running Tool-Related Tests ===${colors.NC}`,
538-
);
539-
540-
// Test 12: CLI mode with tool call
541-
await runBasicTest(
542-
"tool_call",
543-
TEST_CMD,
544-
...TEST_ARGS,
545-
"--cli",
546-
"--method",
547-
"tools/call",
548-
"--tool-name",
549-
"echo",
550-
"--tool-arg",
551-
"message=Hello",
552-
);
553-
554-
// Test 13: CLI mode with tool call but missing tool name (should fail)
555-
await runErrorTest(
556-
"missing_tool_name",
557-
TEST_CMD,
558-
...TEST_ARGS,
559-
"--cli",
560-
"--method",
561-
"tools/call",
562-
"--tool-arg",
563-
"message=Hello",
564-
);
565-
566-
// Test 14: CLI mode with tool call but invalid tool args format (should fail)
567-
await runErrorTest(
568-
"invalid_tool_args",
569-
TEST_CMD,
570-
...TEST_ARGS,
571-
"--cli",
572-
"--method",
573-
"tools/call",
574-
"--tool-name",
575-
"echo",
576-
"--tool-arg",
577-
"invalid_format",
578-
);
579-
580-
// Test 15: CLI mode with multiple tool args
581-
await runBasicTest(
582-
"multiple_tool_args",
583-
TEST_CMD,
584-
...TEST_ARGS,
585-
"--cli",
586-
"--method",
587-
"tools/call",
588-
"--tool-name",
589-
"add",
590-
"--tool-arg",
591-
"a=1",
592-
"b=2",
593-
);
594-
595533
console.log(
596534
`\n${colors.YELLOW}=== Running Resource-Related Tests ===${colors.NC}`,
597535
);

0 commit comments

Comments
 (0)