getTools executes tool retrieval with automatic OAuth handling. emitLifecycleEvents controls whether MCPInitStarted/Finished are emitted; pass false when calling from reprobe to avoid spurious TUI spinner flicker.
(ctx context.Context, a *agent.Agent, sessionSpan trace.Span, events EventSink, emitLifecycleEvents bool)
| 1138 | // emitLifecycleEvents controls whether MCPInitStarted/Finished are emitted; |
| 1139 | // pass false when calling from reprobe to avoid spurious TUI spinner flicker. |
| 1140 | func (r *LocalRuntime) getTools(ctx context.Context, a *agent.Agent, sessionSpan trace.Span, events EventSink, emitLifecycleEvents bool) ([]tools.Tool, error) { |
| 1141 | if emitLifecycleEvents && len(a.ToolSets()) > 0 { |
| 1142 | events.Emit(MCPInitStarted(a.Name())) |
| 1143 | defer func() { events.Emit(MCPInitFinished(a.Name())) }() |
| 1144 | } |
| 1145 | |
| 1146 | agentTools, err := a.Tools(ctx) |
| 1147 | if err != nil { |
| 1148 | slog.ErrorContext(ctx, "Failed to get agent tools", "agent", a.Name(), "error", err) |
| 1149 | sessionSpan.RecordError(err) |
| 1150 | sessionSpan.SetStatus(codes.Error, "failed to get tools") |
| 1151 | r.telemetry.RecordError(ctx, err.Error()) |
| 1152 | return nil, err |
| 1153 | } |
| 1154 | |
| 1155 | slog.DebugContext(ctx, "Retrieved agent tools", "agent", a.Name(), "tool_count", len(agentTools)) |
| 1156 | return agentTools, nil |
| 1157 | } |
| 1158 | |
| 1159 | // configureToolsetHandlers sets up elicitation and OAuth handlers for all toolsets of an agent. |
| 1160 | func (r *LocalRuntime) configureToolsetHandlers(a *agent.Agent, events EventSink) { |