| name | test-mcp-feature |
| description | Test an MCP server feature (tool, resource, or prompt) using the MCP Inspector CLI mode. Validates response shapes, data correctness, and error handling. |
| argument-hint | [feature-name] |
Test MCP Server Feature
Feature to test: $ARGUMENTS
Instructions
Use the MCP Inspector CLI mode to verify that an MCP server feature (tool, resource, or prompt) works correctly. This is a headless testing workflow — no browser UI needed.
The inspector spawns the server, calls the specified method, prints JSON to stdout, and exits. Use this to validate response shapes, data correctness, and error handling during development.
Step 1: Identify What to Test
Determine what type of MCP feature you're testing:
| Feature Type | List Method | Invoke Method |
|---|
| Tool | tools/list | tools/call |
| Resource | resources/list | resources/read |
| Prompt | prompts/list | prompts/get |
Step 2: Verify the Feature Is Registered
First confirm the feature shows up in the server's capability listing:
npm run inspect -- --cli --method tools/list
npm run inspect -- --cli --method resources/list
npm run inspect -- --cli --method prompts/list
Check that the feature name, description, and input schema match what you expect. If the feature doesn't appear, verify it's registered in src/lib/tool-registry.ts and handled in src/handlers/tool-handlers.ts.
Step 3: Call the Feature and Inspect Results
For tools:
npm run inspect -- --cli --method tools/call --tool-name list_datasets
npm run inspect -- --cli --method tools/call --tool-name search_attributes --tool-arg 'query=email'
npm run inspect -- --cli --method tools/call --tool-name dataset_sample --tool-arg 'dataset_id=123' --tool-arg 'size=5'
For resources:
npm run inspect -- --cli --method resources/read --resource-uri 'resource:///1'
For prompts:
npm run inspect -- --cli --method prompts/get --prompt-name execute-nql --prompt-arg 'query=SELECT * FROM dataset_123'
Step 4: Validate the Response
Inspect the JSON output and verify:
- Response structure — The response follows MCP protocol format (e.g.
{ content: [{ type: "text", text: "..." }] } for tools)
- Data correctness — The returned data matches what you'd expect from the underlying API
- Error handling — Test with invalid inputs to confirm errors are returned properly, not thrown
Parsing nested JSON
Tool responses often contain stringified JSON inside the text field. Use jq to extract and pretty-print it:
npm run inspect -- --cli --method tools/call --tool-name list_datasets 2>/dev/null | jq '.content[0].text | fromjson'
Step 5: Test Edge Cases
Run these scenarios to verify robustness:
npm run inspect -- --cli --method tools/call --tool-name search_attributes
npm run inspect -- --cli --method tools/call --tool-name dataset_statistics --tool-arg 'dataset_id='
npm run inspect -- --cli --method tools/call --tool-name search_attributes --tool-arg 'query=zzzznonexistent'
Example: Testing list_datasets
Here's a complete example of testing the list_datasets tool end-to-end:
npm run inspect -- --cli --method tools/list 2>/dev/null | jq '.tools[] | select(.name == "list_datasets")'
npm run inspect -- --cli --method tools/call --tool-name list_datasets
npm run inspect -- --cli --method tools/call --tool-name list_datasets 2>/dev/null | jq '.content[0].text | fromjson'
npm run inspect -- --cli --method tools/call --tool-name list_datasets 2>/dev/null | jq '.isError // false'
Adding Server Logging for Debugging
If you need to trace what's happening inside a handler, add logging messages that will appear in stderr:
console.error(`[DEBUG] Fetching datasets, got ${results.length} results`);
await this.server.sendLoggingMessage({
level: "info",
data: { step: "fetching datasets", count: results.length },
logger: "tool-handler",
});
When using CLI mode, console.error output appears in the terminal alongside the JSON output. Use 2>/dev/null to suppress it when piping through jq.
Quick Reference
npm run inspect -- --cli --method tools/list
npm run inspect -- --cli --method tools/call --tool-name <name>
npm run inspect -- --cli --method tools/call --tool-name <name> --tool-arg 'key=value'
npm run inspect -- --cli --method tools/call --tool-name <name> 2>/dev/null | jq '.content[0].text | fromjson'
npm run inspect -- --cli --method resources/list
npm run inspect -- --cli --method resources/read --resource-uri '<uri>'
npm run inspect -- --cli --method prompts/list
npm run inspect -- --cli --method prompts/get --prompt-name <name> --prompt-arg 'key=value'