@fgv/ts-extras-mcp 5.1.0-47 → 5.1.0-49

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.
Files changed (56) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +19 -9
  3. package/.rush/temp/1ef6da5e025cb1b91fb9dacea403fcf68d03a476.tar.log +0 -90
  4. package/.rush/temp/chunked-rush-logs/ts-extras-mcp.build.chunks.jsonl +0 -9
  5. package/.rush/temp/operation/build/all.log +0 -9
  6. package/.rush/temp/operation/build/log-chunks.jsonl +0 -9
  7. package/.rush/temp/operation/build/state.json +0 -3
  8. package/.rush/temp/shrinkwrap-deps.json +0 -735
  9. package/config/api-extractor.json +0 -38
  10. package/config/jest.config.json +0 -13
  11. package/config/rig.json +0 -6
  12. package/dist/test/unit/endToEnd.test.js +0 -220
  13. package/dist/test/unit/endToEnd.test.js.map +0 -1
  14. package/dist/test/unit/index.test.js +0 -41
  15. package/dist/test/unit/index.test.js.map +0 -1
  16. package/dist/test/unit/mcp.test.js +0 -494
  17. package/dist/test/unit/mcp.test.js.map +0 -1
  18. package/dist/test/unit/sdk.test.js +0 -68
  19. package/dist/test/unit/sdk.test.js.map +0 -1
  20. package/eslint.config.js +0 -15
  21. package/etc/ts-extras-mcp.api.md +0 -114
  22. package/lib/test/unit/endToEnd.test.d.ts +0 -13
  23. package/lib/test/unit/endToEnd.test.d.ts.map +0 -1
  24. package/lib/test/unit/endToEnd.test.js +0 -222
  25. package/lib/test/unit/endToEnd.test.js.map +0 -1
  26. package/lib/test/unit/index.test.d.ts +0 -2
  27. package/lib/test/unit/index.test.d.ts.map +0 -1
  28. package/lib/test/unit/index.test.js +0 -76
  29. package/lib/test/unit/index.test.js.map +0 -1
  30. package/lib/test/unit/mcp.test.d.ts +0 -2
  31. package/lib/test/unit/mcp.test.d.ts.map +0 -1
  32. package/lib/test/unit/mcp.test.js +0 -529
  33. package/lib/test/unit/mcp.test.js.map +0 -1
  34. package/lib/test/unit/sdk.test.d.ts +0 -2
  35. package/lib/test/unit/sdk.test.d.ts.map +0 -1
  36. package/lib/test/unit/sdk.test.js +0 -70
  37. package/lib/test/unit/sdk.test.js.map +0 -1
  38. package/rush-logs/ts-extras-mcp.build.cache.log +0 -3
  39. package/rush-logs/ts-extras-mcp.build.log +0 -9
  40. package/src/index.ts +0 -50
  41. package/src/packlets/mcp/adapter.ts +0 -155
  42. package/src/packlets/mcp/index.ts +0 -34
  43. package/src/packlets/mcp/model.ts +0 -235
  44. package/src/packlets/mcp/operations.ts +0 -181
  45. package/src/packlets/mcp/sdk.ts +0 -154
  46. package/src/packlets/mcp/session.ts +0 -137
  47. package/src/packlets/mcp/transports.ts +0 -111
  48. package/src/test/unit/endToEnd.test.ts +0 -254
  49. package/src/test/unit/index.test.ts +0 -43
  50. package/src/test/unit/mcp.test.ts +0 -601
  51. package/src/test/unit/sdk.test.ts +0 -73
  52. package/temp/build/lint/_eslint-5eVG3S6w.json +0 -54
  53. package/temp/build/typescript/ts_8nwakTlr.json +0 -1
  54. package/temp/ts-extras-mcp.api.json +0 -1843
  55. package/temp/ts-extras-mcp.api.md +0 -114
  56. package/tsconfig.json +0 -12
@@ -1,494 +0,0 @@
1
- /*
2
- * Copyright (c) 2026 Erik Fortune
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in all
12
- * copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- * SOFTWARE.
21
- */
22
- // Mock the SDK-isolation seam so no live MCP server / subprocess is required. The factories
23
- // return controllable fakes; `makeClient` is configured per-test. The jest.mock call must
24
- // precede the regular imports (hoist-jest-mock).
25
- jest.mock('../../packlets/mcp/sdk', () => ({
26
- makeClient: jest.fn(),
27
- makeStdioTransport: jest.fn(() => ({ sentinel: 'stdio' })),
28
- makeHttpTransport: jest.fn(() => ({ sentinel: 'http' }))
29
- }));
30
- import '@fgv/ts-utils-jest';
31
- import { Logging } from '@fgv/ts-utils';
32
- // eslint-disable-next-line @rushstack/packlets/mechanics
33
- import * as sdk from '../../packlets/mcp/sdk';
34
- import { adaptMcpTools, callMcpTool, closeMcpSession, connectMcpSession, createHttpTransport, createStdioTransport, listMcpTools } from '../../packlets/mcp';
35
- const mockSdk = sdk;
36
- function makeFakeClient(overrides = {}) {
37
- return Object.assign({ connect: jest.fn(async () => undefined), getServerVersion: jest.fn(() => ({ name: 'fake-server', version: '1.2.3' })), listTools: jest.fn(async () => ({ tools: [] })), callTool: jest.fn(async () => ({ content: [] })), close: jest.fn(async () => undefined) }, overrides);
38
- }
39
- /** Connect a session backed by the given fake client (and a stdio transport). */
40
- async function connectWith(fake) {
41
- mockSdk.makeClient.mockReturnValueOnce(fake);
42
- const transport = createStdioTransport({ command: 'node' }).orThrow();
43
- return (await connectMcpSession({ transport })).orThrow();
44
- }
45
- /** A foreign (non-package) handle, to exercise the loud narrowing-failure paths. */
46
- const FOREIGN_TRANSPORT = { transportKind: 'stdio' };
47
- const FOREIGN_SESSION = {
48
- clientName: 'x',
49
- clientVersion: 'y',
50
- serverInfo: undefined
51
- };
52
- beforeEach(() => {
53
- jest.clearAllMocks();
54
- mockSdk.makeStdioTransport.mockReturnValue({ sentinel: 'stdio' });
55
- mockSdk.makeHttpTransport.mockReturnValue({ sentinel: 'http' });
56
- });
57
- // ===========================================================================
58
- // Transports
59
- // ===========================================================================
60
- describe('createStdioTransport', () => {
61
- test('succeeds for a valid command', () => {
62
- expect(createStdioTransport({ command: 'node', args: ['x'] })).toSucceedAndSatisfy((t) => {
63
- expect(t.transportKind).toBe('stdio');
64
- });
65
- expect(mockSdk.makeStdioTransport).toHaveBeenCalledWith(expect.objectContaining({ command: 'node', args: ['x'] }));
66
- });
67
- test('fails for an empty/whitespace command', () => {
68
- expect(createStdioTransport({ command: '' })).toFailWith(/command must be a non-empty string/);
69
- expect(createStdioTransport({ command: ' ' })).toFailWith(/command must be a non-empty string/);
70
- });
71
- test('fails (Result) when the SDK constructor throws', () => {
72
- mockSdk.makeStdioTransport.mockImplementationOnce(() => {
73
- throw new Error('spawn boom');
74
- });
75
- expect(createStdioTransport({ command: 'node' })).toFailWith(/createStdioTransport:.*spawn boom/);
76
- });
77
- });
78
- describe('createHttpTransport', () => {
79
- test('succeeds for http and https urls and forwards headers', () => {
80
- expect(createHttpTransport({ url: 'http://localhost:9000/mcp' })).toSucceedAndSatisfy((t) => {
81
- expect(t.transportKind).toBe('http');
82
- });
83
- expect(createHttpTransport({ url: 'https://example.com/mcp', headers: { authorization: 'Bearer t' } })).toSucceed();
84
- expect(mockSdk.makeHttpTransport).toHaveBeenCalledWith(expect.any(URL), { authorization: 'Bearer t' });
85
- });
86
- test('fails for an unparseable url', () => {
87
- expect(createHttpTransport({ url: 'not a url' })).toFailWith(/invalid url 'not a url'/);
88
- });
89
- test('fails for a non-http(s) protocol', () => {
90
- expect(createHttpTransport({ url: 'ftp://example.com' })).toFailWith(/must use http or https/);
91
- });
92
- test('fails (Result) when the SDK constructor throws', () => {
93
- mockSdk.makeHttpTransport.mockImplementationOnce(() => {
94
- throw new Error('http boom');
95
- });
96
- expect(createHttpTransport({ url: 'http://localhost' })).toFailWith(/createHttpTransport:.*http boom/);
97
- });
98
- });
99
- // ===========================================================================
100
- // Session lifecycle
101
- // ===========================================================================
102
- describe('connectMcpSession', () => {
103
- test('fails loudly for a foreign transport handle', async () => {
104
- expect(await connectMcpSession({ transport: FOREIGN_TRANSPORT })).toFailWith(/invalid MCP transport/);
105
- });
106
- test('connects and reports server identity, logging when a logger is supplied', async () => {
107
- const logger = new Logging.InMemoryLogger('all');
108
- const fake = makeFakeClient();
109
- mockSdk.makeClient.mockReturnValueOnce(fake);
110
- const transport = createStdioTransport({ command: 'node' }).orThrow();
111
- expect(await connectMcpSession({ transport, clientName: 'me', clientVersion: '0.0.1', logger })).toSucceedAndSatisfy((session) => {
112
- expect(session.clientName).toBe('me');
113
- expect(session.clientVersion).toBe('0.0.1');
114
- expect(session.serverInfo).toEqual({ name: 'fake-server', version: '1.2.3' });
115
- });
116
- expect(mockSdk.makeClient).toHaveBeenCalledWith('me', '0.0.1');
117
- expect(fake.connect).toHaveBeenCalledTimes(1);
118
- expect(logger.logged.join('\n')).toMatch(/connected to server fake-server@1.2.3/);
119
- });
120
- test('connects with default identity and no server info, no logger', async () => {
121
- const fake = makeFakeClient({ getServerVersion: jest.fn(() => undefined) });
122
- mockSdk.makeClient.mockReturnValueOnce(fake);
123
- const transport = createStdioTransport({ command: 'node' }).orThrow();
124
- expect(await connectMcpSession({ transport })).toSucceedAndSatisfy((session) => {
125
- expect(session.clientName).toBe('@fgv/ts-extras-mcp');
126
- expect(session.serverInfo).toBeUndefined();
127
- });
128
- });
129
- test('logs the no-identity case when a logger is supplied', async () => {
130
- const logger = new Logging.InMemoryLogger('all');
131
- const fake = makeFakeClient({ getServerVersion: jest.fn(() => undefined) });
132
- mockSdk.makeClient.mockReturnValueOnce(fake);
133
- const transport = createStdioTransport({ command: 'node' }).orThrow();
134
- expect(await connectMcpSession({ transport, logger })).toSucceed();
135
- expect(logger.logged.join('\n')).toMatch(/connected \(server did not report identity\)/);
136
- });
137
- test('fails when the connect handshake throws', async () => {
138
- const fake = makeFakeClient({
139
- connect: jest.fn(async () => {
140
- throw new Error('handshake refused');
141
- })
142
- });
143
- mockSdk.makeClient.mockReturnValueOnce(fake);
144
- const transport = createStdioTransport({ command: 'node' }).orThrow();
145
- expect(await connectMcpSession({ transport })).toFailWith(/connectMcpSession:.*handshake refused/);
146
- });
147
- });
148
- describe('closeMcpSession', () => {
149
- test('fails loudly for a foreign session handle', async () => {
150
- expect(await closeMcpSession(FOREIGN_SESSION)).toFailWith(/invalid MCP session/);
151
- });
152
- test('closes a connected session', async () => {
153
- const fake = makeFakeClient();
154
- const session = await connectWith(fake);
155
- expect(await closeMcpSession(session)).toSucceedWith(true);
156
- expect(fake.close).toHaveBeenCalledTimes(1);
157
- });
158
- test('fails when close throws', async () => {
159
- const fake = makeFakeClient({
160
- close: jest.fn(async () => {
161
- throw new Error('already closed');
162
- })
163
- });
164
- const session = await connectWith(fake);
165
- expect(await closeMcpSession(session)).toFailWith(/closeMcpSession:.*already closed/);
166
- });
167
- });
168
- // ===========================================================================
169
- // Tool discovery + invocation
170
- // ===========================================================================
171
- describe('listMcpTools', () => {
172
- test('fails loudly for a foreign session handle', async () => {
173
- expect(await listMcpTools(FOREIGN_SESSION)).toFailWith(/invalid MCP session/);
174
- });
175
- test('returns a single-page catalog', async () => {
176
- const fake = makeFakeClient({
177
- listTools: jest.fn(async () => ({
178
- tools: [{ name: 'a', description: 'tool a', inputSchema: { type: 'object' } }]
179
- }))
180
- });
181
- const session = await connectWith(fake);
182
- expect(await listMcpTools(session)).toSucceedAndSatisfy((tools) => {
183
- expect(tools).toHaveLength(1);
184
- expect(tools[0]).toEqual({ name: 'a', description: 'tool a', inputSchema: { type: 'object' } });
185
- });
186
- });
187
- test('follows nextCursor across pages', async () => {
188
- const listTools = jest
189
- .fn()
190
- .mockResolvedValueOnce({ tools: [{ name: 'a', inputSchema: { type: 'object' } }], nextCursor: 'p2' })
191
- .mockResolvedValueOnce({ tools: [{ name: 'b', inputSchema: { type: 'object' } }] });
192
- const fake = makeFakeClient({ listTools });
193
- const session = await connectWith(fake);
194
- expect(await listMcpTools(session)).toSucceedAndSatisfy((tools) => {
195
- expect(tools.map((t) => t.name)).toEqual(['a', 'b']);
196
- });
197
- expect(listTools).toHaveBeenNthCalledWith(1, undefined);
198
- expect(listTools).toHaveBeenNthCalledWith(2, { cursor: 'p2' });
199
- });
200
- test('coerces a missing/invalid inputSchema to null and a missing description to undefined', async () => {
201
- const fake = makeFakeClient({
202
- listTools: jest.fn(async () => ({ tools: [{ name: 'noschema' }] }))
203
- });
204
- const session = await connectWith(fake);
205
- expect(await listMcpTools(session)).toSucceedAndSatisfy((tools) => {
206
- expect(tools[0]).toEqual({ name: 'noschema', description: undefined, inputSchema: null });
207
- });
208
- });
209
- test('fails when listTools throws', async () => {
210
- const fake = makeFakeClient({
211
- listTools: jest.fn(async () => {
212
- throw new Error('protocol error');
213
- })
214
- });
215
- const session = await connectWith(fake);
216
- expect(await listMcpTools(session)).toFailWith(/listMcpTools:.*protocol error/);
217
- });
218
- });
219
- describe('callMcpTool', () => {
220
- const args = { q: 'hi' };
221
- test('fails loudly for a foreign session handle', async () => {
222
- expect(await callMcpTool(FOREIGN_SESSION, 'a', args)).toFailWith(/invalid MCP session/);
223
- });
224
- test('concatenates text blocks', async () => {
225
- const fake = makeFakeClient({
226
- callTool: jest.fn(async () => ({
227
- content: [
228
- { type: 'text', text: 'line one' },
229
- { type: 'text', text: 'line two' }
230
- ]
231
- }))
232
- });
233
- const session = await connectWith(fake);
234
- expect(await callMcpTool(session, 'a', args)).toSucceedWith({
235
- content: 'line one\nline two'
236
- });
237
- expect(fake.callTool).toHaveBeenCalledWith({ name: 'a', arguments: args });
238
- });
239
- test('summarizes non-text blocks', async () => {
240
- const fake = makeFakeClient({
241
- callTool: jest.fn(async () => ({
242
- content: [
243
- { type: 'text', text: 'caption' },
244
- { type: 'image', data: 'base64==' }
245
- ]
246
- }))
247
- });
248
- const session = await connectWith(fake);
249
- expect(await callMcpTool(session, 'a', args)).toSucceedWith({
250
- content: 'caption\n[image block]'
251
- });
252
- });
253
- test('projects an empty/absent content list to an empty string', async () => {
254
- const fake = makeFakeClient({ callTool: jest.fn(async () => ({})) });
255
- const session = await connectWith(fake);
256
- expect(await callMcpTool(session, 'a', args)).toSucceedWith({ content: '' });
257
- });
258
- test('maps isError:true to a Failure carrying the projected content', async () => {
259
- const fake = makeFakeClient({
260
- callTool: jest.fn(async () => ({ content: [{ type: 'text', text: 'bad input' }], isError: true }))
261
- });
262
- const session = await connectWith(fake);
263
- expect(await callMcpTool(session, 'a', args)).toFailWith(/^bad input$/);
264
- });
265
- test('maps isError:true with no content to a generic error', async () => {
266
- const fake = makeFakeClient({ callTool: jest.fn(async () => ({ isError: true })) });
267
- const session = await connectWith(fake);
268
- expect(await callMcpTool(session, 'broken', args)).toFailWith(/tool 'broken' reported an error/);
269
- });
270
- test('fails when callTool throws', async () => {
271
- const fake = makeFakeClient({
272
- callTool: jest.fn(async () => {
273
- throw new Error('timeout');
274
- })
275
- });
276
- const session = await connectWith(fake);
277
- expect(await callMcpTool(session, 'a', args)).toFailWith(/callMcpTool 'a':.*timeout/);
278
- });
279
- });
280
- // ===========================================================================
281
- // adaptMcpTools — the headline (Constraint 1)
282
- // ===========================================================================
283
- describe('adaptMcpTools', () => {
284
- const goodSchema = {
285
- type: 'object',
286
- properties: { q: { type: 'string' } },
287
- required: ['q']
288
- };
289
- // `pattern` is outside the JsonSchema.fromJson supported subset → fromJson fails with a pointer.
290
- const forbiddenSchema = {
291
- type: 'object',
292
- properties: { name: { type: 'string', pattern: '^a' } }
293
- };
294
- function mixedCatalogClient() {
295
- return makeFakeClient({
296
- listTools: jest.fn(async () => ({
297
- tools: [
298
- { name: 'good', description: 'a good tool', inputSchema: goodSchema },
299
- { name: 'forbidden', inputSchema: forbiddenSchema },
300
- { name: 'nonobject', description: 'bad', inputSchema: 'not-a-schema' }
301
- ]
302
- }))
303
- });
304
- }
305
- test('propagates a tool-discovery failure', async () => {
306
- const fake = makeFakeClient({
307
- listTools: jest.fn(async () => {
308
- throw new Error('discovery down');
309
- })
310
- });
311
- const session = await connectWith(fake);
312
- expect(await adaptMcpTools(session)).toFailWith(/adaptMcpTools:.*discovery down/);
313
- });
314
- test('adapts good tools and surfaces skipped tools structurally + NOISY warn', async () => {
315
- const logger = new Logging.InMemoryLogger('all');
316
- const session = await connectWith(mixedCatalogClient());
317
- expect(await adaptMcpTools(session, { logger })).toSucceedAndSatisfy((result) => {
318
- var _a, _b, _c, _d;
319
- expect(result.tools).toHaveLength(1);
320
- expect(result.tools[0].config.name).toBe('good');
321
- expect(result.tools[0].config.description).toBe('a good tool');
322
- expect(result.skipped).toHaveLength(2);
323
- const byName = new Map(result.skipped.map((s) => [s.name, s]));
324
- expect((_a = byName.get('forbidden')) === null || _a === void 0 ? void 0 : _a.reason).toMatch(/pattern/);
325
- expect((_b = byName.get('forbidden')) === null || _b === void 0 ? void 0 : _b.schema).toEqual(forbiddenSchema);
326
- expect((_c = byName.get('nonobject')) === null || _c === void 0 ? void 0 : _c.reason).toMatch(/not a JSON object/);
327
- expect((_d = byName.get('nonobject')) === null || _d === void 0 ? void 0 : _d.schema).toBe('not-a-schema');
328
- });
329
- // NOISY warn: tool name + pointer reason + the raw failing schema verbatim.
330
- const warned = logger.logged.join('\n');
331
- expect(warned).toMatch(/skipping tool 'forbidden'/);
332
- expect(warned).toMatch(/pattern/);
333
- expect(warned).toContain(JSON.stringify(forbiddenSchema));
334
- expect(warned).toMatch(/skipping tool 'nonobject'/);
335
- });
336
- test('surfaces skips structurally even without a logger', async () => {
337
- const session = await connectWith(mixedCatalogClient());
338
- expect(await adaptMcpTools(session)).toSucceedAndSatisfy((result) => {
339
- expect(result.tools).toHaveLength(1);
340
- expect(result.skipped).toHaveLength(2);
341
- });
342
- });
343
- test('falls back to the tool name when no description is provided', async () => {
344
- const fake = makeFakeClient({
345
- listTools: jest.fn(async () => ({ tools: [{ name: 'nodesc', inputSchema: goodSchema }] }))
346
- });
347
- const session = await connectWith(fake);
348
- expect(await adaptMcpTools(session)).toSucceedAndSatisfy((result) => {
349
- expect(result.tools[0].config.description).toBe('nodesc');
350
- });
351
- });
352
- describe('adapted tool execute', () => {
353
- async function adaptGood(callTool) {
354
- const fake = makeFakeClient({
355
- listTools: jest.fn(async () => ({ tools: [{ name: 'good', inputSchema: goodSchema }] })),
356
- callTool
357
- });
358
- const session = await connectWith(fake);
359
- const result = (await adaptMcpTools(session)).orThrow();
360
- return result.tools[0].execute;
361
- }
362
- test('forwards validated args to callMcpTool and returns the projected content', async () => {
363
- const callTool = jest.fn(async () => ({ content: [{ type: 'text', text: 'tool output' }] }));
364
- const execute = await adaptGood(callTool);
365
- expect(await execute({ q: 'hello' })).toSucceedWith('tool output');
366
- expect(callTool).toHaveBeenCalledWith({ name: 'good', arguments: { q: 'hello' } });
367
- });
368
- test('fails when the model supplies non-object arguments', async () => {
369
- const callTool = jest.fn();
370
- const execute = await adaptGood(callTool);
371
- expect(await execute('not-an-object')).toFailWith(/tool 'good': arguments must be a JSON object/);
372
- expect(callTool).not.toHaveBeenCalled();
373
- });
374
- test('propagates an MCP tool error as a Failure', async () => {
375
- const callTool = jest.fn(async () => ({ content: [{ type: 'text', text: 'denied' }], isError: true }));
376
- const execute = await adaptGood(callTool);
377
- expect(await execute({ q: 'hello' })).toFailWith(/denied/);
378
- });
379
- });
380
- // ==========================================================================
381
- // C2 — MCP Tool.annotations passthrough (normalized, never raw)
382
- // ==========================================================================
383
- describe('annotations passthrough (C2)', () => {
384
- const goodSchema2 = { type: 'object', properties: { q: { type: 'string' } }, required: ['q'] };
385
- test('all five hints round-trip onto descriptor.annotations and config.annotations', async () => {
386
- const annotations = {
387
- title: 'Recall Memory',
388
- readOnlyHint: true,
389
- destructiveHint: false,
390
- idempotentHint: true,
391
- openWorldHint: false
392
- };
393
- const fake = makeFakeClient({
394
- listTools: jest.fn(async () => ({
395
- tools: [{ name: 'recall', description: 'r', inputSchema: goodSchema2, annotations }]
396
- }))
397
- });
398
- const session = await connectWith(fake);
399
- expect(await listMcpTools(session)).toSucceedAndSatisfy((tools) => {
400
- expect(tools[0].annotations).toEqual(annotations);
401
- });
402
- const session2 = await connectWith(makeFakeClient({
403
- listTools: jest.fn(async () => ({
404
- tools: [{ name: 'recall', description: 'r', inputSchema: goodSchema2, annotations }]
405
- }))
406
- }));
407
- expect(await adaptMcpTools(session2)).toSucceedAndSatisfy((result) => {
408
- expect(result.tools[0].config.annotations).toEqual(annotations);
409
- });
410
- });
411
- test('a tool with no annotations leaves the field absent', async () => {
412
- const fake = makeFakeClient({
413
- listTools: jest.fn(async () => ({ tools: [{ name: 'plain', inputSchema: goodSchema2 }] }))
414
- });
415
- const session = await connectWith(fake);
416
- expect(await listMcpTools(session)).toSucceedAndSatisfy((tools) => {
417
- expect(tools[0]).not.toHaveProperty('annotations');
418
- });
419
- const session2 = await connectWith(makeFakeClient({
420
- listTools: jest.fn(async () => ({ tools: [{ name: 'plain', inputSchema: goodSchema2 }] }))
421
- }));
422
- expect(await adaptMcpTools(session2)).toSucceedAndSatisfy((result) => {
423
- expect(result.tools[0].config).not.toHaveProperty('annotations');
424
- });
425
- });
426
- test('a malformed annotations blob is normalized (known fields kept, junk dropped), never raw-propagated', async () => {
427
- // readOnlyHint is the wrong type (dropped); bogusField is unknown (dropped); title is valid (kept).
428
- const rawAnnotations = {
429
- title: 'Keep Me',
430
- readOnlyHint: 'yes-please',
431
- destructiveHint: true,
432
- bogusField: { nested: 42 }
433
- };
434
- const fake = makeFakeClient({
435
- listTools: jest.fn(async () => ({
436
- tools: [{ name: 'messy', inputSchema: goodSchema2, annotations: rawAnnotations }]
437
- }))
438
- });
439
- const session = await connectWith(fake);
440
- expect(await listMcpTools(session)).toSucceedAndSatisfy((tools) => {
441
- // Only the well-typed known fields survive; the malformed readOnlyHint and unknown
442
- // bogusField are dropped; the raw blob is never propagated.
443
- expect(tools[0].annotations).toEqual({ title: 'Keep Me', destructiveHint: true });
444
- expect(tools[0].annotations).not.toHaveProperty('readOnlyHint');
445
- expect(tools[0].annotations).not.toHaveProperty('bogusField');
446
- });
447
- });
448
- test('an all-junk annotations blob normalizes to an absent field (not an empty object)', async () => {
449
- const fake = makeFakeClient({
450
- listTools: jest.fn(async () => ({
451
- tools: [
452
- { name: 'junk', inputSchema: goodSchema2, annotations: { unknownOnly: 1, readOnlyHint: 3 } }
453
- ]
454
- }))
455
- });
456
- const session = await connectWith(fake);
457
- expect(await listMcpTools(session)).toSucceedAndSatisfy((tools) => {
458
- expect(tools[0]).not.toHaveProperty('annotations');
459
- });
460
- });
461
- test('a non-object annotations value is dropped', async () => {
462
- const fake = makeFakeClient({
463
- listTools: jest.fn(async () => ({
464
- tools: [{ name: 'weird', inputSchema: goodSchema2, annotations: 'not-an-object' }]
465
- }))
466
- });
467
- const session = await connectWith(fake);
468
- expect(await listMcpTools(session)).toSucceedAndSatisfy((tools) => {
469
- expect(tools[0]).not.toHaveProperty('annotations');
470
- });
471
- });
472
- test('the skipped-tool path is unaffected by annotations', async () => {
473
- // A tool with annotations but an unsupported inputSchema is still skipped; annotations do
474
- // not rescue it or leak onto the skip record.
475
- const forbidden = {
476
- type: 'object',
477
- properties: { name: { type: 'string', pattern: '^a' } }
478
- };
479
- const fake = makeFakeClient({
480
- listTools: jest.fn(async () => ({
481
- tools: [{ name: 'blocked', inputSchema: forbidden, annotations: { destructiveHint: true } }]
482
- }))
483
- });
484
- const session = await connectWith(fake);
485
- expect(await adaptMcpTools(session)).toSucceedAndSatisfy((result) => {
486
- expect(result.tools).toHaveLength(0);
487
- expect(result.skipped).toHaveLength(1);
488
- expect(result.skipped[0].name).toBe('blocked');
489
- expect(result.skipped[0]).not.toHaveProperty('annotations');
490
- });
491
- });
492
- });
493
- });
494
- //# sourceMappingURL=mcp.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mcp.test.js","sourceRoot":"","sources":["../../../src/test/unit/mcp.test.ts"],"names":[],"mappings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AAC,CAAC;aACJ,CAAC,CAAC;YACH,MAAM,OAAO,GAAG,MAAM,WAAW,CAAC,IAAI,CAAC,CAAC;YACxC,MAAM,CAAC,MAAM,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,MAA4B,EAAE,EAAE;gBACxF,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;gBACrC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;gBACvC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;gBAC/C,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;YAC9D,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["/*\n * Copyright (c) 2026 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\n// Mock the SDK-isolation seam so no live MCP server / subprocess is required. The factories\n// return controllable fakes; `makeClient` is configured per-test. The jest.mock call must\n// precede the regular imports (hoist-jest-mock).\njest.mock('../../packlets/mcp/sdk', () => ({\n makeClient: jest.fn(),\n makeStdioTransport: jest.fn(() => ({ sentinel: 'stdio' })),\n makeHttpTransport: jest.fn(() => ({ sentinel: 'http' }))\n}));\n\nimport '@fgv/ts-utils-jest';\nimport { Logging, type Result } from '@fgv/ts-utils';\nimport { type JsonObject, type JsonValue } from '@fgv/ts-json-base';\n\n// eslint-disable-next-line @rushstack/packlets/mechanics\nimport * as sdk from '../../packlets/mcp/sdk';\nimport {\n type IAdaptMcpToolsResult,\n type IMcpSession,\n type IMcpToolDescriptor,\n type IMcpTransport,\n adaptMcpTools,\n callMcpTool,\n closeMcpSession,\n connectMcpSession,\n createHttpTransport,\n createStdioTransport,\n listMcpTools\n} from '../../packlets/mcp';\n\nconst mockSdk = sdk as jest.Mocked<typeof sdk>;\n\ninterface IFakeClient {\n connect: jest.Mock;\n getServerVersion: jest.Mock;\n listTools: jest.Mock;\n callTool: jest.Mock;\n close: jest.Mock;\n}\n\nfunction makeFakeClient(overrides: Partial<IFakeClient> = {}): IFakeClient {\n return {\n connect: jest.fn(async () => undefined),\n getServerVersion: jest.fn(() => ({ name: 'fake-server', version: '1.2.3' })),\n listTools: jest.fn(async () => ({ tools: [] })),\n callTool: jest.fn(async () => ({ content: [] })),\n close: jest.fn(async () => undefined),\n ...overrides\n };\n}\n\n/** Connect a session backed by the given fake client (and a stdio transport). */\nasync function connectWith(fake: IFakeClient): Promise<IMcpSession> {\n mockSdk.makeClient.mockReturnValueOnce(fake as unknown as sdk.ISdkClient);\n const transport = createStdioTransport({ command: 'node' }).orThrow();\n return (await connectMcpSession({ transport })).orThrow();\n}\n\n/** A foreign (non-package) handle, to exercise the loud narrowing-failure paths. */\nconst FOREIGN_TRANSPORT = { transportKind: 'stdio' } as unknown as IMcpTransport;\nconst FOREIGN_SESSION = {\n clientName: 'x',\n clientVersion: 'y',\n serverInfo: undefined\n} as unknown as IMcpSession;\n\nbeforeEach(() => {\n jest.clearAllMocks();\n mockSdk.makeStdioTransport.mockReturnValue({ sentinel: 'stdio' } as unknown as sdk.ISdkTransport);\n mockSdk.makeHttpTransport.mockReturnValue({ sentinel: 'http' } as unknown as sdk.ISdkTransport);\n});\n\n// ===========================================================================\n// Transports\n// ===========================================================================\n\ndescribe('createStdioTransport', () => {\n test('succeeds for a valid command', () => {\n expect(createStdioTransport({ command: 'node', args: ['x'] })).toSucceedAndSatisfy((t: IMcpTransport) => {\n expect(t.transportKind).toBe('stdio');\n });\n expect(mockSdk.makeStdioTransport).toHaveBeenCalledWith(\n expect.objectContaining({ command: 'node', args: ['x'] })\n );\n });\n\n test('fails for an empty/whitespace command', () => {\n expect(createStdioTransport({ command: '' })).toFailWith(/command must be a non-empty string/);\n expect(createStdioTransport({ command: ' ' })).toFailWith(/command must be a non-empty string/);\n });\n\n test('fails (Result) when the SDK constructor throws', () => {\n mockSdk.makeStdioTransport.mockImplementationOnce(() => {\n throw new Error('spawn boom');\n });\n expect(createStdioTransport({ command: 'node' })).toFailWith(/createStdioTransport:.*spawn boom/);\n });\n});\n\ndescribe('createHttpTransport', () => {\n test('succeeds for http and https urls and forwards headers', () => {\n expect(createHttpTransport({ url: 'http://localhost:9000/mcp' })).toSucceedAndSatisfy(\n (t: IMcpTransport) => {\n expect(t.transportKind).toBe('http');\n }\n );\n expect(\n createHttpTransport({ url: 'https://example.com/mcp', headers: { authorization: 'Bearer t' } })\n ).toSucceed();\n expect(mockSdk.makeHttpTransport).toHaveBeenCalledWith(expect.any(URL), { authorization: 'Bearer t' });\n });\n\n test('fails for an unparseable url', () => {\n expect(createHttpTransport({ url: 'not a url' })).toFailWith(/invalid url 'not a url'/);\n });\n\n test('fails for a non-http(s) protocol', () => {\n expect(createHttpTransport({ url: 'ftp://example.com' })).toFailWith(/must use http or https/);\n });\n\n test('fails (Result) when the SDK constructor throws', () => {\n mockSdk.makeHttpTransport.mockImplementationOnce(() => {\n throw new Error('http boom');\n });\n expect(createHttpTransport({ url: 'http://localhost' })).toFailWith(/createHttpTransport:.*http boom/);\n });\n});\n\n// ===========================================================================\n// Session lifecycle\n// ===========================================================================\n\ndescribe('connectMcpSession', () => {\n test('fails loudly for a foreign transport handle', async () => {\n expect(await connectMcpSession({ transport: FOREIGN_TRANSPORT })).toFailWith(/invalid MCP transport/);\n });\n\n test('connects and reports server identity, logging when a logger is supplied', async () => {\n const logger = new Logging.InMemoryLogger('all');\n const fake = makeFakeClient();\n mockSdk.makeClient.mockReturnValueOnce(fake as unknown as sdk.ISdkClient);\n const transport = createStdioTransport({ command: 'node' }).orThrow();\n\n expect(\n await connectMcpSession({ transport, clientName: 'me', clientVersion: '0.0.1', logger })\n ).toSucceedAndSatisfy((session: IMcpSession) => {\n expect(session.clientName).toBe('me');\n expect(session.clientVersion).toBe('0.0.1');\n expect(session.serverInfo).toEqual({ name: 'fake-server', version: '1.2.3' });\n });\n expect(mockSdk.makeClient).toHaveBeenCalledWith('me', '0.0.1');\n expect(fake.connect).toHaveBeenCalledTimes(1);\n expect(logger.logged.join('\\n')).toMatch(/connected to server fake-server@1.2.3/);\n });\n\n test('connects with default identity and no server info, no logger', async () => {\n const fake = makeFakeClient({ getServerVersion: jest.fn(() => undefined) });\n mockSdk.makeClient.mockReturnValueOnce(fake as unknown as sdk.ISdkClient);\n const transport = createStdioTransport({ command: 'node' }).orThrow();\n\n expect(await connectMcpSession({ transport })).toSucceedAndSatisfy((session: IMcpSession) => {\n expect(session.clientName).toBe('@fgv/ts-extras-mcp');\n expect(session.serverInfo).toBeUndefined();\n });\n });\n\n test('logs the no-identity case when a logger is supplied', async () => {\n const logger = new Logging.InMemoryLogger('all');\n const fake = makeFakeClient({ getServerVersion: jest.fn(() => undefined) });\n mockSdk.makeClient.mockReturnValueOnce(fake as unknown as sdk.ISdkClient);\n const transport = createStdioTransport({ command: 'node' }).orThrow();\n\n expect(await connectMcpSession({ transport, logger })).toSucceed();\n expect(logger.logged.join('\\n')).toMatch(/connected \\(server did not report identity\\)/);\n });\n\n test('fails when the connect handshake throws', async () => {\n const fake = makeFakeClient({\n connect: jest.fn(async () => {\n throw new Error('handshake refused');\n })\n });\n mockSdk.makeClient.mockReturnValueOnce(fake as unknown as sdk.ISdkClient);\n const transport = createStdioTransport({ command: 'node' }).orThrow();\n\n expect(await connectMcpSession({ transport })).toFailWith(/connectMcpSession:.*handshake refused/);\n });\n});\n\ndescribe('closeMcpSession', () => {\n test('fails loudly for a foreign session handle', async () => {\n expect(await closeMcpSession(FOREIGN_SESSION)).toFailWith(/invalid MCP session/);\n });\n\n test('closes a connected session', async () => {\n const fake = makeFakeClient();\n const session = await connectWith(fake);\n expect(await closeMcpSession(session)).toSucceedWith(true);\n expect(fake.close).toHaveBeenCalledTimes(1);\n });\n\n test('fails when close throws', async () => {\n const fake = makeFakeClient({\n close: jest.fn(async () => {\n throw new Error('already closed');\n })\n });\n const session = await connectWith(fake);\n expect(await closeMcpSession(session)).toFailWith(/closeMcpSession:.*already closed/);\n });\n});\n\n// ===========================================================================\n// Tool discovery + invocation\n// ===========================================================================\n\ndescribe('listMcpTools', () => {\n test('fails loudly for a foreign session handle', async () => {\n expect(await listMcpTools(FOREIGN_SESSION)).toFailWith(/invalid MCP session/);\n });\n\n test('returns a single-page catalog', async () => {\n const fake = makeFakeClient({\n listTools: jest.fn(async () => ({\n tools: [{ name: 'a', description: 'tool a', inputSchema: { type: 'object' } }]\n }))\n });\n const session = await connectWith(fake);\n expect(await listMcpTools(session)).toSucceedAndSatisfy((tools: ReadonlyArray<IMcpToolDescriptor>) => {\n expect(tools).toHaveLength(1);\n expect(tools[0]).toEqual({ name: 'a', description: 'tool a', inputSchema: { type: 'object' } });\n });\n });\n\n test('follows nextCursor across pages', async () => {\n const listTools = jest\n .fn()\n .mockResolvedValueOnce({ tools: [{ name: 'a', inputSchema: { type: 'object' } }], nextCursor: 'p2' })\n .mockResolvedValueOnce({ tools: [{ name: 'b', inputSchema: { type: 'object' } }] });\n const fake = makeFakeClient({ listTools });\n const session = await connectWith(fake);\n\n expect(await listMcpTools(session)).toSucceedAndSatisfy((tools: ReadonlyArray<IMcpToolDescriptor>) => {\n expect(tools.map((t) => t.name)).toEqual(['a', 'b']);\n });\n expect(listTools).toHaveBeenNthCalledWith(1, undefined);\n expect(listTools).toHaveBeenNthCalledWith(2, { cursor: 'p2' });\n });\n\n test('coerces a missing/invalid inputSchema to null and a missing description to undefined', async () => {\n const fake = makeFakeClient({\n listTools: jest.fn(async () => ({ tools: [{ name: 'noschema' }] }))\n });\n const session = await connectWith(fake);\n expect(await listMcpTools(session)).toSucceedAndSatisfy((tools: ReadonlyArray<IMcpToolDescriptor>) => {\n expect(tools[0]).toEqual({ name: 'noschema', description: undefined, inputSchema: null });\n });\n });\n\n test('fails when listTools throws', async () => {\n const fake = makeFakeClient({\n listTools: jest.fn(async () => {\n throw new Error('protocol error');\n })\n });\n const session = await connectWith(fake);\n expect(await listMcpTools(session)).toFailWith(/listMcpTools:.*protocol error/);\n });\n});\n\ndescribe('callMcpTool', () => {\n const args: JsonObject = { q: 'hi' };\n\n test('fails loudly for a foreign session handle', async () => {\n expect(await callMcpTool(FOREIGN_SESSION, 'a', args)).toFailWith(/invalid MCP session/);\n });\n\n test('concatenates text blocks', async () => {\n const fake = makeFakeClient({\n callTool: jest.fn(async () => ({\n content: [\n { type: 'text', text: 'line one' },\n { type: 'text', text: 'line two' }\n ]\n }))\n });\n const session = await connectWith(fake);\n expect(await callMcpTool(session, 'a', args)).toSucceedWith({\n content: 'line one\\nline two'\n });\n expect(fake.callTool).toHaveBeenCalledWith({ name: 'a', arguments: args });\n });\n\n test('summarizes non-text blocks', async () => {\n const fake = makeFakeClient({\n callTool: jest.fn(async () => ({\n content: [\n { type: 'text', text: 'caption' },\n { type: 'image', data: 'base64==' }\n ]\n }))\n });\n const session = await connectWith(fake);\n expect(await callMcpTool(session, 'a', args)).toSucceedWith({\n content: 'caption\\n[image block]'\n });\n });\n\n test('projects an empty/absent content list to an empty string', async () => {\n const fake = makeFakeClient({ callTool: jest.fn(async () => ({})) });\n const session = await connectWith(fake);\n expect(await callMcpTool(session, 'a', args)).toSucceedWith({ content: '' });\n });\n\n test('maps isError:true to a Failure carrying the projected content', async () => {\n const fake = makeFakeClient({\n callTool: jest.fn(async () => ({ content: [{ type: 'text', text: 'bad input' }], isError: true }))\n });\n const session = await connectWith(fake);\n expect(await callMcpTool(session, 'a', args)).toFailWith(/^bad input$/);\n });\n\n test('maps isError:true with no content to a generic error', async () => {\n const fake = makeFakeClient({ callTool: jest.fn(async () => ({ isError: true })) });\n const session = await connectWith(fake);\n expect(await callMcpTool(session, 'broken', args)).toFailWith(/tool 'broken' reported an error/);\n });\n\n test('fails when callTool throws', async () => {\n const fake = makeFakeClient({\n callTool: jest.fn(async () => {\n throw new Error('timeout');\n })\n });\n const session = await connectWith(fake);\n expect(await callMcpTool(session, 'a', args)).toFailWith(/callMcpTool 'a':.*timeout/);\n });\n});\n\n// ===========================================================================\n// adaptMcpTools — the headline (Constraint 1)\n// ===========================================================================\n\ndescribe('adaptMcpTools', () => {\n const goodSchema: JsonValue = {\n type: 'object',\n properties: { q: { type: 'string' } },\n required: ['q']\n };\n // `pattern` is outside the JsonSchema.fromJson supported subset → fromJson fails with a pointer.\n const forbiddenSchema: JsonValue = {\n type: 'object',\n properties: { name: { type: 'string', pattern: '^a' } }\n };\n\n function mixedCatalogClient(): IFakeClient {\n return makeFakeClient({\n listTools: jest.fn(async () => ({\n tools: [\n { name: 'good', description: 'a good tool', inputSchema: goodSchema },\n { name: 'forbidden', inputSchema: forbiddenSchema },\n { name: 'nonobject', description: 'bad', inputSchema: 'not-a-schema' }\n ]\n }))\n });\n }\n\n test('propagates a tool-discovery failure', async () => {\n const fake = makeFakeClient({\n listTools: jest.fn(async () => {\n throw new Error('discovery down');\n })\n });\n const session = await connectWith(fake);\n expect(await adaptMcpTools(session)).toFailWith(/adaptMcpTools:.*discovery down/);\n });\n\n test('adapts good tools and surfaces skipped tools structurally + NOISY warn', async () => {\n const logger = new Logging.InMemoryLogger('all');\n const session = await connectWith(mixedCatalogClient());\n\n expect(await adaptMcpTools(session, { logger })).toSucceedAndSatisfy((result: IAdaptMcpToolsResult) => {\n expect(result.tools).toHaveLength(1);\n expect(result.tools[0].config.name).toBe('good');\n expect(result.tools[0].config.description).toBe('a good tool');\n\n expect(result.skipped).toHaveLength(2);\n const byName = new Map(result.skipped.map((s) => [s.name, s]));\n expect(byName.get('forbidden')?.reason).toMatch(/pattern/);\n expect(byName.get('forbidden')?.schema).toEqual(forbiddenSchema);\n expect(byName.get('nonobject')?.reason).toMatch(/not a JSON object/);\n expect(byName.get('nonobject')?.schema).toBe('not-a-schema');\n });\n\n // NOISY warn: tool name + pointer reason + the raw failing schema verbatim.\n const warned = logger.logged.join('\\n');\n expect(warned).toMatch(/skipping tool 'forbidden'/);\n expect(warned).toMatch(/pattern/);\n expect(warned).toContain(JSON.stringify(forbiddenSchema));\n expect(warned).toMatch(/skipping tool 'nonobject'/);\n });\n\n test('surfaces skips structurally even without a logger', async () => {\n const session = await connectWith(mixedCatalogClient());\n expect(await adaptMcpTools(session)).toSucceedAndSatisfy((result: IAdaptMcpToolsResult) => {\n expect(result.tools).toHaveLength(1);\n expect(result.skipped).toHaveLength(2);\n });\n });\n\n test('falls back to the tool name when no description is provided', async () => {\n const fake = makeFakeClient({\n listTools: jest.fn(async () => ({ tools: [{ name: 'nodesc', inputSchema: goodSchema }] }))\n });\n const session = await connectWith(fake);\n expect(await adaptMcpTools(session)).toSucceedAndSatisfy((result: IAdaptMcpToolsResult) => {\n expect(result.tools[0].config.description).toBe('nodesc');\n });\n });\n\n describe('adapted tool execute', () => {\n async function adaptGood(callTool: jest.Mock): Promise<(args: unknown) => Promise<Result<unknown>>> {\n const fake = makeFakeClient({\n listTools: jest.fn(async () => ({ tools: [{ name: 'good', inputSchema: goodSchema }] })),\n callTool\n });\n const session = await connectWith(fake);\n const result = (await adaptMcpTools(session)).orThrow();\n return result.tools[0].execute;\n }\n\n test('forwards validated args to callMcpTool and returns the projected content', async () => {\n const callTool = jest.fn(async () => ({ content: [{ type: 'text', text: 'tool output' }] }));\n const execute = await adaptGood(callTool);\n expect(await execute({ q: 'hello' })).toSucceedWith('tool output');\n expect(callTool).toHaveBeenCalledWith({ name: 'good', arguments: { q: 'hello' } });\n });\n\n test('fails when the model supplies non-object arguments', async () => {\n const callTool = jest.fn();\n const execute = await adaptGood(callTool);\n expect(await execute('not-an-object')).toFailWith(/tool 'good': arguments must be a JSON object/);\n expect(callTool).not.toHaveBeenCalled();\n });\n\n test('propagates an MCP tool error as a Failure', async () => {\n const callTool = jest.fn(async () => ({ content: [{ type: 'text', text: 'denied' }], isError: true }));\n const execute = await adaptGood(callTool);\n expect(await execute({ q: 'hello' })).toFailWith(/denied/);\n });\n });\n\n // ==========================================================================\n // C2 — MCP Tool.annotations passthrough (normalized, never raw)\n // ==========================================================================\n\n describe('annotations passthrough (C2)', () => {\n const goodSchema2: JsonValue = { type: 'object', properties: { q: { type: 'string' } }, required: ['q'] };\n\n test('all five hints round-trip onto descriptor.annotations and config.annotations', async () => {\n const annotations = {\n title: 'Recall Memory',\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false\n };\n const fake = makeFakeClient({\n listTools: jest.fn(async () => ({\n tools: [{ name: 'recall', description: 'r', inputSchema: goodSchema2, annotations }]\n }))\n });\n const session = await connectWith(fake);\n\n expect(await listMcpTools(session)).toSucceedAndSatisfy((tools: ReadonlyArray<IMcpToolDescriptor>) => {\n expect(tools[0].annotations).toEqual(annotations);\n });\n\n const session2 = await connectWith(\n makeFakeClient({\n listTools: jest.fn(async () => ({\n tools: [{ name: 'recall', description: 'r', inputSchema: goodSchema2, annotations }]\n }))\n })\n );\n expect(await adaptMcpTools(session2)).toSucceedAndSatisfy((result: IAdaptMcpToolsResult) => {\n expect(result.tools[0].config.annotations).toEqual(annotations);\n });\n });\n\n test('a tool with no annotations leaves the field absent', async () => {\n const fake = makeFakeClient({\n listTools: jest.fn(async () => ({ tools: [{ name: 'plain', inputSchema: goodSchema2 }] }))\n });\n const session = await connectWith(fake);\n expect(await listMcpTools(session)).toSucceedAndSatisfy((tools: ReadonlyArray<IMcpToolDescriptor>) => {\n expect(tools[0]).not.toHaveProperty('annotations');\n });\n\n const session2 = await connectWith(\n makeFakeClient({\n listTools: jest.fn(async () => ({ tools: [{ name: 'plain', inputSchema: goodSchema2 }] }))\n })\n );\n expect(await adaptMcpTools(session2)).toSucceedAndSatisfy((result: IAdaptMcpToolsResult) => {\n expect(result.tools[0].config).not.toHaveProperty('annotations');\n });\n });\n\n test('a malformed annotations blob is normalized (known fields kept, junk dropped), never raw-propagated', async () => {\n // readOnlyHint is the wrong type (dropped); bogusField is unknown (dropped); title is valid (kept).\n const rawAnnotations = {\n title: 'Keep Me',\n readOnlyHint: 'yes-please',\n destructiveHint: true,\n bogusField: { nested: 42 }\n };\n const fake = makeFakeClient({\n listTools: jest.fn(async () => ({\n tools: [{ name: 'messy', inputSchema: goodSchema2, annotations: rawAnnotations }]\n }))\n });\n const session = await connectWith(fake);\n expect(await listMcpTools(session)).toSucceedAndSatisfy((tools: ReadonlyArray<IMcpToolDescriptor>) => {\n // Only the well-typed known fields survive; the malformed readOnlyHint and unknown\n // bogusField are dropped; the raw blob is never propagated.\n expect(tools[0].annotations).toEqual({ title: 'Keep Me', destructiveHint: true });\n expect(tools[0].annotations).not.toHaveProperty('readOnlyHint');\n expect(tools[0].annotations).not.toHaveProperty('bogusField');\n });\n });\n\n test('an all-junk annotations blob normalizes to an absent field (not an empty object)', async () => {\n const fake = makeFakeClient({\n listTools: jest.fn(async () => ({\n tools: [\n { name: 'junk', inputSchema: goodSchema2, annotations: { unknownOnly: 1, readOnlyHint: 3 } }\n ]\n }))\n });\n const session = await connectWith(fake);\n expect(await listMcpTools(session)).toSucceedAndSatisfy((tools: ReadonlyArray<IMcpToolDescriptor>) => {\n expect(tools[0]).not.toHaveProperty('annotations');\n });\n });\n\n test('a non-object annotations value is dropped', async () => {\n const fake = makeFakeClient({\n listTools: jest.fn(async () => ({\n tools: [{ name: 'weird', inputSchema: goodSchema2, annotations: 'not-an-object' }]\n }))\n });\n const session = await connectWith(fake);\n expect(await listMcpTools(session)).toSucceedAndSatisfy((tools: ReadonlyArray<IMcpToolDescriptor>) => {\n expect(tools[0]).not.toHaveProperty('annotations');\n });\n });\n\n test('the skipped-tool path is unaffected by annotations', async () => {\n // A tool with annotations but an unsupported inputSchema is still skipped; annotations do\n // not rescue it or leak onto the skip record.\n const forbidden: JsonValue = {\n type: 'object',\n properties: { name: { type: 'string', pattern: '^a' } }\n };\n const fake = makeFakeClient({\n listTools: jest.fn(async () => ({\n tools: [{ name: 'blocked', inputSchema: forbidden, annotations: { destructiveHint: true } }]\n }))\n });\n const session = await connectWith(fake);\n expect(await adaptMcpTools(session)).toSucceedAndSatisfy((result: IAdaptMcpToolsResult) => {\n expect(result.tools).toHaveLength(0);\n expect(result.skipped).toHaveLength(1);\n expect(result.skipped[0].name).toBe('blocked');\n expect(result.skipped[0]).not.toHaveProperty('annotations');\n });\n });\n });\n});\n"]}