Skip to content

Flag parsing inconsistency in shell command parameter handling #10

@ayakut16

Description

@ayakut16

-p option within the shell is not working as intended and it causes shell to crash.

Steps to Reproduce

  1. echo "Hello, World" > ~/file.txt
  2. mcp shell npx -y @modelcontextprotocol/server-filesystem ~
  3. mcp > call read_file --params {"path":"~/file.txt"}
    Hello, World
  4. Try to call read_file using the short parameter flag
    mcp > call read_file -p {"path":"~/file.txt"}
    panic: runtime error: index out of range [4] with length 3
    
    goroutine 1 [running]:
    main.main.newShellCmd.func8(0xc0000fe500?, {0xc0000ae500, 0x4, 0x5e6de76?})
            github.com/f/mcptools/cmd/mcptools/main.go:687 +0x176f
    github.com/spf13/cobra.(*Command).execute(0xc000103808, {0xc0000ae500, 0x4, 0x4})
            github.com/spf13/cobra@v1.9.1/command.go:1019 +0xa7b
    github.com/spf13/cobra.(*Command).ExecuteC(0xc000102008)
            github.com/spf13/cobra@v1.9.1/command.go:1148 +0x40c
    github.com/spf13/cobra.(*Command).Execute(...)
            github.com/spf13/cobra@v1.9.1/command.go:1071
    main.main()
            github.com/f/mcptools/cmd/mcptools/main.go:64 +0x307
    

I believe this is caused by incorrect variable usage in this for loop commandArgs[i] == flagParamsShort should be replaced with ii

for ii := 1; ii < len(commandArgs); ii++ {
	if commandArgs[ii] == flagParams || commandArgs[i] == flagParamsShort {
	.
        .
        .

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions