Skip to content

Conversation

@Dumbris
Copy link
Contributor

@Dumbris Dumbris commented Jan 28, 2026

Summary

  • Fix stale index entries persisting after server removal/restart, causing "Tool not found" errors
  • Include tool description in hash so description-only changes from upstream servers are detected and re-indexed
  • Add orphan cleanup on startup to remove tools from servers no longer in config

Changes

Hash Functions (internal/hash/hash.go)

  • Added description parameter to ToolHash, ComputeToolHash, VerifyToolHash
  • Hash now includes description: sha256(serverName + toolName + description + schemaJSON)

Index Layer (internal/index/)

  • Added GetAllIndexedServerNames() method using MatchAll query with faceting
  • Added wrapper in manager and to IndexManager interface

Runtime (internal/runtime/lifecycle.go)

  • Implemented cleanupOrphanedIndexEntries() comparing indexed vs active servers
  • Called on startup in backgroundToolIndexing() before discovery delay

Tests

  • New internal/hash/hash_test.go with 14 test cases
  • Added 2 tests for GetAllIndexedServerNames in bleve_test.go
  • Added TestToolCacheInvalidation_DescriptionOnlyChange and TestToolCacheInvalidation_OrphanCleanup
  • Added E2E test TestE2E_ServerDeleteReaddDifferentTools validating full lifecycle

Test plan

  • go test ./internal/hash/... -v - 14 tests pass
  • go test ./internal/index/... -v - 7 tests pass
  • go test ./internal/runtime/... -v - All tests pass
  • go test ./internal/appctx/... -v - 7 contract tests pass
  • go test ./internal/server/... -run TestE2E_ServerDeleteReaddDifferentTools - E2E pass
  • go test -race ./internal/... - No races
  • ./scripts/run-linter.sh - 0 issues

🤖 Generated with Claude Code

This fixes two related issues:

1. Stale index entries: When a server is removed/reconfigured or mcpproxy
   restarts, old tool entries persisted in the Bleve index on disk. Users
   would find tools via search that no longer exist, leading to "Tool not
   found" errors.

2. Description changes not detected: The tool hash (sha256) omitted
   description, so description-only changes from upstream servers were
   never re-indexed.

Changes:
- Add description parameter to ToolHash, ComputeToolHash, VerifyToolHash
- Include description in hash: sha256(server + tool + description + schema)
- Add GetAllIndexedServerNames() to query unique servers in the index
- Implement cleanupOrphanedIndexEntries() to remove stale entries on startup
- Add comprehensive unit tests for hash, index, and runtime
- Add E2E test validating server delete + re-add with different tools

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jan 28, 2026

Deploying mcpproxy-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 848a967
Status: ✅  Deploy successful!
Preview URL: https://df94c471.mcpproxy-docs.pages.dev
Branch Preview URL: https://fix-stale-tool-index-cleanup.mcpproxy-docs.pages.dev

View logs

@github-actions
Copy link

github-actions bot commented Jan 28, 2026

📦 Build Artifacts

Workflow Run: View Run
Branch: fix/stale-tool-index-cleanup

Available Artifacts

  • archive-darwin-amd64 (23 MB)
  • archive-darwin-arm64 (21 MB)
  • archive-linux-amd64 (12 MB)
  • archive-linux-arm64 (11 MB)
  • archive-windows-amd64 (23 MB)
  • archive-windows-arm64 (20 MB)
  • frontend-dist-pr (0 MB)
  • installer-dmg-darwin-amd64 (26 MB)
  • installer-dmg-darwin-arm64 (23 MB)

How to Download

Option 1: GitHub Web UI (easiest)

  1. Go to the workflow run page linked above
  2. Scroll to the bottom "Artifacts" section
  3. Click on the artifact you want to download

Option 2: GitHub CLI

gh run download 21445780143 --repo smart-mcp-proxy/mcpproxy-go

Note: Artifacts expire in 14 days.

The TestE2E_ServerDeleteReaddDifferentTools test exercises the server
add/remove path aggressively, triggering a pre-existing race condition
in internal/upstream/managed/client.go where onStateChange() reads
mc.Config.Name without holding the lock while SetConfig() writes to it.

Skip this test with the race detector until the underlying race in
managed/client.go is fixed separately.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@Dumbris Dumbris force-pushed the fix/stale-tool-index-cleanup branch from 1679d4b to 848a967 Compare January 28, 2026 16:08
@Dumbris Dumbris merged commit cfe9276 into main Jan 29, 2026
23 checks passed
@Dumbris Dumbris deleted the fix/stale-tool-index-cleanup branch January 29, 2026 06:03
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.

2 participants