-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[cli] Don't force specific endpoints for remote servers #595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[cli] Don't force specific endpoints for remote servers #595
Conversation
At the moment, the CLI tool expects that remote MCP servers, either using SSE or streamable HTTP transport, have certain endpoints or fragments -- `/sse` and `/mcp`, respectively. This is not part of the MCP spec, nor should it be expected. I also added a check to make sure a URL is provided if STDIO isn't picked, erroring out if not.
|
@cliffhall you had previously reviewed my p/r #578. i think this p/r is cleaner and it also addresses your request to remove the warn-level log statements. this p/r LGTM. i checked out this p/r locally and confirmed it was working for my own HTTP Streamable endpoint. |
olaservo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me - although its technically breaking it actually matches the Readme from what I can tell, and this change should help unblock more usage.
I did have one question about testing: were you able to run the updated cli-tests.js? I also wasn't totally clear on this comment from your PR description:
Currently, I can't use the inspector CLI as a little integration test in development.
Could you clarify what you mean?
CLI tests passing$ npm run test
> @modelcontextprotocol/[email protected] test
> node scripts/cli-tests.js
=== MCP Inspector CLI Test Script ===
This script tests the MCP Inspector CLI's ability to handle various command line options:
- Basic CLI mode
- Environment variables (-e)
- Config file (--config)
- Server selection (--server)
- Method selection (--method)
- Tool-related options (--tool-name, --tool-arg)
- Resource-related options (--uri)
- Prompt-related options (--prompt-name, --prompt-args)
- Logging options (--log-level)
- Transport types (--transport http/sse/stdio)
- Transport inference from URL suffixes (/mcp, /sse)
Using existing sample config file: /Users/leblancfg/src/github.com/leblancfg/inspector//sample-config.json
{
"mcpServers": {
"everything": {
"command": "npx",
"args": ["@modelcontextprotocol/server-everything"],
"env": {
"HELLO": "Hello MCP!"
}
},
"myserver": {
"command": "node",
"args": ["build/index.js", "arg1", "arg2"],
"env": {
"KEY": "value",
"KEY2": "value2"
}
}
}
}
=== Running Basic CLI Mode Tests ===
Testing: basic_cli_mode
Command: node /Users/leblancfg/src/github.com/leblancfg/inspector/cli/build/cli.js npx @modelcontextprotocol/server-everything --cli --method tools/list
✓ Test passed: basic_cli_mode
First few lines of output:
{
"tools": [
{
"name": "echo",
"description": "Echoes back the input",
Testing error case: nonexistent_method
Command: node /Users/leblancfg/src/github.com/leblancfg/inspector/cli/build/cli.js npx @modelcontextprotocol/server-everything --cli --method nonexistent/method
✓ Error test passed: nonexistent_method
Error output (expected):
Unsupported method: nonexistent/method. Supported methods include: tools/list, tools/call, resources/list, resources/read, resources/templates/list, prompts/list, prompts/get, logging/setLevel
Unsupported method: nonexistent/method. Supported methods include: tools/list, tools/call, resources/list, resources/read, resources/templates/list, prompts/list, prompts/get, logging/setLevel
Failed with exit code: 1
Testing error case: missing_method
Command: node /Users/leblancfg/src/github.com/leblancfg/inspector/cli/build/cli.js npx @modelcontextprotocol/server-everything --cli
✓ Error test passed: missing_method
Error output (expected):
Method is required. Use --method to specify the method to invoke.
Method is required. Use --method to specify the method to invoke.
Failed with exit code: 1
=== Running Environment Variable Tests ===
Testing: env_variables
Command: node /Users/leblancfg/src/github.com/leblancfg/inspector/cli/build/cli.js npx @modelcontextprotocol/server-everything -e KEY1=value1 -e KEY2=value2 --cli --method tools/list
✓ Test passed: env_variables
First few lines of output:
{
"tools": [
{
"name": "echo",
"description": "Echoes back the input",
Testing error case: invalid_env_format
Command: node /Users/leblancfg/src/github.com/leblancfg/inspector/cli/build/cli.js npx @modelcontextprotocol/server-everything -e INVALID_FORMAT --cli --method tools/list
✓ Error test passed: invalid_env_format
Error output (expected):
Invalid parameter format: INVALID_FORMAT. Use key=value format.
Testing: env_variable_with_equals
Command: node /Users/leblancfg/src/github.com/leblancfg/inspector/cli/build/cli.js npx @modelcontextprotocol/server-everything -e API_KEY=abc123=xyz789== --cli --method tools/list
✓ Test passed: env_variable_with_equals
First few lines of output:
{
"tools": [
{
"name": "echo",
"description": "Echoes back the input",
Testing: env_variable_with_base64
Command: node /Users/leblancfg/src/github.com/leblancfg/inspector/cli/build/cli.js npx @modelcontextprotocol/server-everything -e JWT_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0= --cli --method tools/list
✓ Test passed: env_variable_with_base64
First few lines of output:
{
"tools": [
{
"name": "echo",
"description": "Echoes back the input",
=== Running Config File Tests ===
Testing: config_file
Command: node /Users/leblancfg/src/github.com/leblancfg/inspector/cli/build/cli.js --config /Users/leblancfg/src/github.com/leblancfg/inspector/sample-config.json --server everything --cli --method tools/list
✓ Test passed: config_file
First few lines of output:
{
"tools": [
{
"name": "echo",
"description": "Echoes back the input",
Testing error case: config_without_server
Command: node /Users/leblancfg/src/github.com/leblancfg/inspector/cli/build/cli.js --config /Users/leblancfg/src/github.com/leblancfg/inspector/sample-config.json --cli --method tools/list
✓ Error test passed: config_without_server
Error output (expected):
Both --config and --server must be provided together. If you specify one, you must specify the other.
Testing error case: server_without_config
Command: node /Users/leblancfg/src/github.com/leblancfg/inspector/cli/build/cli.js --server everything --cli --method tools/list
✓ Error test passed: server_without_config
Error output (expected):
Both --config and --server must be provided together. If you specify one, you must specify the other.
Testing error case: nonexistent_config
Command: node /Users/leblancfg/src/github.com/leblancfg/inspector/cli/build/cli.js --config ./nonexistent-config.json --server everything --cli --method tools/list
✓ Error test passed: nonexistent_config
Error output (expected):
Config file not found: /Users/leblancfg/src/github.com/leblancfg/inspector/cli/nonexistent-config.json
Testing error case: invalid_config
Command: node /Users/leblancfg/src/github.com/leblancfg/inspector/cli/build/cli.js --config /var/folders/15/g6qxcjjj4hq091wfwtrlzf1w0000gn/T/mcp-inspector-tests/invalid-config.json --server everything --cli --method tools/list
✓ Error test passed: invalid_config
Error output (expected):
Invalid JSON in config file: Expected property name or '}' in JSON at position 36 (line 3 column 17)
Testing error case: nonexistent_server
Command: node /Users/leblancfg/src/github.com/leblancfg/inspector/cli/build/cli.js --config /Users/leblancfg/src/github.com/leblancfg/inspector/sample-config.json --server nonexistent --cli --method tools/list
✓ Error test passed: nonexistent_server
Error output (expected):
Server 'nonexistent' not found in config file. Available servers: everything, myserver
=== Running Tool-Related Tests ===
Testing: tool_call
Command: node /Users/leblancfg/src/github.com/leblancfg/inspector/cli/build/cli.js npx @modelcontextprotocol/server-everything --cli --method tools/call --tool-name echo --tool-arg message=Hello
✓ Test passed: tool_call
First few lines of output:
{
"content": [
{
"type": "text",
"text": "Echo: Hello"
Testing error case: missing_tool_name
Command: node /Users/leblancfg/src/github.com/leblancfg/inspector/cli/build/cli.js npx @modelcontextprotocol/server-everything --cli --method tools/call --tool-arg message=Hello
✓ Error test passed: missing_tool_name
Error output (expected):
Tool name is required for tools/call method. Use --tool-name to specify the tool name.
Tool name is required for tools/call method. Use --tool-name to specify the tool name.
Failed with exit code: 1
Testing error case: invalid_tool_args
Command: node /Users/leblancfg/src/github.com/leblancfg/inspector/cli/build/cli.js npx @modelcontextprotocol/server-everything --cli --method tools/call --tool-name echo --tool-arg invalid_format
✓ Error test passed: invalid_tool_args
Error output (expected):
Invalid parameter format: invalid_format. Use key=value format.
Invalid parameter format: invalid_format. Use key=value format.
Failed with exit code: 1
Testing: multiple_tool_args
Command: node /Users/leblancfg/src/github.com/leblancfg/inspector/cli/build/cli.js npx @modelcontextprotocol/server-everything --cli --method tools/call --tool-name add --tool-arg a=1 b=2
✓ Test passed: multiple_tool_args
First few lines of output:
{
"content": [
{
"type": "text",
"text": "The sum of 1 and 2 is 3."
=== Running Resource-Related Tests ===
Testing: resource_read
Command: node /Users/leblancfg/src/github.com/leblancfg/inspector/cli/build/cli.js npx @modelcontextprotocol/server-everything --cli --method resources/read --uri test://static/resource/1
✓ Test passed: resource_read
First few lines of output:
{
"contents": [
{
"uri": "test://static/resource/1",
"mimeType": "text/plain",
Testing error case: missing_uri
Command: node /Users/leblancfg/src/github.com/leblancfg/inspector/cli/build/cli.js npx @modelcontextprotocol/server-everything --cli --method resources/read
✓ Error test passed: missing_uri
Error output (expected):
URI is required for resources/read method. Use --uri to specify the resource URI.
URI is required for resources/read method. Use --uri to specify the resource URI.
Failed with exit code: 1
=== Running Prompt-Related Tests ===
Testing: prompt_get
Command: node /Users/leblancfg/src/github.com/leblancfg/inspector/cli/build/cli.js npx @modelcontextprotocol/server-everything --cli --method prompts/get --prompt-name simple_prompt
✓ Test passed: prompt_get
First few lines of output:
{
"messages": [
{
"role": "user",
"content": {
Testing: prompt_get_with_args
Command: node /Users/leblancfg/src/github.com/leblancfg/inspector/cli/build/cli.js npx @modelcontextprotocol/server-everything --cli --method prompts/get --prompt-name complex_prompt --prompt-args temperature=0.7 style=concise
✓ Test passed: prompt_get_with_args
First few lines of output:
{
"messages": [
{
"role": "user",
"content": {
Testing error case: missing_prompt_name
Command: node /Users/leblancfg/src/github.com/leblancfg/inspector/cli/build/cli.js npx @modelcontextprotocol/server-everything --cli --method prompts/get
✓ Error test passed: missing_prompt_name
Error output (expected):
Prompt name is required for prompts/get method. Use --prompt-name to specify the prompt name.
Prompt name is required for prompts/get method. Use --prompt-name to specify the prompt name.
Failed with exit code: 1
=== Running Logging Tests ===
Testing: log_level
Command: node /Users/leblancfg/src/github.com/leblancfg/inspector/cli/build/cli.js npx @modelcontextprotocol/server-everything --cli --method logging/setLevel --log-level debug
✓ Test passed: log_level
First few lines of output:
{}
Testing error case: invalid_log_level
Command: node /Users/leblancfg/src/github.com/leblancfg/inspector/cli/build/cli.js npx @modelcontextprotocol/server-everything --cli --method logging/setLevel --log-level invalid
✓ Error test passed: invalid_log_level
Error output (expected):
Invalid log level: invalid. Valid levels are: trace, debug, info, warn, error
Invalid log level: invalid. Valid levels are: trace, debug, info, warn, error
Failed with exit code: 1
=== Running Combined Option Tests ===
Testing combined options with environment variables and config file.
Testing: combined_options
Command: node /Users/leblancfg/src/github.com/leblancfg/inspector/cli/build/cli.js --config /Users/leblancfg/src/github.com/leblancfg/inspector/sample-config.json --server everything -e CLI_ENV_VAR=cli_value --cli --method tools/list
✓ Test passed: combined_options
First few lines of output:
{
"tools": [
{
"name": "echo",
"description": "Echoes back the input",
Testing: all_options
Command: node /Users/leblancfg/src/github.com/leblancfg/inspector/cli/build/cli.js --config /Users/leblancfg/src/github.com/leblancfg/inspector/sample-config.json --server everything -e CLI_ENV_VAR=cli_value --cli --method tools/call --tool-name echo --tool-arg message=Hello --log-level debug
✓ Test passed: all_options
First few lines of output:
{
"content": [
{
"type": "text",
"text": "Echo: Hello"
=== Running HTTP Transport Tests ===
Starting server-everything in streamableHttp mode.
Testing: http_transport_inferred
Command: node /Users/leblancfg/src/github.com/leblancfg/inspector/cli/build/cli.js http://127.0.0.1:3001/mcp --cli --method tools/list
✓ Test passed: http_transport_inferred
First few lines of output:
{
"tools": [
{
"name": "echo",
"description": "Echoes back the input",
Testing: http_transport_with_explicit_flag
Command: node /Users/leblancfg/src/github.com/leblancfg/inspector/cli/build/cli.js http://127.0.0.1:3001/mcp --transport http --cli --method tools/list
✓ Test passed: http_transport_with_explicit_flag
First few lines of output:
{
"tools": [
{
"name": "echo",
"description": "Echoes back the input",
Testing: http_transport_with_explicit_flag_and_suffix
Command: node /Users/leblancfg/src/github.com/leblancfg/inspector/cli/build/cli.js http://127.0.0.1:3001/mcp --transport http --cli --method tools/list
✓ Test passed: http_transport_with_explicit_flag_and_suffix
First few lines of output:
{
"tools": [
{
"name": "echo",
"description": "Echoes back the input",
Testing error case: sse_transport_given_to_http_server
Command: node /Users/leblancfg/src/github.com/leblancfg/inspector/cli/build/cli.js http://127.0.0.1:3001 --transport sse --cli --method tools/list
✓ Error test passed: sse_transport_given_to_http_server
Error output (expected):
Failed to connect to MCP server: SSE error: Non-200 status code (404)
Failed to connect to MCP server: SSE error: Non-200 status code (404)
Failed with exit code: 1
Testing error case: http_transport_without_url
Command: node /Users/leblancfg/src/github.com/leblancfg/inspector/cli/build/cli.js --transport http --cli --method tools/list
✓ Error test passed: http_transport_without_url
Error output (expected):
error: missing required argument 'target'
error: missing required argument 'target'
Failed with exit code: 1
Testing error case: sse_transport_without_url
Command: node /Users/leblancfg/src/github.com/leblancfg/inspector/cli/build/cli.js --transport sse --cli --method tools/list
✓ Error test passed: sse_transport_without_url
Error output (expected):
error: missing required argument 'target'
error: missing required argument 'target'
Failed with exit code: 1
HTTP server killed, waiting for port to be released...
=== Test Summary ===
Passed: 32
Failed: 0
Skipped: 0
Total: 32
Detailed logs saved to: /Users/leblancfg/src/github.com/leblancfg/inspector/cli/scripts/test-output
All tests completed! |
I'd like to use the inspector's CLI in my MCP server's CI pipeline for lightweight testing. However, my server doesn't use the |
olaservo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for confirming the tests, looks good to me. 👍
Motivation and Context
At the moment, the CLI tool expects that remote MCP servers, either using SSE or streamable HTTP transport, have certain endpoints or fragments --
/sseand/mcp, respectively. These specific routes are not part of the MCP spec, nor should it be expected.I also added a check to make sure a URL is provided if STDIO isn't picked, erroring out if not.
Fixes: #594
See: #578. Recreating it here with a pared-down version that addresses the review comments. I needed this locally now and am sharing it. Please merge whichever.
How Has This Been Tested?
I have a local MCP server on a root endpoint (
/) served by a little Express server (not/mcp). Currently, I can't use the inspector CLI as a little integration test in development. Only now can I do:$ ./build/cli.js --cli --transport http http://localhost:37242 --method tools/listBreaking Changes
Yes. It used to implicitly append
/sseand/mcproutes to remote transport URLs that didn't have them, now it doesn't.People might have workflows set up that depend on these paths not being explicitly configured.
Types of changes
Checklist
Additional context