ai 0.0.0-85f9a635-20240518005312 → 0.0.0-9477ebb9-20250403064906

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 (70) hide show
  1. package/CHANGELOG.md +3521 -0
  2. package/README.md +112 -22
  3. package/dist/index.d.mts +3697 -1642
  4. package/dist/index.d.ts +3697 -1642
  5. package/dist/index.js +7201 -2942
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +7249 -2963
  8. package/dist/index.mjs.map +1 -1
  9. package/mcp-stdio/create-child-process.test.ts +92 -0
  10. package/mcp-stdio/create-child-process.ts +21 -0
  11. package/mcp-stdio/dist/index.d.mts +169 -0
  12. package/mcp-stdio/dist/index.d.ts +169 -0
  13. package/mcp-stdio/dist/index.js +352 -0
  14. package/mcp-stdio/dist/index.js.map +1 -0
  15. package/mcp-stdio/dist/index.mjs +337 -0
  16. package/mcp-stdio/dist/index.mjs.map +1 -0
  17. package/mcp-stdio/get-environment.ts +43 -0
  18. package/mcp-stdio/index.ts +4 -0
  19. package/mcp-stdio/mcp-stdio-transport.test.ts +262 -0
  20. package/mcp-stdio/mcp-stdio-transport.ts +157 -0
  21. package/package.json +46 -103
  22. package/react/dist/index.d.mts +10 -557
  23. package/react/dist/index.d.ts +10 -574
  24. package/react/dist/index.js +6 -1397
  25. package/react/dist/index.js.map +1 -1
  26. package/react/dist/index.mjs +10 -1384
  27. package/react/dist/index.mjs.map +1 -1
  28. package/rsc/dist/index.d.ts +432 -199
  29. package/rsc/dist/rsc-server.d.mts +431 -199
  30. package/rsc/dist/rsc-server.mjs +1599 -1357
  31. package/rsc/dist/rsc-server.mjs.map +1 -1
  32. package/rsc/dist/rsc-shared.d.mts +30 -23
  33. package/rsc/dist/rsc-shared.mjs +70 -108
  34. package/rsc/dist/rsc-shared.mjs.map +1 -1
  35. package/test/dist/index.d.mts +65 -0
  36. package/test/dist/index.d.ts +65 -0
  37. package/test/dist/index.js +121 -0
  38. package/test/dist/index.js.map +1 -0
  39. package/test/dist/index.mjs +94 -0
  40. package/test/dist/index.mjs.map +1 -0
  41. package/prompts/dist/index.d.mts +0 -324
  42. package/prompts/dist/index.d.ts +0 -324
  43. package/prompts/dist/index.js +0 -178
  44. package/prompts/dist/index.js.map +0 -1
  45. package/prompts/dist/index.mjs +0 -146
  46. package/prompts/dist/index.mjs.map +0 -1
  47. package/react/dist/index.server.d.mts +0 -17
  48. package/react/dist/index.server.d.ts +0 -17
  49. package/react/dist/index.server.js +0 -50
  50. package/react/dist/index.server.js.map +0 -1
  51. package/react/dist/index.server.mjs +0 -23
  52. package/react/dist/index.server.mjs.map +0 -1
  53. package/solid/dist/index.d.mts +0 -408
  54. package/solid/dist/index.d.ts +0 -408
  55. package/solid/dist/index.js +0 -1072
  56. package/solid/dist/index.js.map +0 -1
  57. package/solid/dist/index.mjs +0 -1044
  58. package/solid/dist/index.mjs.map +0 -1
  59. package/svelte/dist/index.d.mts +0 -484
  60. package/svelte/dist/index.d.ts +0 -484
  61. package/svelte/dist/index.js +0 -1778
  62. package/svelte/dist/index.js.map +0 -1
  63. package/svelte/dist/index.mjs +0 -1749
  64. package/svelte/dist/index.mjs.map +0 -1
  65. package/vue/dist/index.d.mts +0 -402
  66. package/vue/dist/index.d.ts +0 -402
  67. package/vue/dist/index.js +0 -1072
  68. package/vue/dist/index.js.map +0 -1
  69. package/vue/dist/index.mjs +0 -1034
  70. package/vue/dist/index.mjs.map +0 -1
@@ -0,0 +1,92 @@
1
+ import { beforeEach, vi } from 'vitest';
2
+ import * as getEnvironmentModule from './get-environment';
3
+
4
+ const DEFAULT_ENV = {
5
+ PATH: 'path',
6
+ };
7
+
8
+ const mockGetEnvironment = vi
9
+ .fn()
10
+ .mockImplementation((customEnv?: Record<string, string>) => {
11
+ return {
12
+ ...DEFAULT_ENV,
13
+ ...customEnv,
14
+ };
15
+ });
16
+ vi.spyOn(getEnvironmentModule, 'getEnvironment').mockImplementation(
17
+ mockGetEnvironment,
18
+ );
19
+
20
+ // important: import after mocking getEnv
21
+ const { createChildProcess } = await import('./create-child-process');
22
+
23
+ describe('createChildProcess', () => {
24
+ beforeEach(() => {
25
+ vi.clearAllMocks();
26
+ });
27
+
28
+ it('should spawn a child process', async () => {
29
+ const childProcess = await createChildProcess(
30
+ { command: process.execPath },
31
+ new AbortController().signal,
32
+ );
33
+
34
+ expect(childProcess.pid).toBeDefined();
35
+ expect(mockGetEnvironment).toHaveBeenCalledWith(undefined);
36
+ childProcess.kill();
37
+ });
38
+
39
+ it('should spawn a child process with custom env', async () => {
40
+ const customEnv = { FOO: 'bar' };
41
+ const childProcessWithCustomEnv = await createChildProcess(
42
+ { command: process.execPath, env: customEnv },
43
+ new AbortController().signal,
44
+ );
45
+
46
+ expect(childProcessWithCustomEnv.pid).toBeDefined();
47
+ expect(mockGetEnvironment).toHaveBeenCalledWith(customEnv);
48
+ expect(mockGetEnvironment).toHaveReturnedWith({
49
+ ...DEFAULT_ENV,
50
+ ...customEnv,
51
+ });
52
+ childProcessWithCustomEnv.kill();
53
+ });
54
+
55
+ it('should spawn a child process with args', async () => {
56
+ const childProcessWithArgs = await createChildProcess(
57
+ { command: process.execPath, args: ['-c', 'echo', 'test'] },
58
+ new AbortController().signal,
59
+ );
60
+
61
+ expect(childProcessWithArgs.pid).toBeDefined();
62
+ expect(childProcessWithArgs.spawnargs).toContain(process.execPath);
63
+ expect(childProcessWithArgs.spawnargs).toEqual([
64
+ process.execPath,
65
+ '-c',
66
+ 'echo',
67
+ 'test',
68
+ ]);
69
+ childProcessWithArgs.kill();
70
+ });
71
+
72
+ it('should spawn a child process with cwd', async () => {
73
+ const childProcessWithCwd = await createChildProcess(
74
+ { command: process.execPath, cwd: '/tmp' },
75
+ new AbortController().signal,
76
+ );
77
+
78
+ expect(childProcessWithCwd.pid).toBeDefined();
79
+ childProcessWithCwd.kill();
80
+ });
81
+
82
+ it('should spawn a child process with stderr', async () => {
83
+ const childProcessWithStderr = await createChildProcess(
84
+ { command: process.execPath, stderr: 'pipe' },
85
+ new AbortController().signal,
86
+ );
87
+
88
+ expect(childProcessWithStderr.pid).toBeDefined();
89
+ expect(childProcessWithStderr.stderr).toBeDefined();
90
+ childProcessWithStderr.kill();
91
+ });
92
+ });
@@ -0,0 +1,21 @@
1
+ import { ChildProcess, spawn } from 'node:child_process';
2
+ import { getEnvironment } from './get-environment';
3
+ import { StdioConfig } from './mcp-stdio-transport';
4
+
5
+ export async function createChildProcess(
6
+ config: StdioConfig,
7
+ signal: AbortSignal,
8
+ ): Promise<ChildProcess> {
9
+ return spawn(config.command, config.args ?? [], {
10
+ env: getEnvironment(config.env),
11
+ stdio: ['pipe', 'pipe', config.stderr ?? 'inherit'],
12
+ shell: false,
13
+ signal,
14
+ windowsHide: globalThis.process.platform === 'win32' && isElectron(),
15
+ cwd: config.cwd,
16
+ });
17
+ }
18
+
19
+ function isElectron() {
20
+ return 'type' in globalThis.process;
21
+ }
@@ -0,0 +1,169 @@
1
+ import { IOType } from 'node:child_process';
2
+ import { Stream } from 'node:stream';
3
+ import { z } from 'zod';
4
+
5
+ declare const JSONRPCMessageSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
6
+ jsonrpc: z.ZodLiteral<"2.0">;
7
+ id: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
8
+ }, {
9
+ method: z.ZodString;
10
+ params: z.ZodOptional<z.ZodObject<{
11
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
12
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
13
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
14
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
15
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
16
+ }, z.ZodTypeAny, "passthrough">>>;
17
+ }>, "strict", z.ZodTypeAny, {
18
+ method: string;
19
+ jsonrpc: "2.0";
20
+ id: string | number;
21
+ params?: z.objectOutputType<{
22
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
23
+ }, z.ZodTypeAny, "passthrough"> | undefined;
24
+ }, {
25
+ method: string;
26
+ jsonrpc: "2.0";
27
+ id: string | number;
28
+ params?: z.objectInputType<{
29
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
30
+ }, z.ZodTypeAny, "passthrough"> | undefined;
31
+ }>, z.ZodObject<z.objectUtil.extendShape<{
32
+ jsonrpc: z.ZodLiteral<"2.0">;
33
+ }, {
34
+ method: z.ZodString;
35
+ params: z.ZodOptional<z.ZodObject<{
36
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
37
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
38
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
39
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
40
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
41
+ }, z.ZodTypeAny, "passthrough">>>;
42
+ }>, "strict", z.ZodTypeAny, {
43
+ method: string;
44
+ jsonrpc: "2.0";
45
+ params?: z.objectOutputType<{
46
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
47
+ }, z.ZodTypeAny, "passthrough"> | undefined;
48
+ }, {
49
+ method: string;
50
+ jsonrpc: "2.0";
51
+ params?: z.objectInputType<{
52
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
53
+ }, z.ZodTypeAny, "passthrough"> | undefined;
54
+ }>, z.ZodObject<{
55
+ jsonrpc: z.ZodLiteral<"2.0">;
56
+ id: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
57
+ result: z.ZodObject<{
58
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
59
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
60
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
61
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
62
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
63
+ }, z.ZodTypeAny, "passthrough">>;
64
+ }, "strict", z.ZodTypeAny, {
65
+ result: {
66
+ _meta?: z.objectOutputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
67
+ } & {
68
+ [k: string]: unknown;
69
+ };
70
+ jsonrpc: "2.0";
71
+ id: string | number;
72
+ }, {
73
+ result: {
74
+ _meta?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
75
+ } & {
76
+ [k: string]: unknown;
77
+ };
78
+ jsonrpc: "2.0";
79
+ id: string | number;
80
+ }>, z.ZodObject<{
81
+ jsonrpc: z.ZodLiteral<"2.0">;
82
+ id: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
83
+ error: z.ZodObject<{
84
+ code: z.ZodNumber;
85
+ message: z.ZodString;
86
+ data: z.ZodOptional<z.ZodUnknown>;
87
+ }, "strip", z.ZodTypeAny, {
88
+ code: number;
89
+ message: string;
90
+ data?: unknown;
91
+ }, {
92
+ code: number;
93
+ message: string;
94
+ data?: unknown;
95
+ }>;
96
+ }, "strict", z.ZodTypeAny, {
97
+ error: {
98
+ code: number;
99
+ message: string;
100
+ data?: unknown;
101
+ };
102
+ jsonrpc: "2.0";
103
+ id: string | number;
104
+ }, {
105
+ error: {
106
+ code: number;
107
+ message: string;
108
+ data?: unknown;
109
+ };
110
+ jsonrpc: "2.0";
111
+ id: string | number;
112
+ }>]>;
113
+ type JSONRPCMessage = z.infer<typeof JSONRPCMessageSchema>;
114
+
115
+ /**
116
+ * Transport interface for MCP (Model Context Protocol) communication.
117
+ * Maps to the `Transport` interface in the MCP spec.
118
+ */
119
+ interface MCPTransport {
120
+ /**
121
+ * Initialize and start the transport
122
+ */
123
+ start(): Promise<void>;
124
+ /**
125
+ * Send a JSON-RPC message through the transport
126
+ * @param message The JSON-RPC message to send
127
+ */
128
+ send(message: JSONRPCMessage): Promise<void>;
129
+ /**
130
+ * Clean up and close the transport
131
+ */
132
+ close(): Promise<void>;
133
+ /**
134
+ * Event handler for transport closure
135
+ */
136
+ onclose?: () => void;
137
+ /**
138
+ * Event handler for transport errors
139
+ */
140
+ onerror?: (error: Error) => void;
141
+ /**
142
+ * Event handler for received messages
143
+ */
144
+ onmessage?: (message: JSONRPCMessage) => void;
145
+ }
146
+
147
+ interface StdioConfig {
148
+ command: string;
149
+ args?: string[];
150
+ env?: Record<string, string>;
151
+ stderr?: IOType | Stream | number;
152
+ cwd?: string;
153
+ }
154
+ declare class StdioMCPTransport implements MCPTransport {
155
+ private process?;
156
+ private abortController;
157
+ private readBuffer;
158
+ private serverParams;
159
+ onclose?: () => void;
160
+ onerror?: (error: unknown) => void;
161
+ onmessage?: (message: JSONRPCMessage) => void;
162
+ constructor(server: StdioConfig);
163
+ start(): Promise<void>;
164
+ private processReadBuffer;
165
+ close(): Promise<void>;
166
+ send(message: JSONRPCMessage): Promise<void>;
167
+ }
168
+
169
+ export { StdioMCPTransport as Experimental_StdioMCPTransport, StdioConfig };
@@ -0,0 +1,169 @@
1
+ import { IOType } from 'node:child_process';
2
+ import { Stream } from 'node:stream';
3
+ import { z } from 'zod';
4
+
5
+ declare const JSONRPCMessageSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
6
+ jsonrpc: z.ZodLiteral<"2.0">;
7
+ id: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
8
+ }, {
9
+ method: z.ZodString;
10
+ params: z.ZodOptional<z.ZodObject<{
11
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
12
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
13
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
14
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
15
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
16
+ }, z.ZodTypeAny, "passthrough">>>;
17
+ }>, "strict", z.ZodTypeAny, {
18
+ method: string;
19
+ jsonrpc: "2.0";
20
+ id: string | number;
21
+ params?: z.objectOutputType<{
22
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
23
+ }, z.ZodTypeAny, "passthrough"> | undefined;
24
+ }, {
25
+ method: string;
26
+ jsonrpc: "2.0";
27
+ id: string | number;
28
+ params?: z.objectInputType<{
29
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
30
+ }, z.ZodTypeAny, "passthrough"> | undefined;
31
+ }>, z.ZodObject<z.objectUtil.extendShape<{
32
+ jsonrpc: z.ZodLiteral<"2.0">;
33
+ }, {
34
+ method: z.ZodString;
35
+ params: z.ZodOptional<z.ZodObject<{
36
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
37
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
38
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
39
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
40
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
41
+ }, z.ZodTypeAny, "passthrough">>>;
42
+ }>, "strict", z.ZodTypeAny, {
43
+ method: string;
44
+ jsonrpc: "2.0";
45
+ params?: z.objectOutputType<{
46
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
47
+ }, z.ZodTypeAny, "passthrough"> | undefined;
48
+ }, {
49
+ method: string;
50
+ jsonrpc: "2.0";
51
+ params?: z.objectInputType<{
52
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
53
+ }, z.ZodTypeAny, "passthrough"> | undefined;
54
+ }>, z.ZodObject<{
55
+ jsonrpc: z.ZodLiteral<"2.0">;
56
+ id: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
57
+ result: z.ZodObject<{
58
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
59
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
60
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
61
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
62
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
63
+ }, z.ZodTypeAny, "passthrough">>;
64
+ }, "strict", z.ZodTypeAny, {
65
+ result: {
66
+ _meta?: z.objectOutputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
67
+ } & {
68
+ [k: string]: unknown;
69
+ };
70
+ jsonrpc: "2.0";
71
+ id: string | number;
72
+ }, {
73
+ result: {
74
+ _meta?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
75
+ } & {
76
+ [k: string]: unknown;
77
+ };
78
+ jsonrpc: "2.0";
79
+ id: string | number;
80
+ }>, z.ZodObject<{
81
+ jsonrpc: z.ZodLiteral<"2.0">;
82
+ id: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
83
+ error: z.ZodObject<{
84
+ code: z.ZodNumber;
85
+ message: z.ZodString;
86
+ data: z.ZodOptional<z.ZodUnknown>;
87
+ }, "strip", z.ZodTypeAny, {
88
+ code: number;
89
+ message: string;
90
+ data?: unknown;
91
+ }, {
92
+ code: number;
93
+ message: string;
94
+ data?: unknown;
95
+ }>;
96
+ }, "strict", z.ZodTypeAny, {
97
+ error: {
98
+ code: number;
99
+ message: string;
100
+ data?: unknown;
101
+ };
102
+ jsonrpc: "2.0";
103
+ id: string | number;
104
+ }, {
105
+ error: {
106
+ code: number;
107
+ message: string;
108
+ data?: unknown;
109
+ };
110
+ jsonrpc: "2.0";
111
+ id: string | number;
112
+ }>]>;
113
+ type JSONRPCMessage = z.infer<typeof JSONRPCMessageSchema>;
114
+
115
+ /**
116
+ * Transport interface for MCP (Model Context Protocol) communication.
117
+ * Maps to the `Transport` interface in the MCP spec.
118
+ */
119
+ interface MCPTransport {
120
+ /**
121
+ * Initialize and start the transport
122
+ */
123
+ start(): Promise<void>;
124
+ /**
125
+ * Send a JSON-RPC message through the transport
126
+ * @param message The JSON-RPC message to send
127
+ */
128
+ send(message: JSONRPCMessage): Promise<void>;
129
+ /**
130
+ * Clean up and close the transport
131
+ */
132
+ close(): Promise<void>;
133
+ /**
134
+ * Event handler for transport closure
135
+ */
136
+ onclose?: () => void;
137
+ /**
138
+ * Event handler for transport errors
139
+ */
140
+ onerror?: (error: Error) => void;
141
+ /**
142
+ * Event handler for received messages
143
+ */
144
+ onmessage?: (message: JSONRPCMessage) => void;
145
+ }
146
+
147
+ interface StdioConfig {
148
+ command: string;
149
+ args?: string[];
150
+ env?: Record<string, string>;
151
+ stderr?: IOType | Stream | number;
152
+ cwd?: string;
153
+ }
154
+ declare class StdioMCPTransport implements MCPTransport {
155
+ private process?;
156
+ private abortController;
157
+ private readBuffer;
158
+ private serverParams;
159
+ onclose?: () => void;
160
+ onerror?: (error: unknown) => void;
161
+ onmessage?: (message: JSONRPCMessage) => void;
162
+ constructor(server: StdioConfig);
163
+ start(): Promise<void>;
164
+ private processReadBuffer;
165
+ close(): Promise<void>;
166
+ send(message: JSONRPCMessage): Promise<void>;
167
+ }
168
+
169
+ export { StdioMCPTransport as Experimental_StdioMCPTransport, StdioConfig };