You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Refactor Shared Tool Validation Service for MCP Client and Server
24
25
@@ -41,11 +42,38 @@ Refactor `ai/mcp/server/toolService.mjs` to be a shared resource for both Client
41
42
- Updated `Client.mjs` and Server implementations.
42
43
43
44
45
+
## Comments
46
+
47
+
### @tobiu - 2025-11-30 14:29
48
+
49
+
**Input from Gemini 2.5 pro:**
50
+
51
+
> ✦ I have successfully completed the refactoring for issue #7949.
52
+
>
53
+
> ### Achievements
54
+
> 1.**Shared Service:** Relocated `toolService.mjs` to `ai/mcp/toolService.mjs`, making it accessible to both Server and Client components.
55
+
> 2.**Hybrid Validation:** Implemented `validateToolInput(toolName, args, schema)` which supports:
56
+
> ***Internal Zod Validation:** Uses robust Zod schemas derived from `openapi.yaml` (when initialized, e.g., in Servers).
57
+
> ***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).
58
+
> 3.**Integration:**
59
+
> * Updated `Neo.ai.mcp.client.Client` to use the shared `validateToolInput`.
60
+
> * Updated `github-workflow`, `knowledge-base`, and `memory-core` servers to use the shared service.
61
+
>
62
+
> ### Future Work (Singleton Refactoring)
63
+
> 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.
64
+
> ***Current Impact:**`Client.mjs` uses the JSON Schema fallback for validation, which is functional and safe.
65
+
> ***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.
66
+
>
67
+
> I am closing this ticket as the primary goal of sharing the validation logic and structure is complete.
68
+
44
69
## Activity Log
45
70
46
71
- 2025-11-30 @tobiu added the `enhancement` label
47
72
- 2025-11-30 @tobiu added the `ai` label
48
73
- 2025-11-30 @tobiu added the `refactoring` label
49
74
- 2025-11-30 @tobiu assigned to @tobiu
50
75
- 2025-11-30 @tobiu added parent issue #7931
76
+
- 2025-11-30 @tobiu referenced in commit `4ea7395` - "Refactor Shared Tool Validation Service for MCP Client and Server #7949"
# Refactor ToolService to Class-based Architecture
23
+
24
+
## Context
25
+
In #7949, we moved `toolService.mjs` to a shared location to support client-side validation. However, the service remains a singleton module with module-level state (`toolMapping`). This prevents a single process (like an Agent) from initializing multiple internal server contexts (Zod schemas) simultaneously, as subsequent initializations overwrite the global state.
26
+
27
+
## Goal
28
+
Refactor `ai/mcp/toolService.mjs` into a class-based `Neo.ai.mcp.ToolService` extending `Neo.core.Base`. This allows each Server or Client connection to maintain its own independent tool registry and validation context.
29
+
30
+
## Requirements
31
+
1.**Rename & Refactor:** Rename `ai/mcp/toolService.mjs` to `ai/mcp/ToolService.mjs`. Convert it to export a `ToolService` class extending `Neo.core.Base`.
32
+
2.**Configuration:**
33
+
*`openApiFilePath`: Define as a non-reactive config (no trailing underscore) to allow prototype or instance-level overrides.
34
+
3.**Class Fields:**
35
+
*`serviceMapping`: Define as a class field.
36
+
*`toolMapping` & `allToolsForListing`: Define as instance properties (lazy-loaded state).
37
+
4.**Server Update:** Update all MCP Servers (`github-workflow`, `knowledge-base`, `memory-core`) to instantiate `new ToolService({ serviceMapping, openApiFilePath })` (or similar config pattern) in their local service wrappers.
38
+
5.**Client Update:** Update `Neo.ai.mcp.client.Client` to:
39
+
* Instantiate a `ToolService` for each connection.
40
+
* Pass the `openApiFilePath` (retrieved from config) to the `ToolService` if available, enabling robust Zod validation for internal servers.
0 commit comments