-
Notifications
You must be signed in to change notification settings - Fork 3.2k
improvement(mcp): restructure mcp tools caching/fetching info to improve UX #2416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Greptile SummaryRestructured MCP tools caching and validation to significantly improve UX and performance. The changes introduce a robust two-tier caching system (Redis with in-memory fallback), event-driven tool discovery, and comprehensive tool validation with visual status indicators. Key improvements:
Architecture: Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant UI as Tool Input UI
participant Modal as MCP Settings Modal
participant Query as React Query
participant API as API Routes
participant Service as MCP Service
participant Cache as Redis/Memory Cache
participant DB as Database
participant MCP as MCP Server
Note over User,MCP: Page Load - Tool Discovery
User->>UI: Open workflow editor
UI->>Query: useMcpToolsQuery(workspaceId)
Query->>API: GET /api/mcp/tools/discover
API->>Service: discoverTools(userId, workspaceId)
Service->>Cache: get(workspace:id)
alt Cache Hit
Cache-->>Service: Return cached tools
Service-->>API: Return tools
else Cache Miss
Service->>DB: Get enabled servers
DB-->>Service: Server configs
Service->>MCP: List tools (parallel)
MCP-->>Service: Tool schemas
Service->>DB: Update server status
Service->>Cache: set(workspace:id, tools, 5min)
Service-->>API: Return discovered tools
end
API-->>Query: Tools data
Query->>UI: Render available tools
Note over User,MCP: Server Creation - Force Refresh
User->>Modal: Add new MCP server
Modal->>API: POST /api/mcp/servers
API->>DB: Create server record
API->>Service: clearCache(workspaceId)
Service->>Cache: delete(workspace:id)
API-->>Modal: Server created
Modal->>Query: onSuccess - fetchMcpTools(forceRefresh=true)
Query->>API: GET /api/mcp/tools/discover?refresh=true
Note right of API: forceRefresh bypasses cache
API->>Service: discoverTools(forceRefresh=true)
Service->>MCP: List tools
MCP-->>Service: Fresh tool data
Service->>Cache: Update cache
Service-->>API: Fresh tools
API-->>Query: setQueryData(tools)
Query-->>Modal: Tools updated
Note over User,MCP: Tool Validation - UI Badges
UI->>Query: useMcpServers(workspaceId)
Query-->>UI: Server states
UI->>UI: getMcpToolIssue(stored tool)
Note right of UI: Compare stored vs current state
alt Server Disconnected/Error
UI->>UI: Show "unavailable" badge
UI->>UI: Filter from dropdown
else Schema/URL Changed
UI->>UI: Show "stale" badge
UI->>UI: Keep in dropdown
end
User->>UI: Click badge
UI->>Modal: openSettingsModal(serverId)
Modal->>Modal: Auto-select server
Note over User,MCP: Agent Execution - Filter Tools
User->>UI: Run workflow
UI->>API: Execute agent block
API->>Service: AgentHandler.execute()
Service->>DB: Check server connectionStatus
DB-->>Service: Server states
Service->>Service: filterUnavailableMcpTools()
Note right of Service: Remove tools from disconnected servers
Service->>MCP: Execute with filtered tools
MCP-->>Service: Results
Service-->>API: Agent output
API-->>UI: Display results
Note over User,MCP: Server Refresh - Status Tracking
User->>Modal: Click refresh button
Modal->>API: POST /api/mcp/servers/:id/refresh
API->>Service: discoverServerTools(serverId)
Service->>MCP: List tools
alt Connection Success
MCP-->>Service: Tools
Service->>DB: Update statusConfig {consecutiveFailures: 0}
Service->>Cache: clearCache(workspaceId)
else Connection Failed
MCP-->>Service: Error
Service->>DB: Increment statusConfig.consecutiveFailures
Note right of DB: Set to 'error' after 3 failures
end
Service-->>API: Status + tool count
API-->>Modal: Refresh complete
Modal->>Query: Invalidate & refetch
Query-->>Modal: Updated data
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
20 files reviewed, no comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additional Comments (1)
-
apps/sim/lib/mcp/service.ts, line 427-429 (link)logic: partial success caching - with failed servers, successfully fetched tools from working servers aren't cached, forcing re-discovery on next request even for working servers
31 files reviewed, 1 comment
Summary
Show "unavailable" badge when MCP tool's server is disconnected/error/missing or tool removed from server
Show "stale" badge when tool schema changed or server URL changed
Unavailable tools filtered from agent execution and dropdown
Issues shown in both agent tool input AND MCP settings modal
Filter unavailable/stale tools from reaching Agent
Fix caching bug that was causing discovery on every execution
Add Redis for Server side cache with in memory fallback
Event driven discovery of tools:
Type of Change
Testing
Tested manually
Checklist