-
Notifications
You must be signed in to change notification settings - Fork 3
Introduce the inspector
command
#157
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
base: main
Are you sure you want to change the base?
Introduce the inspector
command
#157
Conversation
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.
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 @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) { |
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.
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" |
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.
"context" | |
"context" | |
"errors" |
Required for errors.Is
.
BaseCmd: baseCmd, | ||
} | ||
|
||
cobraCommand := &cobra.Command{ |
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.
❓ 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, " ")) |
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.
Please could you replace calls to fmt.Printf
with fmt.Fprintf
that use cmd.OutOrStdOut
?
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) |
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.
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" |
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.
!!! 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...) |
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.
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" |
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.
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" |
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)
Notes
The issue mentions the following in the desired solution:
Currently,
mcpd inspector
prints to the terminal whatever the underlyingnpx
process prints, so there will be dev-style details of the error:and in the UI we get a message from the inspector itself, for example:
Not sure if this is enough, glad to discuss if more is needed here.