LearnNewsExamplesServices
Frontmatter
id7949
titleRefactor Shared Tool Validation Service for MCP Client and Server
stateClosed
labels
enhancementairefactoring
assigneestobiu
createdAtNov 30, 2025, 2:50 PM
updatedAtNov 30, 2025, 3:29 PM
githubUrlhttps://github.com/neomjs/neo/issues/7949
authortobiu
commentsCount1
parentIssue7931
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtNov 30, 2025, 3:29 PM

Refactor Shared Tool Validation Service for MCP Client and Server

Closed v11.14.0 enhancementairefactoring
tobiu
tobiu commented on Nov 30, 2025, 2:50 PM

Context

We implemented basic client-side validation in #7946. However, the validation logic is currently fragmented. We want to unify it by moving the tool service to a shared location.

Goal

Refactor ai/mcp/server/toolService.mjs to be a shared resource for both Clients and Servers.

Requirements

  1. Relocate File: Move ai/mcp/server/toolService.mjs one folder level up (to ai/mcp/toolService.mjs) to allow shared access.
  2. Add validateToolInput(): Implement a shared method validateToolInput(toolName, args, schema) within the shared service.
  3. Refactor Client & Server: Update both Neo.ai.mcp.client.Client and the MCP Servers to import and use this shared service for validation.
  4. Server Type Strategy:
    • Implement a check to determine if the connected server is one of our internal servers (GitHub, Knowledge Base, Memory Core).
    • Ensure validation logic is applied appropriately for internal servers (using our shared logic). For external servers, we need to decide if we validate against the provided JSON schema or skip strict validation.

Deliverables

  • Shared ai/mcp/toolService.mjs.
  • Updated Client.mjs and Server implementations.
tobiu added the enhancement label on Nov 30, 2025, 2:50 PM
tobiu added the ai label on Nov 30, 2025, 2:50 PM
tobiu added the refactoring label on Nov 30, 2025, 2:50 PM
tobiu assigned to @tobiu on Nov 30, 2025, 2:51 PM
tobiu added parent issue #7931 on Nov 30, 2025, 2:51 PM
tobiu referenced in commit 4ea7395 - "Refactor Shared Tool Validation Service for MCP Client and Server #7949" on Nov 30, 2025, 3:28 PM
tobiu
tobiu Nov 30, 2025, 3:29 PM

Input from Gemini 2.5 pro:

✦ I have successfully completed the refactoring for issue #7949.

Achievements

  1. Shared Service: Relocated toolService.mjs to ai/mcp/toolService.mjs, making it accessible to both Server and Client components.
  2. Hybrid Validation: Implemented validateToolInput(toolName, args, schema) which supports:
    • Internal Zod Validation: Uses robust Zod schemas derived from openapi.yaml (when initialized, e.g., in Servers).
    • External JSON Schema Validation: Falls back to a lightweight JSON Schema validator (when Zod schemas are unavailable, e.g., in Clients connecting to external servers).
  3. Integration:
    • Updated Neo.ai.mcp.client.Client to use the shared validateToolInput.
    • Updated github-workflow, knowledge-base, and memory-core servers to use the shared service.

Future Work (Singleton Refactoring)

We identified that toolService.mjs is currently a singleton module. This prevents a single process (like an Agent) from initializing multiple internal server contexts (Zod schemas) simultaneously.

  • Current Impact: Client.mjs uses the JSON Schema fallback for validation, which is functional and safe.
  • Next Step: A follow-up ticket will be created to refactor toolService.mjs into a Class-based service to support multiple instances per process, enabling Zod validation on the Client side for multiple internal servers.

I am closing this ticket as the primary goal of sharing the validation logic and structure is complete.

tobiu closed this issue on Nov 30, 2025, 3:29 PM
tobiu cross-referenced by #7950 on Nov 30, 2025, 3:38 PM