Skip to content

Commit 7284f44

Browse files
committed
Refactor ToolService to Class-based Architecture #7950
1 parent 4ea7395 commit 7284f44

10 files changed

Lines changed: 538 additions & 391 deletions

File tree

.github/.sync-metadata.json

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"lastSync": "2025-11-30T13:51:57.333Z",
3-
"releasesLastFetched": "2025-11-30T13:51:57.955Z",
2+
"lastSync": "2025-11-30T14:38:33.349Z",
3+
"releasesLastFetched": "2025-11-30T14:38:33.969Z",
44
"pushFailures": [],
55
"issues": {
66
"3789": {
@@ -11691,7 +11691,7 @@
1169111691
"path": "/Users/Shared/github/neomjs/neo/.github/ISSUE/issue-7931.md",
1169211692
"closedAt": null,
1169311693
"updatedAt": "2025-11-29T17:34:45Z",
11694-
"contentHash": "f79b529dc1c6a0b595b50e60aef984246c1f46ad9ca10676a14b962c64478035"
11694+
"contentHash": "81c23ab6cbb3f402a3c5f8ce96449589a40acff253fb05acf50a4929da88368a"
1169511695
},
1169611696
"7932": {
1169711697
"state": "CLOSED",
@@ -11792,11 +11792,18 @@
1179211792
"contentHash": "30ce5869c2ffb1bcd3a60a637a87c7acf34703cad1fe64de1bfc16d81a90c3b8"
1179311793
},
1179411794
"7949": {
11795-
"state": "OPEN",
11795+
"state": "CLOSED",
1179611796
"path": "/Users/Shared/github/neomjs/neo/.github/ISSUE/issue-7949.md",
11797+
"closedAt": "2025-11-30T14:29:43Z",
11798+
"updatedAt": "2025-11-30T14:29:43Z",
11799+
"contentHash": "cffd7722f36230bd92736b89be8cd6a8fa80a6567eec7f649fab91f24568e7cc"
11800+
},
11801+
"7950": {
11802+
"state": "OPEN",
11803+
"path": "/Users/Shared/github/neomjs/neo/.github/ISSUE/issue-7950.md",
1179711804
"closedAt": null,
11798-
"updatedAt": "2025-11-30T13:51:10Z",
11799-
"contentHash": "7991e0b30ec1f1fef8d3531230a731d86170726b8db53f3dd0e709b0ac79c8f7"
11805+
"updatedAt": "2025-11-30T14:38:20Z",
11806+
"contentHash": "d9944dc381ccf85a71b3198c75995e06e820fd6c19f9ea2672d5c49604a4541b"
1180011807
}
1180111808
},
1180211809
"releases": {

.github/ISSUE/issue-7931.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ subIssues:
2525
- 7945
2626
- 7946
2727
- 7949
28-
subIssuesCompleted: 10
29-
subIssuesTotal: 11
28+
- 7950
29+
subIssuesCompleted: 11
30+
subIssuesTotal: 12
3031
blockedBy: []
3132
blocking: []
3233
---
@@ -72,4 +73,5 @@ To achieve true decoupling and enable agents to use *any* MCP server (not just o
7273
- 2025-11-30 @tobiu added sub-issue #7946
7374
- 2025-11-30 @tobiu cross-referenced by #7947
7475
- 2025-11-30 @tobiu added sub-issue #7949
76+
- 2025-11-30 @tobiu added sub-issue #7950
7577

.github/ISSUE/issue-7949.md

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
---
22
id: 7949
33
title: Refactor Shared Tool Validation Service for MCP Client and Server
4-
state: OPEN
4+
state: CLOSED
55
labels:
66
- enhancement
77
- ai
88
- refactoring
99
assignees:
1010
- tobiu
1111
createdAt: '2025-11-30T13:50:46Z'
12-
updatedAt: '2025-11-30T13:51:10Z'
12+
updatedAt: '2025-11-30T14:29:43Z'
1313
githubUrl: 'https://github.com/neomjs/neo/issues/7949'
1414
author: tobiu
15-
commentsCount: 0
15+
commentsCount: 1
1616
parentIssue: 7931
1717
subIssues: []
1818
subIssuesCompleted: 0
1919
subIssuesTotal: 0
2020
blockedBy: []
2121
blocking: []
22+
closedAt: '2025-11-30T14:29:43Z'
2223
---
2324
# Refactor Shared Tool Validation Service for MCP Client and Server
2425

@@ -41,11 +42,38 @@ Refactor `ai/mcp/server/toolService.mjs` to be a shared resource for both Client
4142
- Updated `Client.mjs` and Server implementations.
4243

4344

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+
4469
## Activity Log
4570

4671
- 2025-11-30 @tobiu added the `enhancement` label
4772
- 2025-11-30 @tobiu added the `ai` label
4873
- 2025-11-30 @tobiu added the `refactoring` label
4974
- 2025-11-30 @tobiu assigned to @tobiu
5075
- 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"
77+
- 2025-11-30 @tobiu closed this issue
78+
- 2025-11-30 @tobiu cross-referenced by #7950
5179

.github/ISSUE/issue-7950.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
id: 7950
3+
title: Refactor ToolService to Class-based Architecture
4+
state: OPEN
5+
labels:
6+
- enhancement
7+
- ai
8+
- refactoring
9+
assignees: []
10+
createdAt: '2025-11-30T14:38:20Z'
11+
updatedAt: '2025-11-30T14:38:20Z'
12+
githubUrl: 'https://github.com/neomjs/neo/issues/7950'
13+
author: tobiu
14+
commentsCount: 0
15+
parentIssue: 7931
16+
subIssues: []
17+
subIssuesCompleted: 0
18+
subIssuesTotal: 0
19+
blockedBy: []
20+
blocking: []
21+
---
22+
# 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.
41+
42+
## Deliverables
43+
- `ai/mcp/ToolService.mjs` (Class-based).
44+
- Updated Servers and Client using the new class.
45+
46+
47+
## Activity Log
48+
49+
- 2025-11-30 @tobiu added the `enhancement` label
50+
- 2025-11-30 @tobiu added the `ai` label
51+
- 2025-11-30 @tobiu added the `refactoring` label
52+
- 2025-11-30 @tobiu added parent issue #7931
53+

ai/agents/mcp-demo-agent.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { fileURLToPath } from 'url';
2020
import dotenv from 'dotenv';
2121

2222
const __dirname = path.dirname(fileURLToPath(import.meta.url));
23-
dotenv.config({ path: path.resolve(__dirname, '../../.env') });
23+
dotenv.config({path: path.resolve(__dirname, '../../.env'), quiet: true});
2424

2525
async function run() {
2626
console.log('🤖 MCP Demo Agent Starting (via Neo.ai.Agent)...');
@@ -37,7 +37,6 @@ async function run() {
3737
console.log('✅ Agent ready (connected to servers).');
3838

3939
// Example: List tools from GitHub Workflow Server
40-
console.log('Agent Instance:', agent); // Log entire agent
4140
console.log('Agent Clients Direct Access:', agent.clients); // Log property access
4241
console.log('GitHub Client Exists:', !!agent.clients?.githubWorkflow); // Safe check
4342

0 commit comments

Comments
 (0)