From e0c7ab80befa659feb787f2077f26cd021ed1dba Mon Sep 17 00:00:00 2001 From: Alex Castillo Date: Wed, 18 Nov 2026 23:07:57 -0400 Subject: [PATCH] fix(mcp): scope gateway mcp projects list/use to Gateway projects The Gateway MCP server set no ProjectFilter, so hookdeck_projects use accepted an Outpost project and every later Gateway call 404ed. Set ProjectFilter to the Event Gateway type; the filter treats console projects as Gateway projects (also in the login mismatch check), and the refusal now points at the other product's MCP server. Co-Authored-By: Claude Sonnet 5.5 --- pkg/gateway/mcp/server_test.go | 42 ++++++++++++++++++++++++++++++++++ pkg/gateway/mcp/tools.go | 6 ++++- pkg/mcpcore/tool_login.go | 2 +- pkg/mcpcore/tool_projects.go | 14 ++++++++++-- 4 files changed, 60 insertions(+), 4 deletions(-) diff --git a/pkg/gateway/mcp/server_test.go b/pkg/gateway/mcp/server_test.go index 2c8d4bbc..e26ae484 100644 --- a/pkg/gateway/mcp/server_test.go +++ b/pkg/gateway/mcp/server_test.go @@ -1436,6 +1436,48 @@ func TestProjectsUse_Success(t *testing.T) { assert.Contains(t, text, `"active_project_id"`) } +// The Gateway server can only serve Gateway projects, so it must neither list +// nor switch to an Outpost project (the switch would leave every Gateway tool +// 404ing against a project it cannot serve). +func mixedTypeProjectsHandler() map[string]http.HandlerFunc { + return map[string]http.HandlerFunc{ + hookdeck.APIPathPrefix + "/projects": func(w http.ResponseWriter, r *http.Request) { + json.NewEncoder(w).Encode([]map[string]any{ + {"id": "proj_test123", "name": "Production", "type": "event_gateway"}, + {"id": "proj_console", "name": "Console One", "type": "console"}, + {"id": "proj_outpost", "name": "Outpost One", "type": "outpost"}, + }) + }, + } +} + +func TestProjectsList_OnlyGatewayProjects(t *testing.T) { + session := mockAPIWithClient(t, mixedTypeProjectsHandler()) + + result := callTool(t, session, "hookdeck_projects_read", map[string]any{"action": "list"}) + assert.False(t, result.IsError) + text := textContent(t, result) + assert.Contains(t, text, "Production") + assert.Contains(t, text, "Console One") + assert.NotContains(t, text, "Outpost One") + assert.NotContains(t, text, "proj_outpost") +} + +func TestProjectsUse_RefusesOutpostProject(t *testing.T) { + api := mockAPI(t, mixedTypeProjectsHandler()) + client := newTestClient(api.URL, "test-key") + client.SuppressRateLimitErrors = true + session := connectInMemory(t, client) + + result := callTool(t, session, "hookdeck_projects_use", map[string]any{"action": "use", "project_id": "proj_outpost"}) + assert.True(t, result.IsError) + text := textContent(t, result) + assert.Contains(t, text, "gateway projects") + assert.Contains(t, text, "hookdeck outpost mcp") + // The session must stay on the project it was already on. + assert.Equal(t, "proj_test123", client.ProjectID) +} + func TestProjectsUse_MissingProjectID(t *testing.T) { client := newTestClient("https://api.hookdeck.com", "test-key") session := connectInMemory(t, client) diff --git a/pkg/gateway/mcp/tools.go b/pkg/gateway/mcp/tools.go index 482b83a4..3250b411 100644 --- a/pkg/gateway/mcp/tools.go +++ b/pkg/gateway/mcp/tools.go @@ -64,7 +64,11 @@ func NewServer(opts ServerOptions) *mcpcore.Server { Client: opts.Client, Config: opts.Config, WriteEnabled: opts.WriteEnabled, - ToolDefs: toolDefs, + // A Gateway server can only act on Gateway projects; without this + // filter `projects use` accepts an Outpost project and every later + // call 404s. + ProjectFilter: config.ProjectTypeEventGateway, + ToolDefs: toolDefs, }) } diff --git a/pkg/mcpcore/tool_login.go b/pkg/mcpcore/tool_login.go index 2ff6ff69..53dfea07 100644 --- a/pkg/mcpcore/tool_login.go +++ b/pkg/mcpcore/tool_login.go @@ -80,7 +80,7 @@ func loginProjectMismatch(filter string, response *hookdeck.PollAPIKeyResponse, return nil } got := config.NormalizeProjectType(response.ProjectType) - if got == filter { + if matchesProjectFilter(got, filter) { return nil } return fmt.Errorf( diff --git a/pkg/mcpcore/tool_projects.go b/pkg/mcpcore/tool_projects.go index 48b50083..f7185c6b 100644 --- a/pkg/mcpcore/tool_projects.go +++ b/pkg/mcpcore/tool_projects.go @@ -101,13 +101,23 @@ func listProjectItems(srv *Server, client *hookdeck.Client) ([]project.ProjectLi filtered := make([]project.ProjectListItem, 0, len(items)) for _, it := range items { - if it.Type == filter { + if matchesProjectFilter(it.Type, filter) { filtered = append(filtered, it) } } return filtered, nil } +// matchesProjectFilter reports whether a project of projectType is served by a +// server whose filter is filter. Console projects are Event Gateway projects +// with a different entry point, so the Gateway filter accepts both. +func matchesProjectFilter(projectType, filter string) bool { + if filter == config.ProjectTypeEventGateway { + return config.IsGatewayProject(projectType) + } + return projectType == filter +} + func projectsList(srv *Server, client *hookdeck.Client) (*mcpsdk.CallToolResult, error) { items, err := listProjectItems(srv, client) if err != nil { @@ -152,7 +162,7 @@ func projectsUse(srv *Server, client *hookdeck.Client, in Input) (*mcpsdk.CallTo // The project may well exist — it is just not one this server can // serve, and switching to it would make every later call fail. return ErrorResult(fmt.Sprintf( - "project %q not found among the %s projects available to this server. Use action list to see them.", + "project %q not found among the %s projects available to this server. Use action list to see them; projects of other types are served by their own MCP server (hookdeck gateway mcp / hookdeck outpost mcp).", id, config.ProjectTypeToJSON(filter), )), nil }