Skip to content

fix: Pass args as string from client to server #652

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

Conversation

alex210501
Copy link

@alex210501 alex210501 commented Jul 27, 2025

The arguments are passed a string between the client and the server.

See #649

Motivation and Context

When the first argument started with -- (e.g. --my-arg), the following error was triggered:

~ » npx @modelcontextprotocol/inspector --config ~/mcp.json --server my-server
Starting MCP inspector...
node:internal/util/parse_args/parse_args:87
    throw new ERR_PARSE_ARGS_INVALID_OPTION_VALUE(errorMessage);
          ^

TypeError [ERR_PARSE_ARGS_INVALID_OPTION_VALUE]: Option '--args' argument is ambiguous.
Did you forget to specify the option argument for '--args'?
To specify an option argument starting with a dash use '--args=-XYZ'.
    at checkOptionLikeValue (node:internal/util/parse_args/parse_args:87:11)
    at node:internal/util/parse_args/parse_args:382:9
    at Array.forEach (<anonymous>)
    at parseArgs (node:internal/util/parse_args/parse_args:378:3)
    at file:///Users/alejandro.borbolla/.npm/_npx/5a9d879542beca3a/node_modules/@modelcontextprotocol/inspector/server/build/index.js:25:20
    at ModuleJob.run (node:internal/modules/esm/module_job:370:25)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:665:26)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:99:5) {
  code: 'ERR_PARSE_ARGS_INVALID_OPTION_VALUE'
}

The reason is that the client passes the following argument to the server:

node <server-path> --command <command> --args <args>

So if the first argument of the MCP server started with --, it gives:

node <server-path> --command mcp-server-command --args --first-arg

This is an invalid syntax. The solution is to send the args as a string, and surrounded by ". Giving the following format:

node <server-path> --command <command> --args "<args>"

The " are simply removed by the server.

How Has This Been Tested?

It has been tested by:

  • Sending parameters directly on the command line: npx @modelcontextprotocol/inspector -- myserver first-arg
  • Using the config file: npx @modelcontextprotocol/inspector --config mcp.json --server myserver

Breaking Changes

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

@alex210501 alex210501 force-pushed the alejandro.borbolla/pass-args-string-client-server branch from 4ed7205 to c70d198 Compare July 28, 2025 07:48
@alex210501 alex210501 marked this pull request as ready for review July 28, 2025 12:03
@richardkmichael
Copy link
Contributor

richardkmichael commented Jul 31, 2025

👋 Thank you for taking the time to investigate and send this PR!

The approach works, but I don't think it's ideal because:

  1. It is "working around" the parser. It's not the quotes per se which permit parsing -- it's that a non-dash character (in this case, a quote) has been added to the beginning of the argument value. An equivalent fix could prefix any non-dash character to the args value, and then remove it; no need even for a terminating character (the closing quote). Sorry if you got that, I just wanted to clarify this because there can be confusion around quotes, shells, ARGV, etc.

  2. The error message indicates the fix: use --args=-foo -- the "equal" notation. (This is what one would do, if invoking server directly on the command line.) Doing this "works with" the parser, which is also a simpler change (one file, at the caller; not two files).

I opened #664 for 2.

@alex210501
Copy link
Author

Thank you for the explanation @richardkmichael, really appreciate your time.

Should I just close this PR, or do you want me to implement the change to fix #664? Happy to help on this if I can :) (also sorry for the solution, I've struggled a bit to understand how the CLI, client and server were working together, not very use to work in TS)

@richardkmichael
Copy link
Contributor

richardkmichael commented Aug 1, 2025

Thank you for the explanation @richardkmichael, really appreciate your time.

Should I just close this PR, or do you want me to implement the change to fix #664?

I think you can close it. 664 is a change to use --args= notation.

Happy to help on this if I can :) (also sorry for the solution, I've struggled a bit to understand how the CLI, client and server were working together, not very use to work in TS)

Don't worry about the solution. I agree the flow of config through all the components is definitely not obvious. It's quite a tricky aspect to investigate. Nice job, and a good write-up too 👍

The Inspector moves quickly, and there are many small issues and improvements possible. So hopefully your learning can help contribution on another aspect of it.

@alex210501
Copy link
Author

So hopefully your learning can help contribution on another aspect of it.

Sure, I'd be very glad to contribute to this project (I'm using it quite extensively 🙂)

@alex210501 alex210501 closed this Aug 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants