Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

mcp: status compares against the URL connect wrote

Claude11abd734a94e
diff --git a/cli/beacon/cmd/mcp_connect.go b/cli/beacon/cmd/mcp_connect.go
index 09dea334..49ee3ec5 100644
--- a/cli/beacon/cmd/mcp_connect.go
+++ b/cli/beacon/cmd/mcp_connect.go
@@ -511,6 +511,13 @@ func runMCPStatus(cmd *cobra.Command, args []string) error {
report := mcpStatusReport{ServerName: mcpconnect.ServerName}
if url, derived, err := mcpconnect.ResolveURL(mcpConnectOpts.url, mcpIngestURL()); err == nil {
report.URL = url
+ // Without --check nothing is fetched, so a derived URL cannot be turned into the
+ // canonical one; compare against the URL connect checked and wrote instead.
+ if derived && !mcpConnectOpts.check {
+ if recorded := mcpconnect.RecordedURL(home); recorded != "" {
+ report.URL = recorded
+ }
+ }
if mcpConnectOpts.check {
if canonical, err := mcpconnect.CheckURL(cmd.Context(), mcpHTTPClient, url, derived); err != nil {
report.Check = "failed: " + err.Error()
@@ -518,6 +525,8 @@ func runMCPStatus(cmd *cobra.Command, args []string) error {
report.URL, report.Check = canonical, "ok"
}
}
+ } else if recorded := mcpconnect.RecordedURL(home); recorded != "" && !mcpConnectOpts.check {
+ report.URL = recorded
} else if mcpConnectOpts.check {
report.Check = "failed: " + err.Error()
}
diff --git a/cli/beacon/cmd/mcp_connect_test.go b/cli/beacon/cmd/mcp_connect_test.go
index f9b4c021..d1f45f5a 100644
--- a/cli/beacon/cmd/mcp_connect_test.go
+++ b/cli/beacon/cmd/mcp_connect_test.go
@@ -134,7 +134,9 @@ func newMCPFixture(t *testing.T, detected ...string) *mcpFixture {
// Anything that bypasses mcpHTTPClient is recorded and refused.
http.DefaultTransport = recordingTransport{log: fx.strays}
mcpLookPath = func(string) (string, error) { return "", errors.New("not on PATH") }
- mcpRunCLI = func(context.Context, string, ...string) ([]byte, error) { return nil, errors.New("no CLI in unit tests") }
+ mcpRunCLI = func(context.Context, string, ...string) ([]byte, error) {
+ return nil, errors.New("no CLI in unit tests")
+ }
mcpIngestURL = func() string { return "" }
return fx
}
@@ -519,3 +521,41 @@ func TestMCPServerNamesDoNotCollide(t *testing.T) {
t.Fatal("the Beacon Managed server must not share the local stdio server's name")
}
}
+
+// Regression: the backend names a canonical MCP URL different from the ingest URL plus /mcp, and
+// connect writes the canonical one. status without --check makes no request, so it must compare
+// against the URL connect wrote, not the derived one.
+func TestMCPStatusWithoutCheckUsesTheURLConnectWrote(t *testing.T) {
+ fx := newMCPFixture(t, "cursor")
+ ingest := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ _ = json.NewEncoder(w).Encode(map[string]any{"resource": fx.url})
+ }))
+ t.Cleanup(ingest.Close)
+ mcpIngestURL = func() string { return ingest.URL }
+ if _, _, err := runMCP(t, "connect", "--yes"); err != nil {
+ t.Fatal(err)
+ }
+ afterConnect := len(fx.requests.all())
+ stdout, _, err := runMCP(t, "status")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if !strings.Contains(stdout, "Beacon Managed MCP URL: "+fx.url) || strings.Contains(stdout, "other URL") {
+ t.Fatalf("status compared against the derived URL:\n%s", stdout)
+ }
+ if n := len(fx.requests.all()); n != afterConnect {
+ t.Fatalf("status made a request without --check (%d after connect, %d after status)", afterConnect, n)
+ }
+}
+
+func TestMCPStatusFallsBackToTheRecordedURLWithoutAnEnrollment(t *testing.T) {
+ fx := newMCPFixture(t, "cursor")
+ if _, _, err := runMCP(t, "connect", "--url", fx.url, "--yes"); err != nil {
+ t.Fatal(err)
+ }
+ stdout, _, err := runMCP(t, "status")
+ if err != nil || !strings.Contains(stdout, "Beacon Managed MCP URL: "+fx.url) || strings.Contains(stdout, "other URL") {
+ t.Fatalf("err = %v\n%s", err, stdout)
+ }
+}
diff --git a/cli/beacon/internal/mcpconnect/manifest.go b/cli/beacon/internal/mcpconnect/manifest.go
index f59e84c9..1d00a9f4 100644
--- a/cli/beacon/internal/mcpconnect/manifest.go
+++ b/cli/beacon/internal/mcpconnect/manifest.go
@@ -75,6 +75,23 @@ func loadManifest(home string) (*manifest, error) {
return &m, nil
}
+// RecordedURL is the URL `connect` last wrote, or "" when it has written nothing. It is what an
+// offline status compares entries against: a URL derived from the ingest URL may not be the
+// canonical one connect checked and wrote.
+func RecordedURL(home string) string {
+ m, err := loadManifest(home)
+ if err != nil {
+ return ""
+ }
+ var latest Record
+ for _, r := range m.Records {
+ if latest.URL == "" || r.WrittenAt.After(latest.WrittenAt) {
+ latest = r
+ }
+ }
+ return latest.URL
+}
+
func (m *manifest) find(harness, path string) (Record, bool) {
for _, r := range m.Records {
if r.Harness == harness && r.Path == path {