Skip to content
Open
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
42 changes: 42 additions & 0 deletions pkg/gateway/mcp/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion pkg/gateway/mcp/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/mcpcore/tool_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
14 changes: 12 additions & 2 deletions pkg/mcpcore/tool_projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down