@l10nmonster/mcp 3.1.0 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/interfaces.d.ts +77 -0
- package/package.json +30 -29
- package/server.js +6 -19
- package/tools/mcpTool.js +1 -3
- package/tsconfig.json +18 -0
- package/.releaserc.json +0 -31
- package/tests/integration.test.js +0 -215
- package/tests/mcpToolValidation.test.js +0 -949
- package/tests/registry.test.js +0 -169
package/tests/registry.test.js
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import { describe, it, beforeEach } from 'node:test';
|
|
2
|
-
import assert from 'node:assert';
|
|
3
|
-
import { registry } from '../tools/registry.js';
|
|
4
|
-
import { McpTool } from '../tools/mcpTool.js';
|
|
5
|
-
import { z } from 'zod';
|
|
6
|
-
|
|
7
|
-
// Mock tool classes for testing
|
|
8
|
-
class TestTool1 extends McpTool {
|
|
9
|
-
static metadata = {
|
|
10
|
-
name: 'test_tool_1',
|
|
11
|
-
description: 'Test tool 1',
|
|
12
|
-
inputSchema: z.object({})
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
static async execute() {
|
|
16
|
-
return { result: 'test1' };
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
static handler() {
|
|
20
|
-
return async () => this.formatResult({ result: 'test1' });
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
class TestTool2 extends McpTool {
|
|
25
|
-
static metadata = {
|
|
26
|
-
name: 'test_tool_2',
|
|
27
|
-
description: 'Test tool 2',
|
|
28
|
-
inputSchema: z.object({})
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
static async execute() {
|
|
32
|
-
return { result: 'test2' };
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
static handler() {
|
|
36
|
-
return async () => this.formatResult({ result: 'test2' });
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
class OverrideTool extends McpTool {
|
|
41
|
-
static metadata = {
|
|
42
|
-
name: 'test_tool_1', // Same name as TestTool1
|
|
43
|
-
description: 'Override tool',
|
|
44
|
-
inputSchema: z.object({})
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
static async execute() {
|
|
48
|
-
return { result: 'override' };
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
static handler() {
|
|
52
|
-
return async () => this.formatResult({ result: 'override' });
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
describe('MCP Registry', () => {
|
|
57
|
-
beforeEach(() => {
|
|
58
|
-
// Clear registry before each test
|
|
59
|
-
registry.clear();
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('should register a single tool', () => {
|
|
63
|
-
registry.registerTool(TestTool1);
|
|
64
|
-
|
|
65
|
-
assert.strictEqual(registry.hasTool('test_tool_1'), true);
|
|
66
|
-
assert.strictEqual(registry.getTool('test_tool_1'), TestTool1);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('should register multiple tools', () => {
|
|
70
|
-
registry.registerTools([TestTool1, TestTool2]);
|
|
71
|
-
|
|
72
|
-
assert.strictEqual(registry.hasTool('test_tool_1'), true);
|
|
73
|
-
assert.strictEqual(registry.hasTool('test_tool_2'), true);
|
|
74
|
-
|
|
75
|
-
const allTools = registry.getAllTools();
|
|
76
|
-
assert.strictEqual(allTools.length, 2);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('should override existing tool with same name', () => {
|
|
80
|
-
registry.registerTool(TestTool1);
|
|
81
|
-
registry.registerTool(OverrideTool);
|
|
82
|
-
|
|
83
|
-
const tool = registry.getTool('test_tool_1');
|
|
84
|
-
assert.strictEqual(tool, OverrideTool);
|
|
85
|
-
assert.notStrictEqual(tool, TestTool1);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('should return all registered tools', () => {
|
|
89
|
-
registry.registerTools([TestTool1, TestTool2]);
|
|
90
|
-
|
|
91
|
-
const allTools = registry.getAllTools();
|
|
92
|
-
assert.strictEqual(allTools.length, 2);
|
|
93
|
-
assert.ok(allTools.includes(TestTool1));
|
|
94
|
-
assert.ok(allTools.includes(TestTool2));
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('should return undefined for non-existent tool', () => {
|
|
98
|
-
const tool = registry.getTool('non_existent');
|
|
99
|
-
assert.strictEqual(tool, undefined);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('should return false for non-existent tool check', () => {
|
|
103
|
-
assert.strictEqual(registry.hasTool('non_existent'), false);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('should clear all registered tools', () => {
|
|
107
|
-
registry.registerTools([TestTool1, TestTool2]);
|
|
108
|
-
assert.strictEqual(registry.getAllTools().length, 2);
|
|
109
|
-
|
|
110
|
-
registry.clear();
|
|
111
|
-
assert.strictEqual(registry.getAllTools().length, 0);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('should throw error for invalid tool class', () => {
|
|
115
|
-
assert.throws(
|
|
116
|
-
() => registry.registerTool(null),
|
|
117
|
-
/ToolClass must be a class\/function/
|
|
118
|
-
);
|
|
119
|
-
|
|
120
|
-
assert.throws(
|
|
121
|
-
() => registry.registerTool('not a class'),
|
|
122
|
-
/ToolClass must be a class\/function/
|
|
123
|
-
);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it('should throw error for tool without metadata', () => {
|
|
127
|
-
class InvalidTool {}
|
|
128
|
-
|
|
129
|
-
assert.throws(
|
|
130
|
-
() => registry.registerTool(InvalidTool),
|
|
131
|
-
/must have static metadata property/
|
|
132
|
-
);
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it('should throw error for tool without name in metadata', () => {
|
|
136
|
-
class InvalidTool {
|
|
137
|
-
static metadata = {
|
|
138
|
-
description: 'No name'
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
assert.throws(
|
|
143
|
-
() => registry.registerTool(InvalidTool),
|
|
144
|
-
/metadata must have a string 'name' property/
|
|
145
|
-
);
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
it('should throw error for tool without handler method', () => {
|
|
149
|
-
class InvalidTool {
|
|
150
|
-
static metadata = {
|
|
151
|
-
name: 'invalid',
|
|
152
|
-
description: 'No handler'
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
assert.throws(
|
|
157
|
-
() => registry.registerTool(InvalidTool),
|
|
158
|
-
/must have static handler method/
|
|
159
|
-
);
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
it('should throw error when registerTools receives non-array', () => {
|
|
163
|
-
assert.throws(
|
|
164
|
-
() => registry.registerTools('not an array'),
|
|
165
|
-
/toolClasses must be an array/
|
|
166
|
-
);
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
|