on main help sign in
fix: handle delayed mcp init
5d01173Carlos Alexandro Becker
internal/agent/coordinator.go+10−12
@@ -348,22 +348,20 @@ func (c *coordinator) buildTools(ctx context.Context, agent config.Agent) ([]fan
348 if agent.AllowedMCP == nil {
348 if agent.AllowedMCP == nil {
349 // No MCP restrictions
349 // No MCP restrictions
350 filteredTools = append(filteredTools, tool)
350 filteredTools = append(filteredTools, tool)
351+ continue
352+ }
351− } else if len(agent.AllowedMCP) == 0 {
353+ if len(agent.AllowedMCP) == 0 {
354+ // No MCPs allowed
352− // no mcps allowed
355+ slog.Warn("MCPs not allowed")
353 break
356 break
354 }
357 }
355
358
356 for mcp, tools := range agent.AllowedMCP {
359 for mcp, tools := range agent.AllowedMCP {
357− if mcp == tool.MCP() {
360+ if mcp != tool.MCP() {
358− if len(tools) == 0 {
361+ continue
359− filteredTools = append(filteredTools, tool)
362+ }
360− }
361− for _, t := range tools {
362− if t == tool.MCPToolName() {
363+ if len(tools) == 0 || slices.Contains(tools, tool.MCPToolName()) {
363− filteredTools = append(filteredTools, tool)
364+ filteredTools = append(filteredTools, tool)
364− }
365− }
366− break
367 }
365 }
368 }
366 }
369 }
367 }
internal/tui/tui.go+13−4
@@ -143,10 +143,12 @@ func (a *appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
143
143
144 case pubsub.Event[mcp.Event]:
144 case pubsub.Event[mcp.Event]:
145 switch msg.Payload.Type {
145 switch msg.Payload.Type {
146+ case mcp.EventStateChanged:
147+ return a, a.handleStateChanged(context.Background())
146 case mcp.EventPromptsListChanged:
148 case mcp.EventPromptsListChanged:
147− return a, a.handleMCPPromptsEvent(context.Background(), msg.Payload.Name)
149+ return a, handleMCPPromptsEvent(context.Background(), msg.Payload.Name)
148 case mcp.EventToolsListChanged:
150 case mcp.EventToolsListChanged:
149− return a, a.handleMCPToolsEvent(context.Background(), msg.Payload.Name)
151+ return a, handleMCPToolsEvent(context.Background(), msg.Payload.Name)
150 }
152 }
151
153
152 // Completions messages
154 // Completions messages
@@ -627,14 +629,21 @@ func (a *appModel) View() tea.View {
627 return view
629 return view
628}
630}
629
631
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+
630−func (a *appModel) handleMCPPromptsEvent(ctx context.Context, name string) tea.Cmd {
639+func handleMCPPromptsEvent(ctx context.Context, name string) tea.Cmd {
631 return func() tea.Msg {
640 return func() tea.Msg {
632 mcp.RefreshPrompts(ctx, name)
641 mcp.RefreshPrompts(ctx, name)
633 return nil
642 return nil
634 }
643 }
635}
644}
636
645
637−func (a *appModel) handleMCPToolsEvent(ctx context.Context, name string) tea.Cmd {
646+func handleMCPToolsEvent(ctx context.Context, name string) tea.Cmd {
638 return func() tea.Msg {
647 return func() tea.Msg {
639 mcp.RefreshTools(ctx, name)
648 mcp.RefreshTools(ctx, name)
640 return nil
649 return nil