ai 0.0.0-8777c42a-20250115032312 → 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.
- package/CHANGELOG.md +660 -2
- package/README.md +19 -6
- package/dist/index.d.mts +3036 -1314
- package/dist/index.d.ts +3036 -1314
- package/dist/index.js +2705 -985
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2667 -962
- package/dist/index.mjs.map +1 -1
- package/mcp-stdio/create-child-process.test.ts +92 -0
- package/mcp-stdio/create-child-process.ts +21 -0
- package/mcp-stdio/dist/index.d.mts +169 -0
- package/mcp-stdio/dist/index.d.ts +169 -0
- package/mcp-stdio/dist/index.js +352 -0
- package/mcp-stdio/dist/index.js.map +1 -0
- package/mcp-stdio/dist/index.mjs +337 -0
- package/mcp-stdio/dist/index.mjs.map +1 -0
- package/mcp-stdio/get-environment.ts +43 -0
- package/mcp-stdio/index.ts +4 -0
- package/mcp-stdio/mcp-stdio-transport.test.ts +262 -0
- package/mcp-stdio/mcp-stdio-transport.ts +157 -0
- package/package.json +14 -10
- package/react/dist/index.d.mts +12 -4
- package/react/dist/index.d.ts +12 -4
- package/react/dist/index.js +0 -3
- package/react/dist/index.js.map +1 -1
- package/react/dist/index.mjs +0 -3
- package/react/dist/index.mjs.map +1 -1
- package/rsc/dist/index.d.ts +108 -18
- package/rsc/dist/rsc-server.d.mts +108 -18
- package/rsc/dist/rsc-server.mjs +550 -256
- package/rsc/dist/rsc-server.mjs.map +1 -1
- package/rsc/dist/rsc-shared.mjs +1 -3
- package/rsc/dist/rsc-shared.mjs.map +1 -1
- package/test/dist/index.d.mts +2 -4
- package/test/dist/index.d.ts +2 -4
- package/test/dist/index.js +4 -14
- package/test/dist/index.js.map +1 -1
- package/test/dist/index.mjs +7 -14
- package/test/dist/index.mjs.map +1 -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 };
|