Skip to content

feat(agent): add MCP server discovery mode for agent tool input#3353

Merged
waleedlatif1 merged 17 commits intostagingfrom
waleedlatif1/mcp-server-tools
Feb 26, 2026
Merged

feat(agent): add MCP server discovery mode for agent tool input#3353
waleedlatif1 merged 17 commits intostagingfrom
waleedlatif1/mcp-server-tools

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

  • Add mcp-server tool type that lets agents dynamically discover and use all tools from an MCP server at execution time
  • Extend agent handler to separate mcp-server selections, discover tools via existing discoverMcpToolsForServer, and create tools through buildMcpTool (same pipeline as individual MCP tools)
  • Add grouped MCP server dropdown in tool picker UI with expandable server folders and "Use all N tools" option
  • Add keepOpen option to combobox to support expandable dropdown sections
  • Add isMcpServerAlreadySelected helper and mcp-server guards throughout selected tool rendering

Type of Change

  • New feature

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Feb 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Feb 26, 2026 10:57pm

Request Review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 26, 2026

Greptile Summary

This PR adds a new "mcp-server" tool type that enables agents to dynamically discover and use all tools from an MCP server at execution time, rather than requiring individual tool selection.

Key Changes:

  • Added mcp-server tool type with server-level selection in the agent tool input UI
  • Grouped MCP servers in a folder-based dropdown with expandable sections and "Use all N tools" option
  • Extended agent handler to separate mcp-server selections and expand them into individual tools via existing discoverMcpToolsForServer and buildMcpTool pipeline
  • Added keepOpen option to combobox for navigable dropdown sections with ArrowLeft/ArrowRight keyboard support
  • Added isMcpServerAlreadySelected helper and mcp-server type guards throughout the codebase
  • Extracted getMcpServerIssue for server-level validation (connectivity, URL changes)

Implementation Quality:

  • Clean separation between UI (tool-input), execution (agent-handler), and validation (tool-validation)
  • Reuses existing MCP infrastructure for consistency
  • Proper state management with drilldown navigation
  • Comprehensive type guards for the new mcp-server type
  • Good error handling with appropriate fallbacks

Minor Issues:

  • Uses Promise.all for tool creation which fails the entire server if any tool fails (should use Promise.allSettled for partial success)

Confidence Score: 4/5

  • Safe to merge with one minor logic issue in error handling
  • Well-structured implementation that follows existing patterns and includes proper type guards, validation, and state management. One issue with Promise.all could cause all tools from a server to fail if any single tool fails, but the overall error handling prevents crashes. No security concerns or breaking changes.
  • apps/sim/executor/handlers/agent/agent-handler.ts requires attention for the Promise.all issue at line 303-312

Important Files Changed

Filename Overview
apps/sim/executor/handlers/agent/agent-handler.ts Adds processMcpServerSelections to expand mcp-server selections into individual tools via existing discoverMcpToolsForServer and buildMcpTool functions. One issue: uses Promise.all which fails entire server if any tool fails.
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/tool-input/tool-input.tsx Implements MCP server drilldown UI with folder navigation, "Use all N tools" option, and proper state management. Correctly handles mcp-server selections, prevents duplicates, and validates server-level issues.
apps/sim/components/emcn/components/combobox/combobox.tsx Adds keepOpen option and ArrowLeft/ArrowRight keyboard navigation for folder-style dropdowns. Properly handles cursor boundary detection in search input to preserve text editing.
apps/sim/executor/handlers/agent/types.ts Adds documentation for new mcp-server tool type that enables server-level selection with dynamic tool discovery at execution time.
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/tool-input/utils.ts Adds isMcpServerAlreadySelected helper to check if an MCP server is already selected in all-tools mode.
apps/sim/lib/mcp/tool-validation.ts Extracts getMcpServerIssue to validate server-level connectivity (server existence, connection status, URL changes) separately from tool-specific validation.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[User opens tool picker] --> B{Navigates to MCP Servers}
    B --> C[Shows server folders with tool count]
    C --> D{User clicks server folder}
    D --> E[Drilldown: Shows Back + Use all tools + Individual tools]
    E --> F{User selects Use all N tools}
    F --> G[Creates mcp-server StoredTool with serverId]
    G --> H[Removes individual tools from same server]
    H --> I[Tool stored in workflow config]
    
    I --> J[Agent execution starts]
    J --> K[AgentHandler.prepareTools]
    K --> L{Separates tool types}
    L --> M[mcpTools array]
    L --> N[mcpServerSelections array]
    L --> O[otherTools array]
    
    N --> P[processMcpServerSelections]
    P --> Q[For each server: discoverMcpToolsForServer]
    Q --> R[Get all tools from MCP server]
    R --> S[createMcpToolFromDiscoveredServerTool for each]
    S --> T[buildMcpTool - same as individual MCP tools]
    T --> U[Returns array of tool definitions]
    
    M --> V[processMcpToolsBatched]
    O --> W[Process other tools]
    
    U --> X[Combine all tools]
    V --> X
    W --> X
    X --> Y[Agent executes with expanded tool set]
Loading

Last reviewed commit: 6e2fb7c

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

20 files reviewed, 5 comments

Edit Code Review Agent Settings | Greptile

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 26, 2026

Additional Comments (4)

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/tool-input/tool-input.tsx
hasMcpTools doesn't include mcp-server type - if only server-level tools are selected, MCP data won't refresh

  const hasMcpTools = selectedTools.some((tool) => tool.type === 'mcp' || tool.type === 'mcp-server')

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/tool-input/tool-input.tsx
usage control shows for unavailable MCP servers - should also check isMcpServer and unavailability

                  {supportsToolControl && !((isMcpTool || isMcpServer) && isMcpToolUnavailable(tool)) && (

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/tool-input/tool-input.tsx
MCP servers don't show unavailability badges - add similar badge logic for isMcpServer to indicate when server is disconnected


apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/tool-input/tool-input.tsx
getMcpToolIssue returns null for mcp-server tools - consider adding server-level validation to check connectivity for mcp-server type

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@waleedlatif1
Copy link
Collaborator Author

@greptile

@waleedlatif1
Copy link
Collaborator Author

@cursor review

@waleedlatif1
Copy link
Collaborator Author

@greptile

@waleedlatif1
Copy link
Collaborator Author

@cursor review

@waleedlatif1
Copy link
Collaborator Author

@greptile

@waleedlatif1
Copy link
Collaborator Author

@cursor review

@waleedlatif1
Copy link
Collaborator Author

@greptile

@waleedlatif1
Copy link
Collaborator Author

@cursor review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 26, 2026

Additional Comments (1)

apps/sim/executor/handlers/agent/agent-handler.ts, line 325
Consider parallelizing server processing with Promise.all for better performance when multiple MCP servers are selected

    const results = await Promise.all(
      mcpServerSelections.map(async (serverSelection) => {
        const serverId = serverSelection.params?.serverId
        const serverName = serverSelection.params?.serverName
        const usageControl = serverSelection.usageControl || 'auto'

        if (!serverId) {
          logger.error('MCP server selection missing serverId:', serverSelection)
          return []
        }

        try {
          const discoveredTools = await this.discoverMcpToolsForServer(ctx, serverId)
          const createdTools = await Promise.all(
            discoveredTools.map((mcpTool) =>
              this.createMcpToolFromDiscoveredServerTool(
                mcpTool,
                serverId,
                serverName || serverId,
                usageControl
              )
            )
          )
          logger.info(
            `[AgentHandler] Expanded MCP server ${serverName} into ${discoveredTools.length} tools`
          )
          return createdTools.filter(Boolean)
        } catch (error) {
          logger.error(`[AgentHandler] Failed to process MCP server selection:`, { serverId, error })
          return []
        }
      })
    )

    return results.flat()

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@waleedlatif1
Copy link
Collaborator Author

@cursor review

@waleedlatif1
Copy link
Collaborator Author

@greptile

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 26, 2026

Additional Comments (1)

apps/sim/executor/handlers/agent/agent-handler.ts, line 312
Promise.all will reject if any single tool fails, returning no tools for the entire server. Use Promise.allSettled for partial success.

          const createdToolsResults = await Promise.allSettled(
            discoveredTools.map((mcpTool) =>
              this.createMcpToolFromDiscoveredServerTool(
                mcpTool,
                serverId,
                serverName || serverId,
                usageControl
              )
            )
          )
          const createdTools = createdToolsResults
            .filter((result) => result.status === 'fulfilled')
            .map((result) => result.value)
            .filter(Boolean)

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

@waleedlatif1 waleedlatif1 merged commit c6e147e into staging Feb 26, 2026
12 checks passed
@waleedlatif1 waleedlatif1 deleted the waleedlatif1/mcp-server-tools branch February 26, 2026 23:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant