diff --git a/API.md b/API.md index 2aba0f3..9016ccb 100644 --- a/API.md +++ b/API.md @@ -111,7 +111,7 @@ Bearer / custom-header auth. Stored in `McpConnection` (migration 018). | Method | Path | Returns | |---|---|---| -| GET | `/api/mcp/connections` | `{connections:[…],suggestions:[…]}` — secret masked `••••••••` when set, never plaintext; suggestions are the shipped catalog of well-known hosted MCP servers (GitHub, HubSpot, Make) with `available:false` marking auth the client cannot satisfy (HubSpot requires OAuth 2.1 + PKCE) | +| GET | `/api/mcp/connections` | `{connections:[…],suggestions:[…]}` — secret masked `••••••••` when set, never plaintext; suggestions are the shipped catalog of well-known hosted MCP servers (GitHub, HubSpot, Make) with `available:false` marking auth the client cannot satisfy (HubSpot requires OAuth 2.1 + PKCE), plus a `core-hub` entry (SSE + bearer) when the deployment sets `MCP_HUB_URL` — deployment DATA like `NEXTCLOUD_URL`, never a TIER fork | | POST | `/api/mcp/connections` | 201 masked projection; body `{name,url,transport,authKind,headerName?,secret?}`; secret required for bearer/header; cap 10 per user | | PATCH | `/api/mcp/connections/{id}` | masked projection; **requires `version`** (409 on stale); a mask or omitted `secret` keeps the stored value; switching `authKind` to `none` clears it | | DELETE | `/api/mcp/connections/{id}` | `{ok:true}`; 404 for another user's row | diff --git a/deploy/federated/lib-superbrain.sh b/deploy/federated/lib-superbrain.sh index 11c7745..04c0077 100644 --- a/deploy/federated/lib-superbrain.sh +++ b/deploy/federated/lib-superbrain.sh @@ -244,6 +244,12 @@ NETGUARD_TRUSTED_HOSTS=mail.$DOMAIN # connection still needs the person's own username and app password; see the # three DAV sections in API.md). NEXTCLOUD_URL=https://nextcloud.$DOMAIN + +# --- MCP hub (Settings → MCP) ---------------------------------------------- +# The core's federated tool hub (mcpserver-hub) as a one-connection MCP +# suggestion; each person connects with their OWN mhub_ bearer token +# (mcphub-token CLI; DESIGN_MCP_HUB_AUTH.md). Purely a hint, like NEXTCLOUD_URL. +MCP_HUB_URL=https://mcphub.$DOMAIN EOF chmod 600 /federated/apps/superbrain/.env diff --git a/internal/config/config.go b/internal/config/config.go index c2b398b..10d57e9 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -222,6 +222,23 @@ func NextcloudSuggestion() string { return raw } +// McpHubSuggestion is the same deployment-data pattern for the core's MCP +// hub (DESIGN_MCP_HUB_AUTH.md): when MCP_HUB_URL points at the federated +// mcpserver-hub origin, Settings → MCP offers it as a one-connection +// suggestion (SSE + the user's own mhub_ bearer token). Unset or invalid → +// no suggestion; never a TIER fork. +func McpHubSuggestion() string { + raw := strings.TrimRight(strings.TrimSpace(os.Getenv("MCP_HUB_URL")), "/") + if raw == "" { + return "" + } + u, err := url.Parse(raw) + if err != nil || (u.Scheme != "http" && u.Scheme != "https") || u.Host == "" { + return "" + } + return raw +} + // Validate fails fast on configuration the app cannot use, instead of // discovering it on the first request (review M-12). func (c *Config) Validate() error { diff --git a/internal/handlers/mcp.go b/internal/handlers/mcp.go index d5a0e61..858f4ad 100644 --- a/internal/handlers/mcp.go +++ b/internal/handlers/mcp.go @@ -99,6 +99,8 @@ var mcpSuggestions = []object{ // HandleMcpConnectionsList returns the caller's connections, masked, plus // the suggestion catalog (always an array so clients can map() blindly). +// The shipped catalog is static product data; the core-hub entry is +// deployment DATA (MCP_HUB_URL), exactly like the Nextcloud DAV prefills. func HandleMcpConnectionsList(w http.ResponseWriter, r *http.Request) { rows, e := db.Many(r.Context(), database(r), `SELECT to_jsonb(t) FROM "McpConnection" t WHERE "ownerId"=$1 ORDER BY "createdAt"`, user(r)) @@ -110,7 +112,17 @@ func HandleMcpConnectionsList(w http.ResponseWriter, r *http.Request) { for _, row := range rows { out = append(out, mcpProjection(row)) } - respond(w, 200, object{"connections": out, "suggestions": mcpSuggestions}, nil) + suggestions := append([]object{}, mcpSuggestions...) + if hub := config.McpHubSuggestion(); hub != "" { + suggestions = append(suggestions, object{ + "kind": "core-hub", "name": "Core tool hub", + "url": hub + "/sse", + "transport": "sse", "authKind": "bearer", "available": true, + "description": "Files, calendar, contacts, repos and more from your core's apps — one connection.", + "secretHint": "Your hub token (mhub_…, from your core operator)", + }) + } + respond(w, 200, object{"connections": out, "suggestions": suggestions}, nil) } func cleanMcpFields(b object, create bool) (object, error) { diff --git a/internal/http/mcp_connections_test.go b/internal/http/mcp_connections_test.go index 960ad3a..4e36825 100644 --- a/internal/http/mcp_connections_test.go +++ b/internal/http/mcp_connections_test.go @@ -166,4 +166,27 @@ func TestMcpSuggestions(t *testing.T) { if hs["available"] != false || hs["url"] != "https://mcp.hubspot.com" { t.Fatalf("hubspot must be flagged OAuth-only: %v", hs) } + if _, present := byKind["core-hub"]; present { + t.Fatal("no MCP_HUB_URL -> no core-hub suggestion") + } + + // The core hub is deployment DATA (the NEXTCLOUD_URL pattern): present + // only when MCP_HUB_URL is set, SSE + bearer, origin + /sse. + t.Setenv("MCP_HUB_URL", "https://mcphub.example/") + list = c.request("GET", "/api/mcp/connections", nil, 200) + for _, s := range list["suggestions"].([]any) { + m := s.(map[string]any) + if m["kind"] == "core-hub" { + if m["url"] != "https://mcphub.example/sse" || m["transport"] != "sse" || m["authKind"] != "bearer" || m["available"] != true { + t.Fatalf("core-hub suggestion wrong: %v", m) + } + } + } + t.Setenv("MCP_HUB_URL", "not a url") + list = c.request("GET", "/api/mcp/connections", nil, 200) + for _, s := range list["suggestions"].([]any) { + if s.(map[string]any)["kind"] == "core-hub" { + t.Fatal("garbage MCP_HUB_URL must suggest nothing") + } + } } diff --git a/scripts/regressions.mjs b/scripts/regressions.mjs index 7cd8bff..56ae3a1 100644 --- a/scripts/regressions.mjs +++ b/scripts/regressions.mjs @@ -77,6 +77,7 @@ const mcpSuggestions = [ { kind: 'github', name: 'GitHub', url: 'https://api.githubcopilot.com/mcp/', transport: 'streamable-http', authKind: 'bearer', available: true, description: 'Repos, issues, pull requests, code search and Actions.', secretHint: 'GitHub personal access token (fine-grained recommended)', note: 'Append /readonly to the URL for read-only tools.' }, { kind: 'hubspot', name: 'HubSpot', url: 'https://mcp.hubspot.com', transport: 'streamable-http', authKind: 'bearer', available: false, description: 'CRM contacts, companies, deals, tickets and activities.', note: 'Requires OAuth 2.1 sign-in (PKCE) — HubSpot refuses token-only connections, and Superbrain\'s MCP client does not do OAuth flows yet.' }, { kind: 'make', name: 'Make', url: 'https://us1.make.com/mcp/v2', transport: 'streamable-http', authKind: 'bearer', available: true, description: 'Run your Make scenarios as tools; manage scenarios and data stores.', secretHint: 'Make API token with the mcp:use scope (Profile → API access)', note: 'Swap in your account\'s zone: eu1, eu2, us1 or us2.make.com.' }, + { kind: 'core-hub', name: 'Core tool hub', url: 'https://mcphub.federatedcomputer.ai/sse', transport: 'sse', authKind: 'bearer', available: true, description: 'Files, calendar, contacts, repos and more from your core\'s apps — one connection.', secretHint: 'Your hub token (mhub_…, from your core operator)' }, ] let lastNextcloudConnect = null // Automations fixture: the sidebar dropdown and the /automations workspace @@ -928,8 +929,9 @@ try { await page.goto(`${base}/settings`) await page.getByRole('tab', { name: 'MCP' }).click() await page.getByText('Repos, issues, pull requests, code search and Actions.').waitFor() - assert.equal(await page.getByRole('button', { name: 'Use', exact: true }).count(), 2, 'only token-connectable suggestions may offer Use') + assert.equal(await page.getByRole('button', { name: 'Use', exact: true }).count(), 3, 'only token-connectable suggestions may offer Use') await page.getByText('OAuth required').waitFor() + await page.getByText('https://mcphub.federatedcomputer.ai/sse').waitFor() await page.getByRole('button', { name: 'Use', exact: true }).first().click() assert.equal(await page.getByPlaceholder('https://mcp.example.tld/mcp').inputValue(), 'https://api.githubcopilot.com/mcp/') assert.equal(await page.getByPlaceholder('e.g. House gateway, Maps tools…').inputValue(), 'GitHub')