on main help sign in
fix(mcp): race condition, logs (#2145)
775cf3aCarlos Alexandro Becker
internal/agent/tools/list_mcp_resources.go+1−2
@@ -1,7 +1,6 @@
1package tools
1package tools
2
2
3import (
3import (
4− "cmp"
5 "context"
4 "context"
6 _ "embed"
5 _ "embed"
7 "fmt"
6 "fmt"
@@ -43,7 +42,7 @@ func NewListMCPResourcesTool(cfg *config.Config, permissions permission.Service)
43 return fantasy.ToolResponse{}, fmt.Errorf("session ID is required for listing MCP resources")
42 return fantasy.ToolResponse{}, fmt.Errorf("session ID is required for listing MCP resources")
44 }
43 }
45
44
46− relPath := filepathext.SmartJoin(cfg.WorkingDir(), cmp.Or(params.MCPName, "mcp-resources"))
45+ relPath := filepathext.SmartJoin(cfg.WorkingDir(), params.MCPName)
47 p, err := permissions.Request(ctx,
46 p, err := permissions.Request(ctx,
48 permission.CreatePermissionRequest{
47 permission.CreatePermissionRequest{
49 SessionID: sessionID,
48 SessionID: sessionID,
internal/ui/model/ui.go+10−6
@@ -97,6 +97,10 @@ type (
97 mcpPromptsLoadedMsg struct {
97 mcpPromptsLoadedMsg struct {
98 Prompts []commands.MCPPrompt
98 Prompts []commands.MCPPrompt
99 }
99 }
100+ // mcpStateChangedMsg is sent when there is a change in MCP client states.
101+ mcpStateChangedMsg struct {
102+ states map[string]mcp.ClientInfo
103+ }
100 // sendMessageMsg is sent to send a message.
104 // sendMessageMsg is sent to send a message.
101 // currently only used for mcp prompts.
105 // currently only used for mcp prompts.
102 sendMessageMsg struct {
106 sendMessageMsg struct {
@@ -429,6 +433,9 @@ func (m *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
429 if ok {
433 if ok {
430 commands.SetCustomCommands(m.customCommands)
434 commands.SetCustomCommands(m.customCommands)
431 }
435 }
436+
437+ case mcpStateChangedMsg:
438+ m.mcpStates = msg.states
432 case mcpPromptsLoadedMsg:
439 case mcpPromptsLoadedMsg:
433 m.mcpPrompts = msg.Prompts
440 m.mcpPrompts = msg.Prompts
434 dia := m.dialog.Dialog(dialog.CommandsID)
441 dia := m.dialog.Dialog(dialog.CommandsID)
@@ -3149,16 +3156,15 @@ func (m *UI) runMCPPrompt(clientID, promptID string, arguments map[string]string
3149}
3156}
3150
3157
3151func (m *UI) handleStateChanged() tea.Cmd {
3158func (m *UI) handleStateChanged() tea.Cmd {
3152− slog.Warn("handleStateChanged")
3153 return func() tea.Msg {
3159 return func() tea.Msg {
3154 m.com.App.UpdateAgentModel(context.Background())
3160 m.com.App.UpdateAgentModel(context.Background())
3161+ return mcpStateChangedMsg{
3155− m.mcpStates = mcp.GetStates()
3162+ states: mcp.GetStates(),
3156− return nil
3163+ }
3157 }
3164 }
3158}
3165}
3159
3166
3160func handleMCPPromptsEvent(name string) tea.Cmd {
3167func handleMCPPromptsEvent(name string) tea.Cmd {
3161− slog.Warn("handleMCPPromptsEvent")
3162 return func() tea.Msg {
3168 return func() tea.Msg {
3163 mcp.RefreshPrompts(context.Background(), name)
3169 mcp.RefreshPrompts(context.Background(), name)
3164 return nil
3170 return nil
@@ -3166,7 +3172,6 @@ func handleMCPPromptsEvent(name string) tea.Cmd {
3166}
3172}
3167
3173
3168func handleMCPToolsEvent(cfg *config.Config, name string) tea.Cmd {
3174func handleMCPToolsEvent(cfg *config.Config, name string) tea.Cmd {
3169− slog.Warn("handleMCPToolsEvent")
3170 return func() tea.Msg {
3175 return func() tea.Msg {
3171 mcp.RefreshTools(
3176 mcp.RefreshTools(
3172 context.Background(),
3177 context.Background(),
@@ -3178,7 +3183,6 @@ func handleMCPToolsEvent(cfg *config.Config, name string) tea.Cmd {
3178}
3183}
3179
3184
3180func handleMCPResourcesEvent(name string) tea.Cmd {
3185func handleMCPResourcesEvent(name string) tea.Cmd {
3181− slog.Warn("handleMCPResourcesEvent")
3182 return func() tea.Msg {
3186 return func() tea.Msg {
3183 mcp.RefreshResources(context.Background(), name)
3187 mcp.RefreshResources(context.Background(), name)
3184 return nil
3188 return nil