handleListTools returns the current MCP tool cache after the manager performs startup-safe config synchronization.
(rw http.ResponseWriter, r *http.Request)
| 40 | // handleListTools returns the current MCP tool cache after the |
| 41 | // manager performs startup-safe config synchronization. |
| 42 | func (api *API) handleListTools(rw http.ResponseWriter, r *http.Request) { |
| 43 | ctx := r.Context() |
| 44 | logger := api.logger.With(agentchat.Fields(ctx)...) |
| 45 | |
| 46 | tools, err := api.manager.Tools(ctx, api.mcpConfigFiles()) |
| 47 | if err != nil { |
| 48 | switch { |
| 49 | case errors.Is(err, context.Canceled): |
| 50 | logger.Warn(ctx, "mcp tool list canceled by caller", slog.Error(err)) |
| 51 | case errors.Is(err, context.DeadlineExceeded): |
| 52 | logger.Warn(ctx, "mcp tool list timed out", slog.Error(err)) |
| 53 | default: |
| 54 | logger.Warn(ctx, "mcp tool list failed", slog.Error(err)) |
| 55 | } |
| 56 | } |
| 57 | if tools == nil { |
| 58 | tools = []workspacesdk.MCPToolInfo{} |
| 59 | } |
| 60 | httpapi.Write(ctx, rw, http.StatusOK, workspacesdk.ListMCPToolsResponse{ |
| 61 | Tools: tools, |
| 62 | }) |
| 63 | } |
| 64 | |
| 65 | // handleCallTool proxies a tool invocation to the appropriate |
| 66 | // MCP server based on the tool name prefix. |