Skip to content

Cannot pass array inputs into the CLI. (type: array results in string) #657

@jfeingold35

Description

@jfeingold35

Description
When using the CLI mode, and a tool input schema defines the type as "array", the CLI passes the value to the server as a single string instead of a JSON array.

To Reproduce
Steps to reproduce the behavior:

  1. Use the following tool description and execution:
server.setRequestHandler(ListToolsRequestSchema, () => {
    return {
        tools: [{
            name: "some-tool",
            description: "sample description",
            inputSchema: {
                type: "object",
                properties: {
                    prop: "array",
                    description: "This should be an array"
                }
            },
            required: ["prop"]
        }]
    }
})

server.setRequestHandler(CallToolRequestSchema, async (request) => {
    const name = request.params.name;
    
    switch (name) {
        case 'some-tool':
            return {
                content: [{
                    type: "text",
                    text: `The arguments provided were ${JSON.stringify(request.params.arguments)}`
                }]
            };
        default:
            throw new Error('unknown tool');
    }
});
  1. Use the inspector CLI mode to invoke the tool, e.g.,
noglob npx @modelcontextprotocol/inspector --cli node dist/index.js --method tools/call --tool-name some-tool --tool-arg prop=["abcd","defg"]

(noglob is necessary when using zsh, because brackets are how zsh detects a glob.)
3. Observe that the return value is:

{
  "content": [
    {
      "type": "text",
      "text": "The arguments provided were {\"prop\":\"[abcd,defg]\"}"
    }
  ]
}

Expected behavior
The value of prop should be ["abcd", "defg"], not "[abcd,defg]".

Logs
N/A

Additional context
N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions