@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,254 +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
-
23
- /**
24
- * End-to-end verification against a REAL in-memory MCP server (the SDK's `Server` +
25
- * `InMemoryTransport.createLinkedPair()`) — NOT a mocked SDK. This is the durable proof that the
26
- * brief's two load-bearing constraints actually flow through the full stack: the real SDK `Client`,
27
- * the real initialize handshake, the real `listTools`/`callTool` round-trips, the `sdk.ts`
28
- * projection casts, and `adaptMcpTools`' `JsonSchema.fromJson` gate. It is the class of gap that
29
- * 100%-line-coverage of a mocked seam cannot catch (e.g. a projection-shape mismatch in `sdk.ts`).
30
- *
31
- * The fixture server advertises a MIX of tools: two adaptable, and one for each JSON Schema feature
32
- * `JsonSchema.fromJson` rejects ($ref, oneOf, anyOf, pattern, union `type[]`).
33
- */
34
-
35
- import '@fgv/ts-utils-jest';
36
- import { Logging, type Result } from '@fgv/ts-utils';
37
-
38
- // Real MCP SDK server side — exercised over an in-process linked transport pair. Subpath imports
39
- // resolve via the tsconfig `paths` mapping (the same seam the package's sdk.ts uses).
40
- import { Server } from '@modelcontextprotocol/sdk/server/index.js';
41
- import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
42
- import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
43
-
44
- import {
45
- type IMcpSession,
46
- adaptMcpTools,
47
- callMcpTool,
48
- closeMcpSession,
49
- connectMcpSession,
50
- listMcpTools
51
- } from '../../packlets/mcp';
52
- // Internal: the opaque-handle class. The package exposes only stdio/http transport factories, so a
53
- // real in-process e2e (which must inject the SDK's InMemoryTransport) wraps it here. Tests may
54
- // import internal modules directly (TESTING_GUIDELINES § Testing Internal Code).
55
- // eslint-disable-next-line @rushstack/packlets/mechanics
56
- import { McpTransport } from '../../packlets/mcp/transports';
57
-
58
- // ---------------------------------------------------------------------------
59
- // Fixture server — a real SDK Server advertising a mix of adaptable + un-adaptable tools.
60
- // ---------------------------------------------------------------------------
61
-
62
- /** The two adaptable tools (in the supported JSON Schema subset). */
63
- const ADAPTABLE_TOOLS = [
64
- {
65
- name: 'echo',
66
- description: 'Echoes the supplied message back.',
67
- inputSchema: {
68
- type: 'object',
69
- properties: { msg: { type: 'string', description: 'message to echo' } },
70
- required: ['msg']
71
- }
72
- },
73
- {
74
- name: 'ping',
75
- description: 'Health check with no required args.',
76
- inputSchema: { type: 'object', properties: {} }
77
- }
78
- ];
79
-
80
- /**
81
- * One tool per JSON Schema feature `JsonSchema.fromJson` rejects. Each carries the forbidden
82
- * keyword NESTED inside a property (the real-world shape: the top-level inputSchema is a valid
83
- * `type: 'object'`, so the MCP SDK's own result validation lets it through, and the rejection
84
- * happens in `adaptMcpTools` exactly as a real server would surface it).
85
- */
86
- const UNADAPTABLE_TOOLS = [
87
- {
88
- name: 'ref_tool',
89
- inputSchema: { type: 'object', properties: { x: { $ref: '#/$defs/Foo' } } }
90
- },
91
- {
92
- name: 'oneof_tool',
93
- inputSchema: { type: 'object', properties: { x: { oneOf: [{ type: 'string' }, { type: 'number' }] } } }
94
- },
95
- {
96
- name: 'anyof_tool',
97
- inputSchema: { type: 'object', properties: { x: { anyOf: [{ type: 'string' }, { type: 'number' }] } } }
98
- },
99
- {
100
- name: 'pattern_tool',
101
- inputSchema: { type: 'object', properties: { code: { type: 'string', pattern: '^[A-Z]+$' } } }
102
- },
103
- {
104
- name: 'union_tool',
105
- inputSchema: { type: 'object', properties: { x: { type: ['string', 'null'] } } }
106
- }
107
- ];
108
-
109
- const ALL_TOOLS = [...ADAPTABLE_TOOLS, ...UNADAPTABLE_TOOLS];
110
-
111
- /** Builds and connects a real in-memory MCP server; returns its server-side handle for teardown. */
112
- async function startFixtureServer(): Promise<{ server: Server; clientTransport: InMemoryTransport }> {
113
- const server = new Server(
114
- { name: 'fixture-mcp-server', version: '0.0.1' },
115
- { capabilities: { tools: {} } }
116
- );
117
-
118
- server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: ALL_TOOLS }));
119
-
120
- server.setRequestHandler(CallToolRequestSchema, async (request) => {
121
- const { name, arguments: args } = request.params;
122
- if (name === 'echo') {
123
- return { content: [{ type: 'text', text: `echo: ${JSON.stringify(args)}` }] };
124
- }
125
- if (name === 'ping') {
126
- return { content: [{ type: 'text', text: 'pong' }] };
127
- }
128
- return { content: [{ type: 'text', text: `unknown tool: ${name}` }], isError: true };
129
- });
130
-
131
- const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
132
- await server.connect(serverTransport);
133
- return { server, clientTransport };
134
- }
135
-
136
- // ---------------------------------------------------------------------------
137
- // End-to-end suite
138
- // ---------------------------------------------------------------------------
139
-
140
- describe('@fgv/ts-extras-mcp end-to-end against a real in-memory MCP server', () => {
141
- let server: Server;
142
- let session: IMcpSession;
143
-
144
- beforeEach(async () => {
145
- const fixture = await startFixtureServer();
146
- server = fixture.server;
147
- // Wrap the SDK in-memory client transport in the package's opaque handle, then connect through
148
- // the PUBLIC connectMcpSession (real Client + real initialize handshake). On a connect failure,
149
- // tear the fixture server down before throwing so a failed handshake can't leak open handles.
150
- const transport = new McpTransport('http', fixture.clientTransport);
151
- const connectResult = await connectMcpSession({ transport, clientName: 'e2e', clientVersion: '0.0.0' });
152
- if (connectResult.isFailure()) {
153
- await server.close();
154
- throw new Error(`fixture connect failed: ${connectResult.message}`);
155
- }
156
- session = connectResult.value;
157
- });
158
-
159
- afterEach(async () => {
160
- // Assert teardown succeeds — a regression in close/transport would otherwise pass silently.
161
- // `server.close()` runs in `finally` so the fixture is always torn down even if the assertion
162
- // throws (otherwise a failed close would leak handles and make later tests flaky).
163
- try {
164
- expect(await closeMcpSession(session)).toSucceedWith(true);
165
- } finally {
166
- await server.close();
167
- }
168
- });
169
-
170
- test('the initialize handshake reports the real server identity', () => {
171
- expect(session.serverInfo).toEqual({ name: 'fixture-mcp-server', version: '0.0.1' });
172
- });
173
-
174
- test('listMcpTools returns the full catalog over the real transport', async () => {
175
- expect(await listMcpTools(session)).toSucceedAndSatisfy((tools) => {
176
- expect(tools.map((t) => t.name).sort()).toEqual(
177
- ['anyof_tool', 'echo', 'oneof_tool', 'pattern_tool', 'ping', 'ref_tool', 'union_tool'].sort()
178
- );
179
- });
180
- });
181
-
182
- test('callMcpTool round-trips a real tool result, and maps isError to Failure', async () => {
183
- expect(await callMcpTool(session, 'echo', { msg: 'hi' })).toSucceedWith({
184
- content: 'echo: {"msg":"hi"}'
185
- });
186
- expect(await callMcpTool(session, 'nope', {})).toFailWith(/unknown tool: nope/);
187
- });
188
-
189
- // =========================================================================
190
- // CONSTRAINT 1 — graceful degradation with NOISY, schema-bearing warnings.
191
- // =========================================================================
192
- describe('Constraint 1 — adaptMcpTools graceful + NOISY degradation', () => {
193
- test('excludes EVERY un-adaptable tool from `tools`, surfaces each on `skipped`, warns with the raw schema', async () => {
194
- const logger = new Logging.InMemoryLogger('all');
195
- const expectedReasonFragment: Record<string, RegExp> = {
196
- ref_tool: /\$ref/,
197
- oneof_tool: /oneOf/,
198
- anyof_tool: /anyOf/,
199
- pattern_tool: /pattern/,
200
- union_tool: /union 'type'/
201
- };
202
-
203
- expect(await adaptMcpTools(session, { logger })).toSucceedAndSatisfy((result) => {
204
- // (a) Only the adaptable tools are offered to the model; none of the rejected ones leak.
205
- expect(result.tools.map((t) => t.config.name).sort()).toEqual(['echo', 'ping']);
206
- const offeredNames = new Set(result.tools.map((t) => t.config.name));
207
- for (const t of UNADAPTABLE_TOOLS) {
208
- expect(offeredNames.has(t.name)).toBe(false);
209
- }
210
-
211
- // (b) Each un-adaptable tool is surfaced structurally with name + JSON-pointer reason + the
212
- // RAW failing schema (verbatim, so the subset can be widened later).
213
- expect(result.skipped).toHaveLength(UNADAPTABLE_TOOLS.length);
214
- const skippedByName = new Map(result.skipped.map((s) => [s.name, s]));
215
- for (const tool of UNADAPTABLE_TOOLS) {
216
- const skipped = skippedByName.get(tool.name);
217
- expect(skipped).toBeDefined();
218
- // JSON-pointer path into the offending node.
219
- expect(skipped?.reason).toMatch(/#\/properties\//);
220
- expect(skipped?.reason).toMatch(expectedReasonFragment[tool.name]);
221
- // The RAW failing schema, verbatim.
222
- expect(skipped?.schema).toEqual(tool.inputSchema);
223
- }
224
- });
225
-
226
- // (c) A NOISY warning per skip that INCLUDES the raw failing schema text + the reason. The
227
- // schema-in-the-warning is the whole "so we can extend fromJson later" requirement — a
228
- // warn WITHOUT the schema would fail this assertion.
229
- const warned = logger.logged.join('\n');
230
- for (const tool of UNADAPTABLE_TOOLS) {
231
- expect(warned).toContain(`skipping tool '${tool.name}'`);
232
- // The raw schema, serialized exactly as adaptMcpTools emits it, must appear in the warn.
233
- expect(warned).toContain(JSON.stringify(tool.inputSchema));
234
- }
235
- // And the reason fragments are present in the warnings too.
236
- expect(warned).toMatch(/\$ref/);
237
- expect(warned).toMatch(/union 'type'/);
238
- });
239
-
240
- test('an adapted tool executes end-to-end against the real server', async () => {
241
- // Result-matcher-driven: extract the adapted `echo` tool inside the success satisfier (where
242
- // its presence is asserted), then drive its execute callback — which round-trips through
243
- // callMcpTool to the real server — with another matcher.
244
- let echoExecute: ((args: unknown) => Promise<Result<unknown>>) | undefined;
245
- expect(await adaptMcpTools(session)).toSucceedAndSatisfy((result) => {
246
- const echo = result.tools.find((t) => t.config.name === 'echo');
247
- expect(echo).toBeDefined();
248
- echoExecute = echo?.execute;
249
- });
250
- expect(echoExecute).toBeDefined();
251
- expect(await echoExecute?.({ msg: 'roundtrip' })).toSucceedWith('echo: {"msg":"roundtrip"}');
252
- });
253
- });
254
- });
@@ -1,43 +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
-
23
- import '@fgv/ts-utils-jest';
24
- import * as mcp from '../../index';
25
-
26
- describe('@fgv/ts-extras-mcp package barrel', () => {
27
- test('re-exports the public boundary primitives', () => {
28
- expect(typeof mcp.createStdioTransport).toBe('function');
29
- expect(typeof mcp.createHttpTransport).toBe('function');
30
- expect(typeof mcp.connectMcpSession).toBe('function');
31
- expect(typeof mcp.closeMcpSession).toBe('function');
32
- expect(typeof mcp.listMcpTools).toBe('function');
33
- expect(typeof mcp.callMcpTool).toBe('function');
34
- expect(typeof mcp.adaptMcpTools).toBe('function');
35
- });
36
-
37
- test('the re-exported transport factories are the real (behaving) implementations', () => {
38
- // Behavioral signal beyond `typeof`: a renamed-but-still-a-function export would not behave
39
- // this way. (The synchronous transport factories validate without touching the SDK/network.)
40
- expect(mcp.createStdioTransport({ command: '' })).toFailWith(/command must be a non-empty string/);
41
- expect(mcp.createHttpTransport({ url: 'not a url' })).toFailWith(/invalid url/);
42
- });
43
- });