on main help sign in
fix: handle delayed mcp init

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

commit5d011730c39013e00332757c3b90ed5d7eb66411 authorCarlos Alexandro Becker <caarlos0@users.noreply.github.com> dateMon 3 Nov 2025, 15:56 (1 year ago) parenta2f7cbb
2 files changed+23−16
internal/agent/coordinator.go+10−12 internal/tui/tui.go+13−4
internal/agent/coordinator.go+10−12
@@ -348,22 +348,20 @@ func (c *coordinator) buildTools(ctx context.Context, agent config.Agent) ([]fan
348348 if agent.AllowedMCP == nil {
349349 // No MCP restrictions
350350 filteredTools = append(filteredTools, tool)
351− } else if len(agent.AllowedMCP) == 0 {
352− // no mcps allowed
351+ continue
352+ }
353+ if len(agent.AllowedMCP) == 0 {
354+ // No MCPs allowed
355+ slog.Warn("MCPs not allowed")
353356 break
354357 }
355358
356359 for mcp, tools := range agent.AllowedMCP {
357− if mcp == tool.MCP() {
358− if len(tools) == 0 {
359− filteredTools = append(filteredTools, tool)
360− }
361− for _, t := range tools {
362− if t == tool.MCPToolName() {
363− filteredTools = append(filteredTools, tool)
364− }
365− }
366− break
360+ if mcp != tool.MCP() {
361+ continue
362+ }
363+ if len(tools) == 0 || slices.Contains(tools, tool.MCPToolName()) {
364+ filteredTools = append(filteredTools, tool)
367365 }
368366 }
369367 }
internal/tui/tui.go+13−4
@@ -143,10 +143,12 @@ func (a *appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
143143
144144 case pubsub.Event[mcp.Event]:
145145 switch msg.Payload.Type {
146+ case mcp.EventStateChanged:
147+ return a, a.handleStateChanged(context.Background())
146148 case mcp.EventPromptsListChanged:
147− return a, a.handleMCPPromptsEvent(context.Background(), msg.Payload.Name)
149+ return a, handleMCPPromptsEvent(context.Background(), msg.Payload.Name)
148150 case mcp.EventToolsListChanged:
149− return a, a.handleMCPToolsEvent(context.Background(), msg.Payload.Name)
151+ return a, handleMCPToolsEvent(context.Background(), msg.Payload.Name)
150152 }
151153
152154 // Completions messages
@@ -627,14 +629,21 @@ func (a *appModel) View() tea.View {
627629 return view
628630}
629631
630−func (a *appModel) handleMCPPromptsEvent(ctx context.Context, name string) tea.Cmd {
632+func (a *appModel) handleStateChanged(ctx context.Context) tea.Cmd {
633+ return func() tea.Msg {
634+ a.app.UpdateAgentModel(ctx)
635+ return nil
636+ }
637+}
638+
639+func handleMCPPromptsEvent(ctx context.Context, name string) tea.Cmd {
631640 return func() tea.Msg {
632641 mcp.RefreshPrompts(ctx, name)
633642 return nil
634643 }
635644}
636645
637−func (a *appModel) handleMCPToolsEvent(ctx context.Context, name string) tea.Cmd {
646+func handleMCPToolsEvent(ctx context.Context, name string) tea.Cmd {
638647 return func() tea.Msg {
639648 mcp.RefreshTools(ctx, name)
640649 return nil