LearnNewsExamplesServices
Frontmatter
id8104
title[MCP] Harden HealthServices with Request Deduplication
stateClosed
labels
enhancementai
assigneestobiu
createdAtDec 13, 2025, 2:15 PM
updatedAtDec 13, 2025, 2:25 PM
githubUrlhttps://github.com/neomjs/neo/issues/8104
authortobiu
commentsCount1
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtDec 13, 2025, 2:25 PM

[MCP] Harden HealthServices with Request Deduplication

Closed v11.17.0 enhancementai
tobiu
tobiu commented on Dec 13, 2025, 2:15 PM

Objective

Implement request deduplication (in-flight promise caching) in the HealthService for both memory-core and knowledge-base MCP servers.

Description

To prevent "thundering herd" race conditions where multiple concurrent callers (e.g., Server initialization and Service initialization) trigger parallel, redundant health checks during startup, we need to cache the pending health check promise. This pattern was successfully implemented in the github-workflow server and should be standardized across all MCP servers.

Implementation Details

For both:

  • ai/mcp/server/memory-core/services/HealthService.mjs
  • ai/mcp/server/knowledge-base/services/HealthService.mjs
  1. Add a private field #healthCheckPromise = null;.
  2. Update healthcheck() method:
    • Check if #healthCheckPromise exists. If so, return it.
    • If not, assign this.#performHealthCheck().finally(...) to it.
    • Ensure the promise is cleared (set to null) in the finally block.
tobiu added the enhancement label on Dec 13, 2025, 2:15 PM
tobiu added the ai label on Dec 13, 2025, 2:15 PM
tobiu assigned to @tobiu on Dec 13, 2025, 2:24 PM
tobiu referenced in commit 6eaf60c - "[MCP] Harden HealthServices with Request Deduplication #8104" on Dec 13, 2025, 2:24 PM
tobiu
tobiu Dec 13, 2025, 2:25 PM

Input from gemini:

✦ I have implemented request deduplication in the HealthService for both memory-core and knowledge-base.

Changes:

  1. Memory Core (ai/mcp/server/memory-core/services/HealthService.mjs):

    • Added #healthCheckPromise private field.
    • Updated healthcheck() to return await this.#healthCheckPromise if a check is already in progress, ensuring the existing error handling wrapper is respected.
    • Ensured the promise is cleared in a finally block.
  2. Knowledge Base (ai/mcp/server/knowledge-base/services/HealthService.mjs):

    • Added #healthCheckPromise private field.
    • Updated healthcheck() to return this.#healthCheckPromise if a check is already in progress.
    • Ensured the promise is cleared in a finally block.

This prevents race conditions during startup where multiple services could trigger redundant health checks simultaneously.

tobiu closed this issue on Dec 13, 2025, 2:25 PM