Skip to content

invalidate cache mcp servers page#1660

Merged
omar-inkeep merged 2 commits intomainfrom
invalidate-cache-mcp-servers-page
Jan 30, 2026
Merged

invalidate cache mcp servers page#1660
omar-inkeep merged 2 commits intomainfrom
invalidate-cache-mcp-servers-page

Conversation

@omar-inkeep
Copy link
Contributor

PRD-5941

@changeset-bot
Copy link

changeset-bot bot commented Jan 30, 2026

🦋 Changeset detected

Latest commit: b2700e8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages
Name Type
@inkeep/agents-manage-ui Patch
@inkeep/agents-api Patch
@inkeep/agents-cli Patch
@inkeep/agents-core Patch
@inkeep/agents-manage-mcp Patch
@inkeep/agents-mcp Patch
@inkeep/agents-sdk Patch
@inkeep/ai-sdk-provider Patch
@inkeep/create-agents Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Jan 30, 2026

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

Project Deployment Actions Updated (UTC)
agents-api Ready Ready Preview, Comment Jan 30, 2026 9:02pm
agents-docs Ready Ready Preview, Comment Jan 30, 2026 9:02pm
agents-manage-ui Ready Ready Preview, Comment Jan 30, 2026 9:02pm

Request Review

@vercel vercel bot temporarily deployed to Preview – agents-docs January 30, 2026 20:33 Inactive
@claude
Copy link
Contributor

claude bot commented Jan 30, 2026

Claude finished @omar-inkeep's task —— View job


Code Review: MCP Server Cache Invalidation

I've completed a comprehensive review of this PR that implements cache invalidation for the MCP servers page. Here are my findings:

Summary

This PR implements proper cache invalidation patterns for MCP server operations by:

  1. Adding a new useMcpToolInvalidation hook for React Query cache invalidation
  2. Updating the MCP server form to call cache invalidation after mutations
  3. Keeping existing revalidatePath calls in server actions for Next.js App Router cache

✅ Strengths

Architecture & Design

  • Hybrid Caching Strategy: Smart approach using both React Query (invalidateQueries) and Next.js (revalidatePath) for comprehensive cache invalidation
  • Consistent with Existing Patterns: Follows established patterns seen in projects.ts and other query files
  • Proper Separation of Concerns: Client-side query management separated from server-side path revalidation

Code Quality

  • Well-Structured Hook: useMcpToolInvalidation follows React Query best practices with proper memoization
  • Granular Invalidation: Supports both list invalidation and specific tool status invalidation
  • Error Handling: Maintains existing error handling patterns in form submission

🔍 Areas for Consideration

1. Missing Changeset ⚠️

As flagged by changeset-bot, this PR needs a changeset since it affects @inkeep/agents-manage-ui. Based on the repository guidelines:

pnpm bump patch --pkg agents-manage-ui "Improve cache invalidation for MCP servers page"

This appears to be a patch-level change as it's improving existing functionality without breaking changes.

2. Potential Race Conditions ⚠️

Lines 132, 182, 216, 228 in mcp-server-form.tsx

There's a potential race condition where cache invalidation happens before API operations complete:

// Current pattern - potential race condition
const result = await createToolAction(tenantId, projectId, mcpToolData);
await invalidateMcpToolCache(); // Could execute before server state settles

Recommendation: Consider adding a small delay or ensuring server-side revalidation completes first:

const result = await createToolAction(tenantId, projectId, mcpToolData);
// revalidatePath happens in createToolAction, give it time to propagate
await new Promise(resolve => setTimeout(resolve, 100));
await invalidateMcpToolCache();

3. Testing Coverage ⚠️

According to repository guidelines, all new features require unit tests. This functionality should have tests covering:

  • Cache invalidation hook behavior
  • Form submission with cache invalidation
  • Error scenarios during invalidation

Missing: __tests__/mcp-server-form.test.tsx and __tests__/mcp-tools-query.test.tsx

4. Performance Consideration ℹ️

Lines 49-51 in mcp-tools.ts

The invalidation pattern invalidates the entire list query even for single tool updates:

await queryClient.invalidateQueries({
  queryKey: mcpToolQueryKeys.list(tenantId, projectId),
});

Consideration: For large tool lists, this could cause unnecessary refetches. Consider more granular updates using setQueryData for single tool mutations.

5. Consistency Check ℹ️

Line 87 in mcp-server-form.tsx

The hook is called within the component but could be moved to the same pattern used in other query files where invalidation is returned as a function.

Compare with projects.ts:62-65:

export function useProjectInvalidation(tenantId: string) {
  const queryClient = useQueryClient();
  return async () => {
    await queryClient.invalidateQueries({ queryKey: projectQueryKeys.list(tenantId) });
  };
}

6. Documentation ⚠️

Based on repository requirements, new features need documentation. Consider updating relevant docs about:

  • MCP server management workflow
  • Cache behavior for users
  • Developer guide for similar invalidation patterns

🎯 System Design Considerations

Surface Area Analysis

This change affects:

  • UI Layer: Form interaction and state management
  • API Layer: Existing server actions (no breaking changes)
  • Cache Layer: Both React Query and Next.js caching

Future Extensibility

The pattern established here can be reused for other tool types and similar mutation scenarios. Consider extracting a generic useResourceInvalidation hook if this pattern repeats.

Auth/Security

No security implications - invalidation pattern doesn't affect data access controls.

🚀 Recommendation

This is a solid implementation that follows established patterns. Address the missing changeset immediately and consider the race condition fix before merging.

Priority Actions:

  1. High: Add required changeset
  2. Medium: Add tests for new functionality
  3. Low: Consider race condition mitigation

The cache invalidation strategy is architecturally sound and will improve user experience by ensuring fresh data after mutations.


@omar-inkeep omar-inkeep merged commit f23d445 into main Jan 30, 2026
7 of 8 checks passed
@omar-inkeep omar-inkeep deleted the invalidate-cache-mcp-servers-page branch January 30, 2026 21:28
anubra266 pushed a commit that referenced this pull request Feb 4, 2026
* invalidate cache mcp servers page

* changeset
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