Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions cmd/mcpproxy/access_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,14 @@ func fixCommand(f runtime.Fix, tool string) string {
case profile.FixApproveTool:
// A tool-approval target is "server:tool": approve only that tool (a bare
// `approve <server>` approves every pending tool of the server). A
// quarantined-server target is the server name alone, where approving
// the whole server is the intended action.
// quarantined-server target is the server name alone, where admitting
// the whole server is the intended action: that is `review approve`,
// because `upstream approve` only approves pending tools and leaves a
// quarantined server quarantined.
if server, tool, ok := strings.Cut(f.Target, ":"); ok && server != "" && tool != "" {
return "mcpproxy upstream approve " + server + " " + tool
}
return "mcpproxy upstream approve " + f.Target
return "mcpproxy review approve " + f.Target
case profile.FixChangeSetting:
if f.Target == "require_mcp_auth" {
return "set require_mcp_auth: true (config or Settings → Security)"
Expand Down
9 changes: 5 additions & 4 deletions cmd/mcpproxy/access_fix_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,17 @@ func TestAccessExplain_MoveClientFixNamesDestinationProfile(t *testing.T) {

// A tool_approval failure targets one tool, so its hint must approve only that
// tool: `upstream approve <server>` with no tool list approves every pending
// tool of the server. Only a quarantined SERVER (target = the server name) is
// approved as a whole.
// tool of the server. A quarantined SERVER (target = the server name) is
// admitted with `review approve <server>`: `upstream approve <server>` only
// approves pending tools and leaves a quarantined server quarantined.
func TestAccessExplain_ApproveToolFixNamesOnlyThatTool(t *testing.T) {
for _, tc := range []struct {
name, target, want string
}{
{"tool approval", "github:create_issue", "mcpproxy upstream approve github create_issue"},
{"server quarantine", "github", "mcpproxy upstream approve github"},
{"server quarantine", "github", "mcpproxy review approve github"},
{"cut at the first colon only", "github:ns:create_issue", "mcpproxy upstream approve github ns:create_issue"},
{"empty tool part is the server", "github:", "mcpproxy upstream approve github:"},
{"empty tool part is the server", "github:", "mcpproxy review approve github:"},
} {
t.Run(tc.name, func(t *testing.T) {
got := fixCommand(runtime.Fix{Action: profile.FixApproveTool, Target: tc.target}, "github:create_issue")
Expand Down
9 changes: 6 additions & 3 deletions cmd/mcpproxy/catalog_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ the curated official/popular sections with no query.
mcpproxy catalog search # browse official + popular
mcpproxy catalog show official/io.github.github/github-mcp-server
mcpproxy catalog add official/io.github.github/github-mcp-server
mcpproxy upstream approve <name> # approve once trusted
mcpproxy review show <name> # inspect the captured tools
mcpproxy review approve <name> --yes # approve once trusted

'catalog search'/'catalog add' supersede 'registry search'/'registry add'.
'registry list'/'add-source'/'edit'/'remove' still manage catalog SOURCES.`,
Expand Down Expand Up @@ -182,8 +183,10 @@ func newCatalogAddCmd() *cobra.Command {
Use: "add <source>/<id>",
Short: "Add a catalog entry as a (quarantined) upstream server",
Long: `Add a server found via 'catalog search'/'catalog show' as an upstream server.
The server is added quarantined by default; approve it once you trust it:
mcpproxy upstream approve <name>
The server is added quarantined by default; inspect it, then approve it once
you trust it:
mcpproxy review show <name>
mcpproxy review approve <name> --yes

This is the same keystone add operation as 'registry add <source> <id>' (Spec
070) — it just takes the combined "<source>/<id>" ref catalog results print.`,
Expand Down
12 changes: 12 additions & 0 deletions cmd/mcpproxy/registry_add_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ func TestRegistryAddMessage(t *testing.T) {
t.Fatalf("expected quarantined message to say %q, got %q", "quarantined for review", quarantined)
}

// The quarantined hint must name the step that actually admits the
// server. `mcpproxy upstream approve` only approves pending tools: on a
// quarantined server it prints "Approved 0 tools" and the server stays
// quarantined, which left first-run users stuck.
if !strings.Contains(quarantined, "mcpproxy review show github-server") ||
!strings.Contains(quarantined, "mcpproxy review approve github-server --yes") {
t.Fatalf("quarantined message must name review show / review approve --yes, got %q", quarantined)
}
if strings.Contains(quarantined, "upstream approve") {
t.Fatalf("quarantined message must not point at upstream approve, got %q", quarantined)
}

notQuarantined := registryAddMessage("github-server", false)
if !strings.Contains(notQuarantined, "Added github-server to MCPProxy") {
t.Fatalf("expected message to contain %q, got %q", "Added github-server to MCPProxy", notQuarantined)
Expand Down
10 changes: 6 additions & 4 deletions cmd/mcpproxy/registry_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Typical flow:
mcpproxy registry list # see available registries
mcpproxy registry search weather -r pulse # find a server
mcpproxy registry add pulse weather-mcp # add it (quarantined)
mcpproxy upstream approve weather-mcp # approve once you trust it
mcpproxy review approve weather-mcp --yes # approve once you trust it

Add your own registry source (any official modelcontextprotocol/registry v0.1 endpoint):
mcpproxy registry add-source https://registry.example.com # tagged "custom"
Expand Down Expand Up @@ -168,7 +168,7 @@ add through it follow the global quarantine default like any other server, so
with quarantine enabled (the default) they land quarantined for review:
mcpproxy registry search <query> -r <id>
mcpproxy registry add <id> <serverId>
mcpproxy upstream approve <name>`,
mcpproxy review approve <name> --yes`,
Args: cobra.ExactArgs(1),
RunE: func(_ *cobra.Command, args []string) error {
sourceURL := args[0]
Expand Down Expand Up @@ -424,7 +424,7 @@ func newRegistryAddCmd() *cobra.Command {
Long: `Add a server discovered in a registry as an upstream server.

The server is added quarantined by default; approve it once you trust it:
mcpproxy upstream approve <name>
mcpproxy review approve <name> --yes

The daemon re-derives the runnable config (command/args/url) from the registry
entry — you only supply optional overrides. If the server declares required
Expand Down Expand Up @@ -487,7 +487,9 @@ inputs, supply them with --env KEY=VALUE.`,
func registryAddMessage(name string, quarantined bool) string {
msg := fmt.Sprintf("✅ Added %s to MCPProxy", name)
if quarantined {
msg += fmt.Sprintf(" (quarantined for review — approve with: mcpproxy upstream approve %s)", name)
// Name the step that admits the server. `upstream approve` only
// approves pending tools and leaves a quarantined server quarantined.
msg += fmt.Sprintf(" (quarantined for review — inspect with: mcpproxy review show %s, then approve with: mcpproxy review approve %s --yes)", name, name)
}
return msg
}
Expand Down
75 changes: 71 additions & 4 deletions cmd/mcpproxy/upstream_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/spf13/cobra"
"go.uber.org/zap"

"github.com/smart-mcp-proxy/mcpproxy-go/internal/auth"
"github.com/smart-mcp-proxy/mcpproxy-go/internal/cli/output"
"github.com/smart-mcp-proxy/mcpproxy-go/internal/cliclient"
"github.com/smart-mcp-proxy/mcpproxy-go/internal/config"
Expand Down Expand Up @@ -429,10 +430,13 @@ func runUpstreamList(_ *cobra.Command, _ []string) error {
return outputError(err, output.ErrCodeOperationFailed)
}

// Check if daemon is running (socket first, then TCP fallback)
if client, ok := newDaemonClient(globalConfig, logger.Sugar()); ok {
// Check if daemon is running (socket first, then TCP fallback). The key
// the client will send decides whether the list is the whole install:
// none (the socket) or the admin key is, an agent token's is not.
if endpoint, apiKey, ok := daemonEndpoint(globalConfig); ok {
logger.Info("Detected running daemon, using client mode")
return runUpstreamListClientMode(ctx, client, logger)
client := cliclient.NewClientWithAPIKey(endpoint, apiKey, logger.Sugar())
return runUpstreamListClientMode(ctx, client, apiKey, logger)
}
if upstreamListProfile != "" {
return outputError(output.NewStructuredError(output.ErrCodeConnectionFailed,
Expand All @@ -459,7 +463,7 @@ func upstreamListQuery() url.Values {
return q
}

func runUpstreamListClientMode(ctx context.Context, client *cliclient.Client, _ *zap.Logger) error {
func runUpstreamListClientMode(ctx context.Context, client *cliclient.Client, apiKey string, _ *zap.Logger) error {
// Call GET /api/v1/servers
servers, err := client.GetServersWithQuery(ctx, upstreamListQuery())
if err != nil {
Expand All @@ -468,6 +472,10 @@ func runUpstreamListClientMode(ctx context.Context, client *cliclient.Client, _
WithRecoveryCommand("mcpproxy serve"), output.ErrCodeConnectionFailed)
}

upstreamListSource = listOriginDaemonAdmin
if strings.HasPrefix(apiKey, auth.TokenPrefixStr) {
upstreamListSource = listOriginDaemonScoped
}
return outputServers(servers)
}

Expand Down Expand Up @@ -557,10 +565,18 @@ func runUpstreamListFromConfig(globalConfig *config.Config) error {
}
}

upstreamListSource = listOriginConfig
return outputServers(servers)
}

func outputServers(servers []map[string]interface{}) error {
// An install with no servers at all gets a next step after the empty
// table, in table output only. A --profile list holds only that profile's
// servers, so an empty one says nothing about the install. (A --status
// filter is applied below, after this check.)
noServersConfigured := len(servers) == 0 && upstreamListProfile == "" &&
upstreamListSource != listOriginDaemonScoped

// FR-015: --status <value> is repeatable, and a comma-separated value is
// equivalent to repeating the flag; several values select the UNION of
// their statuses. Applies to every output format (table, json, yaml).
Expand Down Expand Up @@ -601,6 +617,9 @@ func outputServers(servers []map[string]interface{}) error {
return fmt.Errorf("failed to format table: %w", err)
}
fmt.Print(result)
if noServersConfigured {
fmt.Print(firstServerHint(exec.LookPath, upstreamListSource != listOriginConfig))
}
return nil
}

Expand Down Expand Up @@ -2787,3 +2806,51 @@ func viewOr(view map[string]interface{}, key, fallback string) string {
}
return fallback
}

// firstServerHint is the empty-state next step for `mcpproxy upstream list`
// on an install with no servers (Spec 126 US2, CLI surface). It suggests one
// credential-free reference server through the catalog door, in the Spec 126
// FR-002 starter order (time, then sequentialthinking), choosing the first
// whose launcher this machine has. The catalog door applies quarantine, trust
// mode and the admission scan exactly as for any catalog add; the hint itself
// adds, runs and approves nothing. lookPath is exec.LookPath in production.
func firstServerHint(lookPath func(string) (string, error), daemonRunning bool) string {
var b strings.Builder
b.WriteString("\nNo upstream servers yet. Next steps:\n")
if !daemonRunning {
b.WriteString(" mcpproxy serve # start the core first (catalog add and review need it)\n")
}
has := func(name string) bool { _, err := lookPath(name); return err == nil }
switch {
case has("uvx"):
b.WriteString(" mcpproxy catalog add reference/time # reference server, no credentials (runs: uvx mcp-server-time)\n")
case has("npx"):
b.WriteString(" mcpproxy catalog add reference/sequentialthinking # reference server, no credentials (runs: npx -y @modelcontextprotocol/server-sequential-thinking)\n")
default:
b.WriteString(" (local reference servers need uv (uvx) or Node.js (npx); neither is on PATH)\n")
}
b.WriteString(" mcpproxy upstream add <name> <url> # any remote MCP server\n")
b.WriteString(" mcpproxy catalog search <query> # browse the catalog\n")
b.WriteString("New servers are quarantined and scanned; inspect one with 'mcpproxy review show <name>' and admit it with 'mcpproxy review approve <name> --yes'.\n")
return b.String()
}

// upstreamListOrigin says where `upstream list` got its servers, which
// decides whether an empty list means an empty install (first-server hint).
type upstreamListOrigin int

const (
// listOriginDaemonAdmin: the daemon, as an administrator (socket or the
// instance API key). An empty list is an empty install.
listOriginDaemonAdmin upstreamListOrigin = iota
// listOriginConfig: no daemon; the config file. An empty list is an empty
// install, but the core must be started before catalog add / review.
listOriginConfig
// listOriginDaemonScoped: the daemon, as an agent token. The list holds
// only the servers the token may see, so an empty one says nothing about
// the install, and adding servers is not the token's operation.
listOriginDaemonScoped
)

// upstreamListSource is set by the two list paths before outputServers.
var upstreamListSource = listOriginDaemonAdmin
Loading
Loading