Skip to content

Conversation

michalismeng
Copy link

What's changed

Introduce the 'inspector' command, which starts the MCP inspector tool. Internally it launches the inspector with npx @modelcontextprotocol/inspector and passes any addition arguments the user gives.

Closes #51

(See the issue for some more details)


Screenshot from 2025-08-26 10-55-01

Notes

The issue mentions the following in the desired solution:

Warn the user that they need the relevant binaries on their machine when they enter a command in the UI

Currently, mcpd inspector prints to the terminal whatever the underlying npx process prints, so there will be dev-style details of the error:

New STDIO connection request
Query parameters: {"command":"uvx","args":"mcp-server-time@latest", ....

and in the UI we get a message from the inspector itself, for example:

error: Could not find the `uv` binary at either of: ...

Not sure if this is enough, glad to discuss if more is needed here.

Introduce the 'inspector' command, which starts the MCP inspector tool
via an npx process for interaction with 'try me out' style MCP servers.

Also, add a note to the docs.
@peteski22 peteski22 self-requested a review August 27, 2025 15:05
@peteski22 peteski22 self-assigned this Aug 27, 2025
@peteski22 peteski22 added enhancement New feature or request cli and removed needs-triage labels Sep 3, 2025
Copy link
Contributor

@peteski22 peteski22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @michalismeng for picking this up, looks good! I added some suggestions, it would be great if you could take a look please.

Just re-tag me afterwards and we can get this approved and merged. 🥳

}

// NewInspectorCmd creates a newly configured (Cobra) command.
func NewInspectorCmd(baseCmd *internalcmd.BaseCmd, opt ...cmdopts.CmdOption) (*cobra.Command, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func NewInspectorCmd(baseCmd *internalcmd.BaseCmd, opt ...cmdopts.CmdOption) (*cobra.Command, error) {
func NewInspectorCmd(baseCmd *internalcmd.BaseCmd, _ ...cmdopts.CmdOption) (*cobra.Command, error) {

package cmd

import (
"context"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"context"
"context"
"errors"

Required for errors.Is.

BaseCmd: baseCmd,
}

cobraCommand := &cobra.Command{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ I think perhaps we should mention in the docs (long) which version of @modelcontextprotocol/inspector we run... or pin it explicitly to latest.

npxCommand.Stdout = os.Stdout
npxCommand.Stderr = os.Stderr

fmt.Printf("Starting the MCP inspector: npx %s...\n", strings.Join(npxArgs, " "))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please could you replace calls to fmt.Printf with fmt.Fprintf that use cmd.OutOrStdOut?

Suggested change
fmt.Printf("Starting the MCP inspector: npx %s...\n", strings.Join(npxArgs, " "))
_, _ = fmt.Fprintf(
cmd.OutOrStdout(), "Starting the MCP inspector: npx %s...\n",
strings.Join(npxArgs, " "),
)

}

if err != nil {
return fmt.Errorf("failed to run the inspector: %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return fmt.Errorf("failed to run the inspector: %w", err)
return fmt.Errorf("error running the inspector: %w", err)

@@ -37,6 +37,15 @@ You can also restrict access to allow only specific tools:
mcpd add time --tool get_current_time
```

!!! note "Experiment with MCP servers"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
!!! note "Experiment with MCP servers"
!!! tip "Experiment with MCP servers"

// Create a new npx process with the user provided arguments
// Bind the process's stdout and stderr to our own for streaming output
npxArgs := append([]string{"@modelcontextprotocol/inspector"}, args...)
npxCommand := exec.CommandContext(ctx, "npx", npxArgs...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
npxCommand := exec.CommandContext(ctx, "npx", npxArgs...)
npxCommand := exec.CommandContext(ctx, string(runtime.NPX), npxArgs...)

Note: requires "github.com/mozilla-ai/mcpd/v2/internal/runtime" to be imported.

"github.com/spf13/cobra"

internalcmd "github.com/mozilla-ai/mcpd/v2/internal/cmd"
cmdopts "github.com/mozilla-ai/mcpd/v2/internal/cmd/options"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cmdopts "github.com/mozilla-ai/mcpd/v2/internal/cmd/options"
cmdopts "github.com/mozilla-ai/mcpd/v2/internal/cmd/options"
"github.com/mozilla-ai/mcpd/v2/internal/runtime"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support inspector style command
2 participants