Skip to content

Commit 2faad08

Browse files
committed
chore: replace dedicated chatgpt endpoint with query param
1 parent f86a119 commit 2faad08

File tree

3 files changed

+48
-41
lines changed

3 files changed

+48
-41
lines changed

coderd/coderd.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -998,10 +998,7 @@ func New(options *Options) *API {
998998
)
999999

10001000
// MCP HTTP transport endpoint with mandatory authentication
1001-
r.Mount("/http", api.standardMCPHTTPHandler())
1002-
// ChatGPT gets a dedicated endpoint with a limited set of tools.
1003-
// See the docstring of the chatgptMCPHTTPHandler for more details.
1004-
r.Mount("/chatgpt", api.chatgptMCPHTTPHandler())
1001+
r.Mount("/http", api.mcpHTTPHandler())
10051002
})
10061003
})
10071004

coderd/mcp/mcp_e2e_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,7 @@ func TestMCPHTTP_E2E_ChatGPTEndpoint(t *testing.T) {
12321232
template := coderdtest.CreateTemplate(t, coderClient, user.OrganizationID, version.ID)
12331233

12341234
// Create MCP client pointing to the ChatGPT endpoint
1235-
mcpURL := api.AccessURL.String() + "/api/experimental/mcp/chatgpt"
1235+
mcpURL := api.AccessURL.String() + "/api/experimental/mcp/http?toolset=chatgpt"
12361236

12371237
// Configure client with authentication headers using RFC 6750 Bearer token
12381238
mcpClient, err := mcpclient.NewStreamableHttpClient(mcpURL,

coderd/mcp_http.go

Lines changed: 46 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,53 @@ import (
1212
"github.com/coder/coder/v2/codersdk/toolsdk"
1313
)
1414

15+
type MCPToolset string
16+
17+
const (
18+
MCPToolsetStandard MCPToolset = "standard"
19+
MCPToolsetChatGPT MCPToolset = "chatgpt"
20+
)
21+
1522
// mcpHTTPHandler creates the MCP HTTP transport handler
16-
func (api *API) mcpHTTPHandler(tools []toolsdk.GenericTool) http.Handler {
23+
// It supports a "toolset" query parameter to select the set of tools to register.
24+
func (api *API) mcpHTTPHandler() http.Handler {
1725
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
26+
toolset := MCPToolset(r.URL.Query().Get("toolset"))
27+
// Default to standard toolset if no toolset is specified.
28+
if toolset == "" {
29+
toolset = MCPToolsetStandard
30+
}
31+
32+
mcpTools := []toolsdk.GenericTool{}
33+
switch toolset {
34+
case MCPToolsetStandard:
35+
// Register all available tools, but exclude:
36+
// - ReportTask - which requires dependencies not available in the remote MCP context
37+
// - ChatGPT search and fetch tools, which are redundant with the standard tools.
38+
for _, tool := range toolsdk.All {
39+
if tool.Name == toolsdk.ToolNameReportTask ||
40+
tool.Name == toolsdk.ToolNameChatGPTSearch || tool.Name == toolsdk.ToolNameChatGPTFetch {
41+
continue
42+
}
43+
mcpTools = append(mcpTools, tool)
44+
}
45+
case MCPToolsetChatGPT:
46+
// ChatGPT tools are the search and fetch tools as defined in https://platform.openai.com/docs/mcp.
47+
// We do not expose any extra ones because ChatGPT has an undocumented "Safety Scan" feature.
48+
// In my experiments, if I included extra tools in the MCP server, ChatGPT would often - but not always -
49+
// refuse to add Coder as a connector.
50+
for _, tool := range toolsdk.All {
51+
if tool.Name == toolsdk.ToolNameChatGPTSearch || tool.Name == toolsdk.ToolNameChatGPTFetch {
52+
mcpTools = append(mcpTools, tool)
53+
}
54+
}
55+
default:
56+
httpapi.Write(r.Context(), w, http.StatusBadRequest, codersdk.Response{
57+
Message: "Invalid toolset",
58+
})
59+
return
60+
}
61+
1862
// Create MCP server instance for each request
1963
mcpServer, err := mcp.NewServer(api.Logger.Named("mcp"))
2064
if err != nil {
@@ -30,45 +74,11 @@ func (api *API) mcpHTTPHandler(tools []toolsdk.GenericTool) http.Handler {
3074
authenticatedClient.SetSessionToken(httpmw.APITokenFromRequest(r))
3175

3276
// Register tools with authenticated client
33-
if err := mcpServer.RegisterTools(authenticatedClient, tools); err != nil {
77+
if err := mcpServer.RegisterTools(authenticatedClient, mcpTools); err != nil {
3478
api.Logger.Warn(r.Context(), "failed to register MCP tools", slog.Error(err))
3579
}
3680

3781
// Handle the MCP request
3882
mcpServer.ServeHTTP(w, r)
3983
})
4084
}
41-
42-
// standardMCPHTTPHandler sets up the MCP HTTP transport handler for the standard tools.
43-
// Standard tools are all tools except for the report task, ChatGPT search, and ChatGPT fetch tools.
44-
func (api *API) standardMCPHTTPHandler() http.Handler {
45-
mcpTools := []toolsdk.GenericTool{}
46-
// Register all available tools, but exclude:
47-
// - ReportTask - which requires dependencies not available in the remote MCP context
48-
// - ChatGPT search and fetch tools, which are redundant with the standard tools.
49-
for _, tool := range toolsdk.All {
50-
if tool.Name == toolsdk.ToolNameReportTask ||
51-
tool.Name == toolsdk.ToolNameChatGPTSearch || tool.Name == toolsdk.ToolNameChatGPTFetch {
52-
continue
53-
}
54-
mcpTools = append(mcpTools, tool)
55-
}
56-
return api.mcpHTTPHandler(mcpTools)
57-
}
58-
59-
// chatgptMCPHTTPHandler sets up the MCP HTTP transport handler for the ChatGPT tools.
60-
// ChatGPT tools are the search and fetch tools as defined in https://platform.openai.com/docs/mcp.
61-
// We do not expose any extra ones because ChatGPT has an undocumented "Safety Scan" feature.
62-
// In my experiments, if I included extra tools in the MCP server, ChatGPT would refuse
63-
// to add Coder as a connector.
64-
func (api *API) chatgptMCPHTTPHandler() http.Handler {
65-
mcpTools := []toolsdk.GenericTool{}
66-
// Register only the ChatGPT search and fetch tools.
67-
for _, tool := range toolsdk.All {
68-
if !(tool.Name == toolsdk.ToolNameChatGPTSearch || tool.Name == toolsdk.ToolNameChatGPTFetch) {
69-
continue
70-
}
71-
mcpTools = append(mcpTools, tool)
72-
}
73-
return api.mcpHTTPHandler(mcpTools)
74-
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy