@fgv/ts-extras-mcp 5.1.0-34

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 (107) hide show
  1. package/.rush/temp/5d207610a84e494acaefe7ed13447cda74ddf7da.tar.log +90 -0
  2. package/.rush/temp/chunked-rush-logs/ts-extras-mcp.build.chunks.jsonl +9 -0
  3. package/.rush/temp/operation/build/all.log +9 -0
  4. package/.rush/temp/operation/build/log-chunks.jsonl +9 -0
  5. package/.rush/temp/operation/build/state.json +3 -0
  6. package/.rush/temp/shrinkwrap-deps.json +734 -0
  7. package/CHANGELOG.json +4 -0
  8. package/README.md +133 -0
  9. package/config/api-extractor.json +38 -0
  10. package/config/jest.config.json +13 -0
  11. package/config/rig.json +6 -0
  12. package/dist/index.js +49 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/packlets/mcp/adapter.js +122 -0
  15. package/dist/packlets/mcp/adapter.js.map +1 -0
  16. package/dist/packlets/mcp/index.js +33 -0
  17. package/dist/packlets/mcp/index.js.map +1 -0
  18. package/dist/packlets/mcp/model.js +23 -0
  19. package/dist/packlets/mcp/model.js.map +1 -0
  20. package/dist/packlets/mcp/operations.js +119 -0
  21. package/dist/packlets/mcp/operations.js.map +1 -0
  22. package/dist/packlets/mcp/sdk.js +67 -0
  23. package/dist/packlets/mcp/sdk.js.map +1 -0
  24. package/dist/packlets/mcp/session.js +109 -0
  25. package/dist/packlets/mcp/session.js.map +1 -0
  26. package/dist/packlets/mcp/transports.js +96 -0
  27. package/dist/packlets/mcp/transports.js.map +1 -0
  28. package/dist/test/unit/endToEnd.test.js +220 -0
  29. package/dist/test/unit/endToEnd.test.js.map +1 -0
  30. package/dist/test/unit/index.test.js +41 -0
  31. package/dist/test/unit/index.test.js.map +1 -0
  32. package/dist/test/unit/mcp.test.js +381 -0
  33. package/dist/test/unit/mcp.test.js.map +1 -0
  34. package/dist/test/unit/sdk.test.js +68 -0
  35. package/dist/test/unit/sdk.test.js.map +1 -0
  36. package/dist/ts-extras-mcp.d.ts +290 -0
  37. package/dist/tsdoc-metadata.json +11 -0
  38. package/eslint.config.js +15 -0
  39. package/etc/ts-extras-mcp.api.md +104 -0
  40. package/lib/index.d.ts +28 -0
  41. package/lib/index.d.ts.map +1 -0
  42. package/lib/index.js +65 -0
  43. package/lib/index.js.map +1 -0
  44. package/lib/packlets/mcp/adapter.d.ts +33 -0
  45. package/lib/packlets/mcp/adapter.d.ts.map +1 -0
  46. package/lib/packlets/mcp/adapter.js +125 -0
  47. package/lib/packlets/mcp/adapter.js.map +1 -0
  48. package/lib/packlets/mcp/index.d.ts +10 -0
  49. package/lib/packlets/mcp/index.d.ts.map +1 -0
  50. package/lib/packlets/mcp/index.js +57 -0
  51. package/lib/packlets/mcp/index.js.map +1 -0
  52. package/lib/packlets/mcp/model.d.ts +155 -0
  53. package/lib/packlets/mcp/model.d.ts.map +1 -0
  54. package/lib/packlets/mcp/model.js +24 -0
  55. package/lib/packlets/mcp/model.js.map +1 -0
  56. package/lib/packlets/mcp/operations.d.ts +36 -0
  57. package/lib/packlets/mcp/operations.d.ts.map +1 -0
  58. package/lib/packlets/mcp/operations.js +123 -0
  59. package/lib/packlets/mcp/operations.js.map +1 -0
  60. package/lib/packlets/mcp/sdk.d.ts +91 -0
  61. package/lib/packlets/mcp/sdk.d.ts.map +1 -0
  62. package/lib/packlets/mcp/sdk.js +72 -0
  63. package/lib/packlets/mcp/sdk.js.map +1 -0
  64. package/lib/packlets/mcp/session.d.ts +43 -0
  65. package/lib/packlets/mcp/session.d.ts.map +1 -0
  66. package/lib/packlets/mcp/session.js +115 -0
  67. package/lib/packlets/mcp/session.js.map +1 -0
  68. package/lib/packlets/mcp/transports.d.ts +49 -0
  69. package/lib/packlets/mcp/transports.d.ts.map +1 -0
  70. package/lib/packlets/mcp/transports.js +102 -0
  71. package/lib/packlets/mcp/transports.js.map +1 -0
  72. package/lib/test/unit/endToEnd.test.d.ts +13 -0
  73. package/lib/test/unit/endToEnd.test.d.ts.map +1 -0
  74. package/lib/test/unit/endToEnd.test.js +222 -0
  75. package/lib/test/unit/endToEnd.test.js.map +1 -0
  76. package/lib/test/unit/index.test.d.ts +2 -0
  77. package/lib/test/unit/index.test.d.ts.map +1 -0
  78. package/lib/test/unit/index.test.js +76 -0
  79. package/lib/test/unit/index.test.js.map +1 -0
  80. package/lib/test/unit/mcp.test.d.ts +2 -0
  81. package/lib/test/unit/mcp.test.d.ts.map +1 -0
  82. package/lib/test/unit/mcp.test.js +416 -0
  83. package/lib/test/unit/mcp.test.js.map +1 -0
  84. package/lib/test/unit/sdk.test.d.ts +2 -0
  85. package/lib/test/unit/sdk.test.d.ts.map +1 -0
  86. package/lib/test/unit/sdk.test.js +70 -0
  87. package/lib/test/unit/sdk.test.js.map +1 -0
  88. package/package.json +86 -0
  89. package/rush-logs/ts-extras-mcp.build.cache.log +3 -0
  90. package/rush-logs/ts-extras-mcp.build.log +9 -0
  91. package/src/index.ts +50 -0
  92. package/src/packlets/mcp/adapter.ts +152 -0
  93. package/src/packlets/mcp/index.ts +34 -0
  94. package/src/packlets/mcp/model.ts +204 -0
  95. package/src/packlets/mcp/operations.ts +138 -0
  96. package/src/packlets/mcp/sdk.ts +148 -0
  97. package/src/packlets/mcp/session.ts +137 -0
  98. package/src/packlets/mcp/transports.ts +111 -0
  99. package/src/test/unit/endToEnd.test.ts +254 -0
  100. package/src/test/unit/index.test.ts +43 -0
  101. package/src/test/unit/mcp.test.ts +473 -0
  102. package/src/test/unit/sdk.test.ts +73 -0
  103. package/temp/build/lint/_eslint-5eVG3S6w.json +54 -0
  104. package/temp/build/typescript/ts_8nwakTlr.json +1 -0
  105. package/temp/ts-extras-mcp.api.json +1662 -0
  106. package/temp/ts-extras-mcp.api.md +104 -0
  107. package/tsconfig.json +12 -0
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Opaque transport handle. The concrete value is an SDK `Transport`; consumers of this module
3
+ * treat it as opaque and only ever hand it back to {@link makeClient}-produced clients.
4
+ * @internal
5
+ */
6
+ export type ISdkTransport = object;
7
+ /**
8
+ * A single content block in an MCP `CallToolResult`. Only `text` blocks carry inline content;
9
+ * all other block types are projected to a structural summary by the operations layer.
10
+ * @internal
11
+ */
12
+ export interface ISdkContentBlock {
13
+ readonly type: string;
14
+ readonly text?: string;
15
+ }
16
+ /**
17
+ * Projection of the SDK's `CallToolResult`.
18
+ * @internal
19
+ */
20
+ export interface ISdkCallToolResult {
21
+ readonly content?: ReadonlyArray<ISdkContentBlock>;
22
+ readonly isError?: boolean;
23
+ }
24
+ /**
25
+ * Projection of a single tool descriptor in the SDK's `ListToolsResult`.
26
+ * @internal
27
+ */
28
+ export interface ISdkToolDescriptor {
29
+ readonly name: string;
30
+ readonly description?: string;
31
+ readonly inputSchema?: unknown;
32
+ }
33
+ /**
34
+ * Projection of the SDK's `ListToolsResult` (one page).
35
+ * @internal
36
+ */
37
+ export interface ISdkListToolsResult {
38
+ readonly tools: ReadonlyArray<ISdkToolDescriptor>;
39
+ readonly nextCursor?: string;
40
+ }
41
+ /**
42
+ * Server identity returned by the SDK's `getServerVersion()` after the initialize handshake.
43
+ * @internal
44
+ */
45
+ export interface ISdkImplementation {
46
+ readonly name: string;
47
+ readonly version: string;
48
+ }
49
+ /**
50
+ * Minimal projection of the SDK `Client` surface the package depends on.
51
+ * @internal
52
+ */
53
+ export interface ISdkClient {
54
+ connect(transport: ISdkTransport): Promise<void>;
55
+ getServerVersion(): ISdkImplementation | undefined;
56
+ listTools(params?: {
57
+ cursor?: string;
58
+ }): Promise<ISdkListToolsResult>;
59
+ callTool(params: {
60
+ name: string;
61
+ arguments?: Record<string, unknown>;
62
+ }): Promise<ISdkCallToolResult>;
63
+ close(): Promise<void>;
64
+ }
65
+ /**
66
+ * Parameters for the stdio transport factory.
67
+ * @internal
68
+ */
69
+ export interface ISdkStdioParams {
70
+ readonly command: string;
71
+ readonly args?: ReadonlyArray<string>;
72
+ readonly env?: Record<string, string>;
73
+ readonly cwd?: string;
74
+ }
75
+ /**
76
+ * Constructs an MCP client. The `as unknown as` cast is the package's single SDK-type
77
+ * bridge — the runtime object is a real SDK `Client`.
78
+ * @internal
79
+ */
80
+ export declare function makeClient(name: string, version: string): ISdkClient;
81
+ /**
82
+ * Constructs a stdio transport that spawns the given command as a subprocess.
83
+ * @internal
84
+ */
85
+ export declare function makeStdioTransport(params: ISdkStdioParams): ISdkTransport;
86
+ /**
87
+ * Constructs a Streamable-HTTP transport for the given URL, with optional static headers.
88
+ * @internal
89
+ */
90
+ export declare function makeHttpTransport(url: URL, headers?: Record<string, string>): ISdkTransport;
91
+ //# sourceMappingURL=sdk.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../../../src/packlets/mcp/sdk.ts"],"names":[],"mappings":"AAwCA;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC;AAEnC;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,OAAO,CAAC,EAAE,aAAa,CAAC,gBAAgB,CAAC,CAAC;IACnD,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC;CAChC;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,kBAAkB,CAAC,CAAC;IAClD,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED;;;GAGG;AACH,MAAM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+ "use strict";
2
+ /*
3
+ * Copyright (c) 2026 Erik Fortune
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in all
13
+ * copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ * SOFTWARE.
22
+ */
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.makeClient = makeClient;
25
+ exports.makeStdioTransport = makeStdioTransport;
26
+ exports.makeHttpTransport = makeHttpTransport;
27
+ /**
28
+ * **The single `@modelcontextprotocol/sdk` import site for the entire package.**
29
+ *
30
+ * Every other module in `@fgv/ts-extras-mcp` depends only on the minimal local projection
31
+ * exported here (`ISdkClient`, `ISdkTransport`, the three `make*` factories) — never on the SDK
32
+ * directly. This keeps the announced v2 client-package rename a one-file change and lets unit
33
+ * tests mock this module instead of the SDK internals (no live server required).
34
+ *
35
+ * The only `as unknown as` casts in the package live here, at the boundary where the real SDK
36
+ * objects are narrowed to the local projection.
37
+ *
38
+ * @internal
39
+ */
40
+ const index_js_1 = require("@modelcontextprotocol/sdk/client/index.js");
41
+ const stdio_js_1 = require("@modelcontextprotocol/sdk/client/stdio.js");
42
+ const streamableHttp_js_1 = require("@modelcontextprotocol/sdk/client/streamableHttp.js");
43
+ /**
44
+ * Constructs an MCP client. The `as unknown as` cast is the package's single SDK-type
45
+ * bridge — the runtime object is a real SDK `Client`.
46
+ * @internal
47
+ */
48
+ function makeClient(name, version) {
49
+ return new index_js_1.Client({ name, version }, { capabilities: {} });
50
+ }
51
+ /**
52
+ * Constructs a stdio transport that spawns the given command as a subprocess.
53
+ * @internal
54
+ */
55
+ function makeStdioTransport(params) {
56
+ return new stdio_js_1.StdioClientTransport({
57
+ command: params.command,
58
+ args: params.args ? [...params.args] : undefined,
59
+ env: params.env,
60
+ cwd: params.cwd
61
+ });
62
+ }
63
+ /**
64
+ * Constructs a Streamable-HTTP transport for the given URL, with optional static headers.
65
+ * @internal
66
+ */
67
+ function makeHttpTransport(url, headers) {
68
+ return new streamableHttp_js_1.StreamableHTTPClientTransport(url, {
69
+ requestInit: headers ? { headers } : undefined
70
+ });
71
+ }
72
+ //# sourceMappingURL=sdk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sdk.js","sourceRoot":"","sources":["../../../src/packlets/mcp/sdk.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;AAsGH,gCAEC;AAMD,gDAOC;AAMD,8CAIC;AA7HD;;;;;;;;;;;;GAYG;AAEH,wEAAmE;AACnE,wEAAiF;AACjF,0FAAmG;AA+EnG;;;;GAIG;AACH,SAAgB,UAAU,CAAC,IAAY,EAAE,OAAe;IACtD,OAAO,IAAI,iBAAM,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE,CAA0B,CAAC;AACtF,CAAC;AAED;;;GAGG;AACH,SAAgB,kBAAkB,CAAC,MAAuB;IACxD,OAAO,IAAI,+BAAoB,CAAC;QAC9B,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS;QAChD,GAAG,EAAE,MAAM,CAAC,GAAG;QACf,GAAG,EAAE,MAAM,CAAC,GAAG;KAChB,CAA6B,CAAC;AACjC,CAAC;AAED;;;GAGG;AACH,SAAgB,iBAAiB,CAAC,GAAQ,EAAE,OAAgC;IAC1E,OAAO,IAAI,iDAA6B,CAAC,GAAG,EAAE;QAC5C,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,SAAS;KAC/C,CAA6B,CAAC;AACjC,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/**\n * **The single `@modelcontextprotocol/sdk` import site for the entire package.**\n *\n * Every other module in `@fgv/ts-extras-mcp` depends only on the minimal local projection\n * exported here (`ISdkClient`, `ISdkTransport`, the three `make*` factories) — never on the SDK\n * directly. This keeps the announced v2 client-package rename a one-file change and lets unit\n * tests mock this module instead of the SDK internals (no live server required).\n *\n * The only `as unknown as` casts in the package live here, at the boundary where the real SDK\n * objects are narrowed to the local projection.\n *\n * @internal\n */\n\nimport { Client } from '@modelcontextprotocol/sdk/client/index.js';\nimport { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';\nimport { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';\n\n/**\n * Opaque transport handle. The concrete value is an SDK `Transport`; consumers of this module\n * treat it as opaque and only ever hand it back to {@link makeClient}-produced clients.\n * @internal\n */\nexport type ISdkTransport = object;\n\n/**\n * A single content block in an MCP `CallToolResult`. Only `text` blocks carry inline content;\n * all other block types are projected to a structural summary by the operations layer.\n * @internal\n */\nexport interface ISdkContentBlock {\n readonly type: string;\n readonly text?: string;\n}\n\n/**\n * Projection of the SDK's `CallToolResult`.\n * @internal\n */\nexport interface ISdkCallToolResult {\n readonly content?: ReadonlyArray<ISdkContentBlock>;\n readonly isError?: boolean;\n}\n\n/**\n * Projection of a single tool descriptor in the SDK's `ListToolsResult`.\n * @internal\n */\nexport interface ISdkToolDescriptor {\n readonly name: string;\n readonly description?: string;\n readonly inputSchema?: unknown;\n}\n\n/**\n * Projection of the SDK's `ListToolsResult` (one page).\n * @internal\n */\nexport interface ISdkListToolsResult {\n readonly tools: ReadonlyArray<ISdkToolDescriptor>;\n readonly nextCursor?: string;\n}\n\n/**\n * Server identity returned by the SDK's `getServerVersion()` after the initialize handshake.\n * @internal\n */\nexport interface ISdkImplementation {\n readonly name: string;\n readonly version: string;\n}\n\n/**\n * Minimal projection of the SDK `Client` surface the package depends on.\n * @internal\n */\nexport interface ISdkClient {\n connect(transport: ISdkTransport): Promise<void>;\n getServerVersion(): ISdkImplementation | undefined;\n listTools(params?: { cursor?: string }): Promise<ISdkListToolsResult>;\n callTool(params: { name: string; arguments?: Record<string, unknown> }): Promise<ISdkCallToolResult>;\n close(): Promise<void>;\n}\n\n/**\n * Parameters for the stdio transport factory.\n * @internal\n */\nexport interface ISdkStdioParams {\n readonly command: string;\n readonly args?: ReadonlyArray<string>;\n readonly env?: Record<string, string>;\n readonly cwd?: string;\n}\n\n/**\n * Constructs an MCP client. The `as unknown as` cast is the package's single SDK-type\n * bridge — the runtime object is a real SDK `Client`.\n * @internal\n */\nexport function makeClient(name: string, version: string): ISdkClient {\n return new Client({ name, version }, { capabilities: {} }) as unknown as ISdkClient;\n}\n\n/**\n * Constructs a stdio transport that spawns the given command as a subprocess.\n * @internal\n */\nexport function makeStdioTransport(params: ISdkStdioParams): ISdkTransport {\n return new StdioClientTransport({\n command: params.command,\n args: params.args ? [...params.args] : undefined,\n env: params.env,\n cwd: params.cwd\n }) as unknown as ISdkTransport;\n}\n\n/**\n * Constructs a Streamable-HTTP transport for the given URL, with optional static headers.\n * @internal\n */\nexport function makeHttpTransport(url: URL, headers?: Record<string, string>): ISdkTransport {\n return new StreamableHTTPClientTransport(url, {\n requestInit: headers ? { headers } : undefined\n }) as unknown as ISdkTransport;\n}\n"]}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Session lifecycle — connect / close, converting the throwing SDK calls into `Result<T>`.
3
+ * @packageDocumentation
4
+ */
5
+ import { type Result } from '@fgv/ts-utils';
6
+ import { type IConnectMcpSessionParams, type IMcpServerInfo, type IMcpSession } from './model';
7
+ import { type ISdkClient } from './sdk';
8
+ /**
9
+ * Concrete session handle. Packlet-internal — carries the live SDK client that the operations
10
+ * layer recovers via {@link McpSession.fromHandle}. Not exported from the package barrel.
11
+ * @internal
12
+ */
13
+ export declare class McpSession implements IMcpSession {
14
+ readonly clientName: string;
15
+ readonly clientVersion: string;
16
+ readonly serverInfo: IMcpServerInfo | undefined;
17
+ /** The live SDK client. */
18
+ readonly client: ISdkClient;
19
+ constructor(client: ISdkClient, clientName: string, clientVersion: string, serverInfo: IMcpServerInfo | undefined);
20
+ /**
21
+ * Narrows a public {@link IMcpSession} handle back to the concrete {@link McpSession}. Fails
22
+ * loudly when handed a foreign object that did not originate from {@link connectMcpSession}.
23
+ */
24
+ static fromHandle(handle: IMcpSession): Result<McpSession>;
25
+ }
26
+ /**
27
+ * Connects to an MCP server over the given transport and performs the initialize handshake.
28
+ *
29
+ * @param params - Transport plus optional client identity and logger.
30
+ * @returns `Success` with an opaque {@link IMcpSession}, or `Failure` if the transport handle is
31
+ * foreign or the connection/handshake fails.
32
+ * @public
33
+ */
34
+ export declare function connectMcpSession(params: IConnectMcpSessionParams): Promise<Result<IMcpSession>>;
35
+ /**
36
+ * Closes an MCP session, tearing down the transport (and any spawned subprocess).
37
+ *
38
+ * @param session - A session from {@link connectMcpSession}.
39
+ * @returns `Success(true)`, or `Failure` if the handle is foreign or the close call throws.
40
+ * @public
41
+ */
42
+ export declare function closeMcpSession(session: IMcpSession): Promise<Result<true>>;
43
+ //# sourceMappingURL=session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../../src/packlets/mcp/session.ts"],"names":[],"mappings":"AAsBA;;;GAGG;AAEH,OAAO,EAAE,KAAK,MAAM,EAAqC,MAAM,eAAe,CAAC;AAE/E,OAAO,EAAE,KAAK,wBAAwB,EAAE,KAAK,cAAc,EAAE,KAAK,WAAW,EAAE,MAAM,SAAS,CAAC;AAC/F,OAAO,EAAE,KAAK,UAAU,EAAc,MAAM,OAAO,CAAC;AAgBpD;;;;GAIG;AACH,qBAAa,UAAW,YAAW,WAAW;IAC5C,SAAgB,UAAU,EAAE,MAAM,CAAC;IACnC,SAAgB,aAAa,EAAE,MAAM,CAAC;IACtC,SAAgB,UAAU,EAAE,cAAc,GAAG,SAAS,CAAC;IACvD,2BAA2B;IAC3B,SAAgB,MAAM,EAAE,UAAU,CAAC;gBAGjC,MAAM,EAAE,UAAU,EAClB,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,MAAM,EACrB,UAAU,EAAE,cAAc,GAAG,SAAS;IAQxC;;;OAGG;WACW,UAAU,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC;CAMlE;AAED;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CAAC,MAAM,EAAE,wBAAwB,GAAG,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CA6BtG;AAED;;;;;;GAMG;AACH,wBAAsB,eAAe,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAQjF"}
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2026 Erik Fortune
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in all
13
+ * copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ * SOFTWARE.
22
+ */
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.McpSession = void 0;
25
+ exports.connectMcpSession = connectMcpSession;
26
+ exports.closeMcpSession = closeMcpSession;
27
+ /**
28
+ * Session lifecycle — connect / close, converting the throwing SDK calls into `Result<T>`.
29
+ * @packageDocumentation
30
+ */
31
+ const ts_utils_1 = require("@fgv/ts-utils");
32
+ const sdk_1 = require("./sdk");
33
+ const transports_1 = require("./transports");
34
+ /** Default client name advertised during the initialize handshake. */
35
+ const DEFAULT_CLIENT_NAME = '@fgv/ts-extras-mcp';
36
+ /**
37
+ * Default client version advertised during the initialize handshake.
38
+ *
39
+ * @remarks
40
+ * Keep in sync with this package's `package.json` version on each release. It is informational
41
+ * only — MCP servers use it for logging/telemetry, not for behavior — so a drift is low-impact,
42
+ * but it should be bumped alongside the lockstep version. (Reading it from `package.json` at
43
+ * runtime is avoided to keep the bundle free of a JSON import / `require` of the manifest.)
44
+ */
45
+ const DEFAULT_CLIENT_VERSION = '5.1.0';
46
+ /**
47
+ * Concrete session handle. Packlet-internal — carries the live SDK client that the operations
48
+ * layer recovers via {@link McpSession.fromHandle}. Not exported from the package barrel.
49
+ * @internal
50
+ */
51
+ class McpSession {
52
+ constructor(client, clientName, clientVersion, serverInfo) {
53
+ this.client = client;
54
+ this.clientName = clientName;
55
+ this.clientVersion = clientVersion;
56
+ this.serverInfo = serverInfo;
57
+ }
58
+ /**
59
+ * Narrows a public {@link IMcpSession} handle back to the concrete {@link McpSession}. Fails
60
+ * loudly when handed a foreign object that did not originate from {@link connectMcpSession}.
61
+ */
62
+ static fromHandle(handle) {
63
+ if (handle instanceof McpSession) {
64
+ return (0, ts_utils_1.succeed)(handle);
65
+ }
66
+ return (0, ts_utils_1.fail)('invalid MCP session: expected a handle from connectMcpSession');
67
+ }
68
+ }
69
+ exports.McpSession = McpSession;
70
+ /**
71
+ * Connects to an MCP server over the given transport and performs the initialize handshake.
72
+ *
73
+ * @param params - Transport plus optional client identity and logger.
74
+ * @returns `Success` with an opaque {@link IMcpSession}, or `Failure` if the transport handle is
75
+ * foreign or the connection/handshake fails.
76
+ * @public
77
+ */
78
+ async function connectMcpSession(params) {
79
+ const { transport, clientName, clientVersion, logger } = params;
80
+ const transportResult = transports_1.McpTransport.fromHandle(transport);
81
+ if (transportResult.isFailure()) {
82
+ return (0, ts_utils_1.fail)(`connectMcpSession: ${transportResult.message}`);
83
+ }
84
+ const name = clientName !== null && clientName !== void 0 ? clientName : DEFAULT_CLIENT_NAME;
85
+ const version = clientVersion !== null && clientVersion !== void 0 ? clientVersion : DEFAULT_CLIENT_VERSION;
86
+ const client = (0, sdk_1.makeClient)(name, version);
87
+ logger === null || logger === void 0 ? void 0 : logger.info(`mcp: connecting (client ${name}@${version}, transport ${transportResult.value.transportKind})`);
88
+ return (0, ts_utils_1.captureAsyncResult)(() => client.connect(transportResult.value.sdkTransport))
89
+ .onSuccess(() => {
90
+ const raw = client.getServerVersion();
91
+ const serverInfo = raw !== undefined ? { name: raw.name, version: raw.version } : undefined;
92
+ logger === null || logger === void 0 ? void 0 : logger.info(serverInfo !== undefined
93
+ ? `mcp: connected to server ${serverInfo.name}@${serverInfo.version}`
94
+ : 'mcp: connected (server did not report identity)');
95
+ return (0, ts_utils_1.succeed)(new McpSession(client, name, version, serverInfo));
96
+ })
97
+ .withErrorFormat((msg) => `connectMcpSession: ${msg}`);
98
+ }
99
+ /**
100
+ * Closes an MCP session, tearing down the transport (and any spawned subprocess).
101
+ *
102
+ * @param session - A session from {@link connectMcpSession}.
103
+ * @returns `Success(true)`, or `Failure` if the handle is foreign or the close call throws.
104
+ * @public
105
+ */
106
+ async function closeMcpSession(session) {
107
+ const sessionResult = McpSession.fromHandle(session);
108
+ if (sessionResult.isFailure()) {
109
+ return (0, ts_utils_1.fail)(`closeMcpSession: ${sessionResult.message}`);
110
+ }
111
+ return (0, ts_utils_1.captureAsyncResult)(() => sessionResult.value.client.close())
112
+ .onSuccess(() => (0, ts_utils_1.succeed)(true))
113
+ .withErrorFormat((msg) => `closeMcpSession: ${msg}`);
114
+ }
115
+ //# sourceMappingURL=session.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.js","sourceRoot":"","sources":["../../../src/packlets/mcp/session.ts"],"names":[],"mappings":";A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CAAC,CAAC;IAC3D,CAAC;IACD,OAAO,IAAA,6BAAkB,EAAC,GAAG,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;SAChE,SAAS,CAAC,GAAG,EAAE,CAAC,IAAA,kBAAO,EAAC,IAAa,CAAC,CAAC;SACvC,eAAe,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,oBAAoB,GAAG,EAAE,CAAC,CAAC;AACzD,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/**\n * Session lifecycle — connect / close, converting the throwing SDK calls into `Result<T>`.\n * @packageDocumentation\n */\n\nimport { type Result, captureAsyncResult, fail, succeed } from '@fgv/ts-utils';\n\nimport { type IConnectMcpSessionParams, type IMcpServerInfo, type IMcpSession } from './model';\nimport { type ISdkClient, makeClient } from './sdk';\nimport { McpTransport } from './transports';\n\n/** Default client name advertised during the initialize handshake. */\nconst DEFAULT_CLIENT_NAME: string = '@fgv/ts-extras-mcp';\n/**\n * Default client version advertised during the initialize handshake.\n *\n * @remarks\n * Keep in sync with this package's `package.json` version on each release. It is informational\n * only — MCP servers use it for logging/telemetry, not for behavior — so a drift is low-impact,\n * but it should be bumped alongside the lockstep version. (Reading it from `package.json` at\n * runtime is avoided to keep the bundle free of a JSON import / `require` of the manifest.)\n */\nconst DEFAULT_CLIENT_VERSION: string = '5.1.0';\n\n/**\n * Concrete session handle. Packlet-internal — carries the live SDK client that the operations\n * layer recovers via {@link McpSession.fromHandle}. Not exported from the package barrel.\n * @internal\n */\nexport class McpSession implements IMcpSession {\n public readonly clientName: string;\n public readonly clientVersion: string;\n public readonly serverInfo: IMcpServerInfo | undefined;\n /** The live SDK client. */\n public readonly client: ISdkClient;\n\n public constructor(\n client: ISdkClient,\n clientName: string,\n clientVersion: string,\n serverInfo: IMcpServerInfo | undefined\n ) {\n this.client = client;\n this.clientName = clientName;\n this.clientVersion = clientVersion;\n this.serverInfo = serverInfo;\n }\n\n /**\n * Narrows a public {@link IMcpSession} handle back to the concrete {@link McpSession}. Fails\n * loudly when handed a foreign object that did not originate from {@link connectMcpSession}.\n */\n public static fromHandle(handle: IMcpSession): Result<McpSession> {\n if (handle instanceof McpSession) {\n return succeed(handle);\n }\n return fail('invalid MCP session: expected a handle from connectMcpSession');\n }\n}\n\n/**\n * Connects to an MCP server over the given transport and performs the initialize handshake.\n *\n * @param params - Transport plus optional client identity and logger.\n * @returns `Success` with an opaque {@link IMcpSession}, or `Failure` if the transport handle is\n * foreign or the connection/handshake fails.\n * @public\n */\nexport async function connectMcpSession(params: IConnectMcpSessionParams): Promise<Result<IMcpSession>> {\n const { transport, clientName, clientVersion, logger } = params;\n\n const transportResult = McpTransport.fromHandle(transport);\n if (transportResult.isFailure()) {\n return fail(`connectMcpSession: ${transportResult.message}`);\n }\n\n const name = clientName ?? DEFAULT_CLIENT_NAME;\n const version = clientVersion ?? DEFAULT_CLIENT_VERSION;\n const client = makeClient(name, version);\n\n logger?.info(\n `mcp: connecting (client ${name}@${version}, transport ${transportResult.value.transportKind})`\n );\n\n return captureAsyncResult(() => client.connect(transportResult.value.sdkTransport))\n .onSuccess(() => {\n const raw = client.getServerVersion();\n const serverInfo: IMcpServerInfo | undefined =\n raw !== undefined ? { name: raw.name, version: raw.version } : undefined;\n logger?.info(\n serverInfo !== undefined\n ? `mcp: connected to server ${serverInfo.name}@${serverInfo.version}`\n : 'mcp: connected (server did not report identity)'\n );\n return succeed<IMcpSession>(new McpSession(client, name, version, serverInfo));\n })\n .withErrorFormat((msg) => `connectMcpSession: ${msg}`);\n}\n\n/**\n * Closes an MCP session, tearing down the transport (and any spawned subprocess).\n *\n * @param session - A session from {@link connectMcpSession}.\n * @returns `Success(true)`, or `Failure` if the handle is foreign or the close call throws.\n * @public\n */\nexport async function closeMcpSession(session: IMcpSession): Promise<Result<true>> {\n const sessionResult = McpSession.fromHandle(session);\n if (sessionResult.isFailure()) {\n return fail(`closeMcpSession: ${sessionResult.message}`);\n }\n return captureAsyncResult(() => sessionResult.value.client.close())\n .onSuccess(() => succeed(true as const))\n .withErrorFormat((msg) => `closeMcpSession: ${msg}`);\n}\n"]}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Transport factories — convert the throwing SDK transport constructors into `Result<T>`.
3
+ * @packageDocumentation
4
+ */
5
+ import { type Result } from '@fgv/ts-utils';
6
+ import { type IMcpHttpTransportParams, type IMcpStdioTransportParams, type IMcpTransport } from './model';
7
+ import { type ISdkTransport } from './sdk';
8
+ /**
9
+ * Concrete transport handle. Packlet-internal — carries the SDK transport that
10
+ * {@link McpTransport.fromHandle} recovers inside {@link connectMcpSession}. Not exported from
11
+ * the package barrel, so it does not appear in the public API surface.
12
+ * @internal
13
+ */
14
+ export declare class McpTransport implements IMcpTransport {
15
+ readonly transportKind: 'stdio' | 'http';
16
+ /** The wrapped SDK transport. */
17
+ readonly sdkTransport: ISdkTransport;
18
+ constructor(transportKind: 'stdio' | 'http', sdkTransport: ISdkTransport);
19
+ /**
20
+ * Narrows a public {@link IMcpTransport} handle back to the concrete {@link McpTransport}.
21
+ * Fails loudly when handed a foreign object that did not originate from one of this
22
+ * package's transport factories.
23
+ */
24
+ static fromHandle(handle: IMcpTransport): Result<McpTransport>;
25
+ }
26
+ /**
27
+ * Creates a stdio MCP transport that speaks MCP over the stdin/stdout of a spawned subprocess.
28
+ *
29
+ * @remarks
30
+ * **Security — trust boundary.** The transport spawns `params.command` (with `params.args`) as a
31
+ * child process. Never source the command or arguments from untrusted input; treat them with the
32
+ * same care as any shell-out. See the package README's security note.
33
+ *
34
+ * @param params - The command, arguments, environment, and working directory.
35
+ * @returns `Success` with an opaque transport handle, or `Failure` if the SDK constructor throws
36
+ * (e.g. an empty command).
37
+ * @public
38
+ */
39
+ export declare function createStdioTransport(params: IMcpStdioTransportParams): Result<IMcpTransport>;
40
+ /**
41
+ * Creates a Streamable-HTTP MCP transport for the given endpoint URL.
42
+ *
43
+ * @param params - The endpoint URL and optional static headers.
44
+ * @returns `Success` with an opaque transport handle, or `Failure` if the URL is invalid or the
45
+ * SDK constructor throws.
46
+ * @public
47
+ */
48
+ export declare function createHttpTransport(params: IMcpHttpTransportParams): Result<IMcpTransport>;
49
+ //# sourceMappingURL=transports.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transports.d.ts","sourceRoot":"","sources":["../../../src/packlets/mcp/transports.ts"],"names":[],"mappings":"AAsBA;;;GAGG;AAEH,OAAO,EAAE,KAAK,MAAM,EAAgC,MAAM,eAAe,CAAC;AAE1E,OAAO,EAAE,KAAK,uBAAuB,EAAE,KAAK,wBAAwB,EAAE,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AAC1G,OAAO,EAAE,KAAK,aAAa,EAAyC,MAAM,OAAO,CAAC;AAElF;;;;;GAKG;AACH,qBAAa,YAAa,YAAW,aAAa;IAChD,SAAgB,aAAa,EAAE,OAAO,GAAG,MAAM,CAAC;IAChD,iCAAiC;IACjC,SAAgB,YAAY,EAAE,aAAa,CAAC;gBAEzB,aAAa,EAAE,OAAO,GAAG,MAAM,EAAE,YAAY,EAAE,aAAa;IAK/E;;;;OAIG;WACW,UAAU,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,CAAC,YAAY,CAAC;CAMtE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,wBAAwB,GAAG,MAAM,CAAC,aAAa,CAAC,CAc5F;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,uBAAuB,GAAG,MAAM,CAAC,aAAa,CAAC,CAY1F"}
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2026 Erik Fortune
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in all
13
+ * copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ * SOFTWARE.
22
+ */
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.McpTransport = void 0;
25
+ exports.createStdioTransport = createStdioTransport;
26
+ exports.createHttpTransport = createHttpTransport;
27
+ /**
28
+ * Transport factories — convert the throwing SDK transport constructors into `Result<T>`.
29
+ * @packageDocumentation
30
+ */
31
+ const ts_utils_1 = require("@fgv/ts-utils");
32
+ const sdk_1 = require("./sdk");
33
+ /**
34
+ * Concrete transport handle. Packlet-internal — carries the SDK transport that
35
+ * {@link McpTransport.fromHandle} recovers inside {@link connectMcpSession}. Not exported from
36
+ * the package barrel, so it does not appear in the public API surface.
37
+ * @internal
38
+ */
39
+ class McpTransport {
40
+ constructor(transportKind, sdkTransport) {
41
+ this.transportKind = transportKind;
42
+ this.sdkTransport = sdkTransport;
43
+ }
44
+ /**
45
+ * Narrows a public {@link IMcpTransport} handle back to the concrete {@link McpTransport}.
46
+ * Fails loudly when handed a foreign object that did not originate from one of this
47
+ * package's transport factories.
48
+ */
49
+ static fromHandle(handle) {
50
+ if (handle instanceof McpTransport) {
51
+ return (0, ts_utils_1.succeed)(handle);
52
+ }
53
+ return (0, ts_utils_1.fail)('invalid MCP transport: expected a handle from createStdioTransport / createHttpTransport');
54
+ }
55
+ }
56
+ exports.McpTransport = McpTransport;
57
+ /**
58
+ * Creates a stdio MCP transport that speaks MCP over the stdin/stdout of a spawned subprocess.
59
+ *
60
+ * @remarks
61
+ * **Security — trust boundary.** The transport spawns `params.command` (with `params.args`) as a
62
+ * child process. Never source the command or arguments from untrusted input; treat them with the
63
+ * same care as any shell-out. See the package README's security note.
64
+ *
65
+ * @param params - The command, arguments, environment, and working directory.
66
+ * @returns `Success` with an opaque transport handle, or `Failure` if the SDK constructor throws
67
+ * (e.g. an empty command).
68
+ * @public
69
+ */
70
+ function createStdioTransport(params) {
71
+ if (params.command.trim().length === 0) {
72
+ return (0, ts_utils_1.fail)('createStdioTransport: command must be a non-empty string');
73
+ }
74
+ return (0, ts_utils_1.captureResult)(() => (0, sdk_1.makeStdioTransport)({
75
+ command: params.command,
76
+ args: params.args,
77
+ env: params.env,
78
+ cwd: params.cwd
79
+ }))
80
+ .onSuccess((sdkTransport) => (0, ts_utils_1.succeed)(new McpTransport('stdio', sdkTransport)))
81
+ .withErrorFormat((msg) => `createStdioTransport: ${msg}`);
82
+ }
83
+ /**
84
+ * Creates a Streamable-HTTP MCP transport for the given endpoint URL.
85
+ *
86
+ * @param params - The endpoint URL and optional static headers.
87
+ * @returns `Success` with an opaque transport handle, or `Failure` if the URL is invalid or the
88
+ * SDK constructor throws.
89
+ * @public
90
+ */
91
+ function createHttpTransport(params) {
92
+ return (0, ts_utils_1.captureResult)(() => new URL(params.url))
93
+ .withErrorFormat(() => `invalid url '${params.url}'`)
94
+ .onSuccess((url) => {
95
+ if (url.protocol !== 'http:' && url.protocol !== 'https:') {
96
+ return (0, ts_utils_1.fail)(`url must use http or https protocol (got '${url.protocol}')`);
97
+ }
98
+ return (0, ts_utils_1.captureResult)(() => (0, sdk_1.makeHttpTransport)(url, params.headers)).onSuccess((sdkTransport) => (0, ts_utils_1.succeed)(new McpTransport('http', sdkTransport)));
99
+ })
100
+ .withErrorFormat((msg) => `createHttpTransport: ${msg}`);
101
+ }
102
+ //# sourceMappingURL=transports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transports.js","sourceRoot":"","sources":["../../../src/packlets/mcp/transports.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAsDH,oDAcC;AAUD,kDAYC;AAxFD;;;GAGG;AAEH,4CAA0E;AAG1E,+BAAkF;AAElF;;;;;GAKG;AACH,MAAa,YAAY;IAKvB,YAAmB,aAA+B,EAAE,YAA2B;QAC7E,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,UAAU,CAAC,MAAqB;QAC5C,IAAI,MAAM,YAAY,YAAY,EAAE,CAAC;YACnC,OAAO,IAAA,kBAAO,EAAC,MAAM,CAAC,CAAC;QACzB,CAAC;QACD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AA,uBAAiB,EAAC,GAAG,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,YAAY,EAAE,EAAE,CAC5F,IAAA,kBAAO,EAAgB,IAAI,YAAY,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAC/D,CAAC;IACJ,CAAC,CAAC;SACD,eAAe,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,wBAAwB,GAAG,EAAE,CAAC,CAAC;AAC7D,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/**\n * Transport factories — convert the throwing SDK transport constructors into `Result<T>`.\n * @packageDocumentation\n */\n\nimport { type Result, captureResult, fail, succeed } from '@fgv/ts-utils';\n\nimport { type IMcpHttpTransportParams, type IMcpStdioTransportParams, type IMcpTransport } from './model';\nimport { type ISdkTransport, makeHttpTransport, makeStdioTransport } from './sdk';\n\n/**\n * Concrete transport handle. Packlet-internal — carries the SDK transport that\n * {@link McpTransport.fromHandle} recovers inside {@link connectMcpSession}. Not exported from\n * the package barrel, so it does not appear in the public API surface.\n * @internal\n */\nexport class McpTransport implements IMcpTransport {\n public readonly transportKind: 'stdio' | 'http';\n /** The wrapped SDK transport. */\n public readonly sdkTransport: ISdkTransport;\n\n public constructor(transportKind: 'stdio' | 'http', sdkTransport: ISdkTransport) {\n this.transportKind = transportKind;\n this.sdkTransport = sdkTransport;\n }\n\n /**\n * Narrows a public {@link IMcpTransport} handle back to the concrete {@link McpTransport}.\n * Fails loudly when handed a foreign object that did not originate from one of this\n * package's transport factories.\n */\n public static fromHandle(handle: IMcpTransport): Result<McpTransport> {\n if (handle instanceof McpTransport) {\n return succeed(handle);\n }\n return fail('invalid MCP transport: expected a handle from createStdioTransport / createHttpTransport');\n }\n}\n\n/**\n * Creates a stdio MCP transport that speaks MCP over the stdin/stdout of a spawned subprocess.\n *\n * @remarks\n * **Security — trust boundary.** The transport spawns `params.command` (with `params.args`) as a\n * child process. Never source the command or arguments from untrusted input; treat them with the\n * same care as any shell-out. See the package README's security note.\n *\n * @param params - The command, arguments, environment, and working directory.\n * @returns `Success` with an opaque transport handle, or `Failure` if the SDK constructor throws\n * (e.g. an empty command).\n * @public\n */\nexport function createStdioTransport(params: IMcpStdioTransportParams): Result<IMcpTransport> {\n if (params.command.trim().length === 0) {\n return fail('createStdioTransport: command must be a non-empty string');\n }\n return captureResult(() =>\n makeStdioTransport({\n command: params.command,\n args: params.args,\n env: params.env,\n cwd: params.cwd\n })\n )\n .onSuccess((sdkTransport) => succeed<IMcpTransport>(new McpTransport('stdio', sdkTransport)))\n .withErrorFormat((msg) => `createStdioTransport: ${msg}`);\n}\n\n/**\n * Creates a Streamable-HTTP MCP transport for the given endpoint URL.\n *\n * @param params - The endpoint URL and optional static headers.\n * @returns `Success` with an opaque transport handle, or `Failure` if the URL is invalid or the\n * SDK constructor throws.\n * @public\n */\nexport function createHttpTransport(params: IMcpHttpTransportParams): Result<IMcpTransport> {\n return captureResult(() => new URL(params.url))\n .withErrorFormat(() => `invalid url '${params.url}'`)\n .onSuccess((url): Result<IMcpTransport> => {\n if (url.protocol !== 'http:' && url.protocol !== 'https:') {\n return fail(`url must use http or https protocol (got '${url.protocol}')`);\n }\n return captureResult(() => makeHttpTransport(url, params.headers)).onSuccess((sdkTransport) =>\n succeed<IMcpTransport>(new McpTransport('http', sdkTransport))\n );\n })\n .withErrorFormat((msg) => `createHttpTransport: ${msg}`);\n}\n"]}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * End-to-end verification against a REAL in-memory MCP server (the SDK's `Server` +
3
+ * `InMemoryTransport.createLinkedPair()`) — NOT a mocked SDK. This is the durable proof that the
4
+ * brief's two load-bearing constraints actually flow through the full stack: the real SDK `Client`,
5
+ * the real initialize handshake, the real `listTools`/`callTool` round-trips, the `sdk.ts`
6
+ * projection casts, and `adaptMcpTools`' `JsonSchema.fromJson` gate. It is the class of gap that
7
+ * 100%-line-coverage of a mocked seam cannot catch (e.g. a projection-shape mismatch in `sdk.ts`).
8
+ *
9
+ * The fixture server advertises a MIX of tools: two adaptable, and one for each JSON Schema feature
10
+ * `JsonSchema.fromJson` rejects ($ref, oneOf, anyOf, pattern, union `type[]`).
11
+ */
12
+ import '@fgv/ts-utils-jest';
13
+ //# sourceMappingURL=endToEnd.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endToEnd.test.d.ts","sourceRoot":"","sources":["../../../src/test/unit/endToEnd.test.ts"],"names":[],"mappings":"AAsBA;;;;;;;;;;GAUG;AAEH,OAAO,oBAAoB,CAAC"}