MCPcopy Index your code
hub / github.com/coder/coder / handleCallTool

Method handleCallTool

agent/x/agentmcp/api.go:67–91  ·  view source on GitHub ↗

handleCallTool proxies a tool invocation to the appropriate MCP server based on the tool name prefix.

(rw http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

65// handleCallTool proxies a tool invocation to the appropriate
66// MCP server based on the tool name prefix.
67func (api *API) handleCallTool(rw http.ResponseWriter, r *http.Request) {
68 ctx := r.Context()
69
70 var req workspacesdk.CallMCPToolRequest
71 if !httpapi.Read(ctx, rw, r, &req) {
72 return
73 }
74
75 resp, err := api.manager.CallTool(ctx, req)
76 if err != nil {
77 status := http.StatusBadGateway
78 if errors.Is(err, ErrInvalidToolName) {
79 status = http.StatusBadRequest
80 } else if errors.Is(err, ErrUnknownServer) {
81 status = http.StatusNotFound
82 }
83 httpapi.Write(ctx, rw, status, codersdk.Response{
84 Message: "MCP tool call failed.",
85 Detail: err.Error(),
86 })
87 return
88 }
89
90 httpapi.Write(ctx, rw, http.StatusOK, resp)
91}

Callers

nothing calls this directly

Calls 6

ReadFunction · 0.92
WriteFunction · 0.92
ContextMethod · 0.65
CallToolMethod · 0.65
IsMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected