Skip to content

Commit 6f2053d

Browse files
committed
Clean up 'Servers' in API docs (break out sub-components)
1 parent 3f53ba3 commit 6f2053d

File tree

4 files changed

+48
-36
lines changed

4 files changed

+48
-36
lines changed

internal/api/prompts.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,11 @@ func handleServerPromptGenerate(
243243
}
244244

245245
// RegisterPromptRoutes registers prompt-related routes under the servers API.
246-
func RegisterPromptRoutes(serversAPI huma.API, accessor contracts.MCPClientAccessor) {
247-
tags := []string{"Servers", "Prompts"}
246+
func RegisterPromptRoutes(parentAPI huma.API, accessor contracts.MCPClientAccessor) {
247+
tags := []string{"Prompts"}
248248

249249
huma.Register(
250-
serversAPI,
250+
parentAPI,
251251
huma.Operation{
252252
OperationID: "listPrompts",
253253
Method: "GET",
@@ -261,7 +261,7 @@ func RegisterPromptRoutes(serversAPI huma.API, accessor contracts.MCPClientAcces
261261
)
262262

263263
huma.Register(
264-
serversAPI,
264+
parentAPI,
265265
huma.Operation{
266266
OperationID: "generatePrompt",
267267
Method: "POST",

internal/api/resources.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,11 +344,11 @@ func handleServerResourceContent(
344344
}
345345

346346
// RegisterResourceRoutes registers resource-related routes under the servers API.
347-
func RegisterResourceRoutes(serversAPI huma.API, accessor contracts.MCPClientAccessor) {
348-
tags := []string{"Servers", "Resources"}
347+
func RegisterResourceRoutes(parentAPI huma.API, accessor contracts.MCPClientAccessor) {
348+
tags := []string{"Resources"}
349349

350350
huma.Register(
351-
serversAPI,
351+
parentAPI,
352352
huma.Operation{
353353
OperationID: "listResources",
354354
Method: "GET",
@@ -362,7 +362,7 @@ func RegisterResourceRoutes(serversAPI huma.API, accessor contracts.MCPClientAcc
362362
)
363363

364364
huma.Register(
365-
serversAPI,
365+
parentAPI,
366366
huma.Operation{
367367
OperationID: "listResourceTemplates",
368368
Method: "GET",
@@ -376,7 +376,7 @@ func RegisterResourceRoutes(serversAPI huma.API, accessor contracts.MCPClientAcc
376376
)
377377

378378
huma.Register(
379-
serversAPI,
379+
parentAPI,
380380
huma.Operation{
381381
OperationID: "getResourceContent",
382382
Method: "GET",

internal/api/servers.go

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -51,33 +51,8 @@ func RegisterServerRoutes(routerAPI huma.API, accessor contracts.MCPClientAccess
5151
},
5252
)
5353

54-
huma.Register(
55-
serversAPI,
56-
huma.Operation{
57-
OperationID: "listTools",
58-
Method: http.MethodGet,
59-
Path: "/{name}/tools",
60-
Summary: "List server tools",
61-
Tags: append(tags, "Tools"),
62-
},
63-
func(ctx context.Context, input *ServerToolsRequest) (*ToolsResponse, error) {
64-
return handleServerTools(accessor, input.Name)
65-
},
66-
)
67-
68-
huma.Register(
69-
serversAPI,
70-
huma.Operation{
71-
OperationID: "callTool",
72-
Method: http.MethodPost,
73-
Path: "/{server}/tools/{tool}",
74-
Summary: "Call a tool for a server",
75-
Tags: append(tags, "Tools"),
76-
},
77-
func(ctx context.Context, input *ServerToolCallRequest) (*ToolCallResponse, error) {
78-
return handleServerToolCall(accessor, input.Server, input.Tool, input.Body)
79-
},
80-
)
54+
// Register tool routes.
55+
RegisterToolRoutes(serversAPI, accessor)
8156

8257
// Register prompt routes.
8358
RegisterPromptRoutes(serversAPI, accessor)

internal/api/tools.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
package api
22

33
import (
4+
"context"
5+
"net/http"
6+
7+
"github.com/danielgtaylor/huma/v2"
48
"github.com/mark3labs/mcp-go/mcp"
59

10+
"github.com/mozilla-ai/mcpd/v2/internal/contracts"
611
"github.com/mozilla-ai/mcpd/v2/internal/filter"
712
)
813

@@ -122,3 +127,35 @@ func (d DomainTool) ToAPIType() (Tool, error) {
122127
Annotations: annotations,
123128
}, nil
124129
}
130+
131+
func RegisterToolRoutes(parentAPI huma.API, accessor contracts.MCPClientAccessor) {
132+
tags := []string{"Tools"}
133+
134+
huma.Register(
135+
parentAPI,
136+
huma.Operation{
137+
OperationID: "listTools",
138+
Method: http.MethodGet,
139+
Path: "/{name}/tools",
140+
Summary: "List server tools",
141+
Tags: tags,
142+
},
143+
func(ctx context.Context, input *ServerToolsRequest) (*ToolsResponse, error) {
144+
return handleServerTools(accessor, input.Name)
145+
},
146+
)
147+
148+
huma.Register(
149+
parentAPI,
150+
huma.Operation{
151+
OperationID: "callTool",
152+
Method: http.MethodPost,
153+
Path: "/{server}/tools/{tool}",
154+
Summary: "Call a tool for a server",
155+
Tags: tags,
156+
},
157+
func(ctx context.Context, input *ServerToolCallRequest) (*ToolCallResponse, error) {
158+
return handleServerToolCall(accessor, input.Server, input.Tool, input.Body)
159+
},
160+
)
161+
}

0 commit comments

Comments
 (0)