@lspeasy/core 1.0.1
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/LICENSE +21 -0
- package/README.md +550 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/jsonrpc/framing.d.ts +32 -0
- package/dist/jsonrpc/framing.d.ts.map +1 -0
- package/dist/jsonrpc/framing.js +96 -0
- package/dist/jsonrpc/framing.js.map +1 -0
- package/dist/jsonrpc/messages.d.ts +64 -0
- package/dist/jsonrpc/messages.d.ts.map +1 -0
- package/dist/jsonrpc/messages.js +23 -0
- package/dist/jsonrpc/messages.js.map +1 -0
- package/dist/jsonrpc/reader.d.ts +44 -0
- package/dist/jsonrpc/reader.d.ts.map +1 -0
- package/dist/jsonrpc/reader.js +107 -0
- package/dist/jsonrpc/reader.js.map +1 -0
- package/dist/jsonrpc/schemas.d.ts +103 -0
- package/dist/jsonrpc/schemas.d.ts.map +1 -0
- package/dist/jsonrpc/schemas.js +66 -0
- package/dist/jsonrpc/schemas.js.map +1 -0
- package/dist/jsonrpc/writer.d.ts +43 -0
- package/dist/jsonrpc/writer.d.ts.map +1 -0
- package/dist/jsonrpc/writer.js +110 -0
- package/dist/jsonrpc/writer.js.map +1 -0
- package/dist/middleware/compose.d.ts +3 -0
- package/dist/middleware/compose.d.ts.map +1 -0
- package/dist/middleware/compose.js +16 -0
- package/dist/middleware/compose.js.map +1 -0
- package/dist/middleware/index.d.ts +6 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/index.js +5 -0
- package/dist/middleware/index.js.map +1 -0
- package/dist/middleware/pipeline.d.ts +5 -0
- package/dist/middleware/pipeline.d.ts.map +1 -0
- package/dist/middleware/pipeline.js +54 -0
- package/dist/middleware/pipeline.js.map +1 -0
- package/dist/middleware/scoped.d.ts +9 -0
- package/dist/middleware/scoped.d.ts.map +1 -0
- package/dist/middleware/scoped.js +20 -0
- package/dist/middleware/scoped.js.map +1 -0
- package/dist/middleware/typed.d.ts +3 -0
- package/dist/middleware/typed.d.ts.map +1 -0
- package/dist/middleware/typed.js +18 -0
- package/dist/middleware/typed.js.map +1 -0
- package/dist/middleware/types.d.ts +45 -0
- package/dist/middleware/types.d.ts.map +1 -0
- package/dist/middleware/types.js +2 -0
- package/dist/middleware/types.js.map +1 -0
- package/dist/protocol/capabilities.d.ts +93 -0
- package/dist/protocol/capabilities.d.ts.map +1 -0
- package/dist/protocol/capabilities.js +143 -0
- package/dist/protocol/capabilities.js.map +1 -0
- package/dist/protocol/capability-methods.d.ts +270 -0
- package/dist/protocol/capability-methods.d.ts.map +1 -0
- package/dist/protocol/capability-methods.js +14 -0
- package/dist/protocol/capability-methods.js.map +1 -0
- package/dist/protocol/enums.d.ts +336 -0
- package/dist/protocol/enums.d.ts.map +1 -0
- package/dist/protocol/enums.js +417 -0
- package/dist/protocol/enums.js.map +1 -0
- package/dist/protocol/infer.d.ts +112 -0
- package/dist/protocol/infer.d.ts.map +1 -0
- package/dist/protocol/infer.js +58 -0
- package/dist/protocol/infer.js.map +1 -0
- package/dist/protocol/namespaces.d.ts +1432 -0
- package/dist/protocol/namespaces.d.ts.map +1 -0
- package/dist/protocol/namespaces.js +570 -0
- package/dist/protocol/namespaces.js.map +1 -0
- package/dist/protocol/partial.d.ts +29 -0
- package/dist/protocol/partial.d.ts.map +1 -0
- package/dist/protocol/partial.js +24 -0
- package/dist/protocol/partial.js.map +1 -0
- package/dist/protocol/progress.d.ts +32 -0
- package/dist/protocol/progress.d.ts.map +1 -0
- package/dist/protocol/progress.js +60 -0
- package/dist/protocol/progress.js.map +1 -0
- package/dist/protocol/schemas.d.ts +534 -0
- package/dist/protocol/schemas.d.ts.map +1 -0
- package/dist/protocol/schemas.js +271 -0
- package/dist/protocol/schemas.js.map +1 -0
- package/dist/protocol/types.d.ts +19 -0
- package/dist/protocol/types.d.ts.map +1 -0
- package/dist/protocol/types.js +8 -0
- package/dist/protocol/types.js.map +1 -0
- package/dist/protocol/watching.d.ts +29 -0
- package/dist/protocol/watching.d.ts.map +1 -0
- package/dist/protocol/watching.js +36 -0
- package/dist/protocol/watching.js.map +1 -0
- package/dist/protocol/workspace.d.ts +24 -0
- package/dist/protocol/workspace.d.ts.map +1 -0
- package/dist/protocol/workspace.js +26 -0
- package/dist/protocol/workspace.js.map +1 -0
- package/dist/transport/events.d.ts +27 -0
- package/dist/transport/events.d.ts.map +1 -0
- package/dist/transport/events.js +34 -0
- package/dist/transport/events.js.map +1 -0
- package/dist/transport/stdio.d.ts +55 -0
- package/dist/transport/stdio.d.ts.map +1 -0
- package/dist/transport/stdio.js +147 -0
- package/dist/transport/stdio.js.map +1 -0
- package/dist/transport/transport.d.ts +38 -0
- package/dist/transport/transport.d.ts.map +1 -0
- package/dist/transport/transport.js +5 -0
- package/dist/transport/transport.js.map +1 -0
- package/dist/transport/websocket.d.ts +142 -0
- package/dist/transport/websocket.d.ts.map +1 -0
- package/dist/transport/websocket.js +324 -0
- package/dist/transport/websocket.js.map +1 -0
- package/dist/utils/cancellation.d.ts +47 -0
- package/dist/utils/cancellation.d.ts.map +1 -0
- package/dist/utils/cancellation.js +77 -0
- package/dist/utils/cancellation.js.map +1 -0
- package/dist/utils/disposable-event-emitter.d.ts +26 -0
- package/dist/utils/disposable-event-emitter.d.ts.map +1 -0
- package/dist/utils/disposable-event-emitter.js +62 -0
- package/dist/utils/disposable-event-emitter.js.map +1 -0
- package/dist/utils/disposable.d.ts +34 -0
- package/dist/utils/disposable.d.ts.map +1 -0
- package/dist/utils/disposable.js +55 -0
- package/dist/utils/disposable.js.map +1 -0
- package/dist/utils/document.d.ts +20 -0
- package/dist/utils/document.d.ts.map +1 -0
- package/dist/utils/document.js +54 -0
- package/dist/utils/document.js.map +1 -0
- package/dist/utils/errors.d.ts +69 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +104 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/handler-registry.d.ts +35 -0
- package/dist/utils/handler-registry.d.ts.map +1 -0
- package/dist/utils/handler-registry.js +68 -0
- package/dist/utils/handler-registry.js.map +1 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/internal.d.ts +3 -0
- package/dist/utils/internal.d.ts.map +1 -0
- package/dist/utils/internal.js +3 -0
- package/dist/utils/internal.js.map +1 -0
- package/dist/utils/logger.d.ts +47 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +61 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/pending-request-tracker.d.ts +36 -0
- package/dist/utils/pending-request-tracker.d.ts.map +1 -0
- package/dist/utils/pending-request-tracker.js +93 -0
- package/dist/utils/pending-request-tracker.js.map +1 -0
- package/dist/utils/transport-attachment.d.ts +34 -0
- package/dist/utils/transport-attachment.d.ts.map +1 -0
- package/dist/utils/transport-attachment.js +48 -0
- package/dist/utils/transport-attachment.js.map +1 -0
- package/package.json +87 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"framing.d.ts","sourceRoot":"","sources":["../../src/jsonrpc/framing.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAE7C;;GAEG;AACH,eAAO,MAAM,qBAAqB,mBAAmB,CAAC;AACtD,eAAO,MAAM,mBAAmB,iBAAiB,CAAC;AAClD,eAAO,MAAM,oBAAoB,8CAA8C,CAAC;AAEhF;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,MAAM,GACb;IAAE,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CA+B5D;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAwC3F;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAiBzD"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON-RPC 2.0 message framing with Content-Length headers
|
|
3
|
+
* Pattern: MCP SDK's parseMessage with header parsing
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Header constants
|
|
7
|
+
*/
|
|
8
|
+
export const CONTENT_LENGTH_HEADER = 'Content-Length';
|
|
9
|
+
export const CONTENT_TYPE_HEADER = 'Content-Type';
|
|
10
|
+
export const DEFAULT_CONTENT_TYPE = 'application/vscode-jsonrpc; charset=utf-8';
|
|
11
|
+
/**
|
|
12
|
+
* Parse headers from buffer
|
|
13
|
+
* Format: "Header-Name: value\r\n"
|
|
14
|
+
*/
|
|
15
|
+
export function parseHeaders(buffer) {
|
|
16
|
+
const headers = new Map();
|
|
17
|
+
let offset = 0;
|
|
18
|
+
while (offset < buffer.length) {
|
|
19
|
+
// Look for \r\n\r\n (end of headers)
|
|
20
|
+
const lineEnd = buffer.indexOf('\r\n', offset);
|
|
21
|
+
if (lineEnd === -1) {
|
|
22
|
+
return null; // Incomplete headers
|
|
23
|
+
}
|
|
24
|
+
// Empty line signals end of headers
|
|
25
|
+
if (lineEnd === offset) {
|
|
26
|
+
return { headers, bodyStart: offset + 2 }; // Skip \r\n
|
|
27
|
+
}
|
|
28
|
+
// Parse header line
|
|
29
|
+
const line = buffer.toString('utf8', offset, lineEnd);
|
|
30
|
+
const colonIndex = line.indexOf(':');
|
|
31
|
+
if (colonIndex === -1) {
|
|
32
|
+
throw new Error(`Invalid header line: ${line}`);
|
|
33
|
+
}
|
|
34
|
+
const name = line.substring(0, colonIndex).trim();
|
|
35
|
+
const value = line.substring(colonIndex + 1).trim();
|
|
36
|
+
headers.set(name, value);
|
|
37
|
+
offset = lineEnd + 2; // Skip \r\n
|
|
38
|
+
}
|
|
39
|
+
return null; // Incomplete headers
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Parse a complete message from buffer
|
|
43
|
+
* Returns { message, bytesRead } or null if incomplete
|
|
44
|
+
*/
|
|
45
|
+
export function parseMessage(buffer) {
|
|
46
|
+
// Parse headers
|
|
47
|
+
const headerResult = parseHeaders(buffer);
|
|
48
|
+
if (!headerResult) {
|
|
49
|
+
return null; // Incomplete headers
|
|
50
|
+
}
|
|
51
|
+
const { headers, bodyStart } = headerResult;
|
|
52
|
+
// Extract Content-Length
|
|
53
|
+
const contentLengthStr = headers.get(CONTENT_LENGTH_HEADER);
|
|
54
|
+
if (!contentLengthStr) {
|
|
55
|
+
throw new Error('Missing Content-Length header');
|
|
56
|
+
}
|
|
57
|
+
const contentLength = parseInt(contentLengthStr, 10);
|
|
58
|
+
if (Number.isNaN(contentLength) || contentLength < 0) {
|
|
59
|
+
throw new Error(`Invalid Content-Length: ${contentLengthStr}`);
|
|
60
|
+
}
|
|
61
|
+
// Check if we have the full body
|
|
62
|
+
const totalLength = bodyStart + contentLength;
|
|
63
|
+
if (buffer.length < totalLength) {
|
|
64
|
+
return null; // Incomplete body
|
|
65
|
+
}
|
|
66
|
+
// Extract and parse JSON body
|
|
67
|
+
const bodyBuffer = buffer.subarray(bodyStart, totalLength);
|
|
68
|
+
const bodyStr = bodyBuffer.toString('utf8');
|
|
69
|
+
let message;
|
|
70
|
+
try {
|
|
71
|
+
message = JSON.parse(bodyStr);
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
throw new Error(`Failed to parse JSON-RPC message: ${error instanceof Error ? error.message : String(error)}`);
|
|
75
|
+
}
|
|
76
|
+
return { message, bytesRead: totalLength };
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Serialize a message to buffer with headers
|
|
80
|
+
*/
|
|
81
|
+
export function serializeMessage(message) {
|
|
82
|
+
// Serialize JSON body
|
|
83
|
+
const bodyStr = JSON.stringify(message);
|
|
84
|
+
const bodyBuffer = Buffer.from(bodyStr, 'utf8');
|
|
85
|
+
// Build headers
|
|
86
|
+
const headers = [
|
|
87
|
+
`${CONTENT_LENGTH_HEADER}: ${bodyBuffer.length}`,
|
|
88
|
+
`${CONTENT_TYPE_HEADER}: ${DEFAULT_CONTENT_TYPE}`,
|
|
89
|
+
'',
|
|
90
|
+
''
|
|
91
|
+
].join('\r\n');
|
|
92
|
+
const headerBuffer = Buffer.from(headers, 'utf8');
|
|
93
|
+
// Combine headers + body
|
|
94
|
+
return Buffer.concat([headerBuffer, bodyBuffer]);
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=framing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"framing.js","sourceRoot":"","sources":["../../src/jsonrpc/framing.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,gBAAgB,CAAC;AACtD,MAAM,CAAC,MAAM,mBAAmB,GAAG,cAAc,CAAC;AAClD,MAAM,CAAC,MAAM,oBAAoB,GAAG,2CAA2C,CAAC;AAEhF;;;GAGG;AACH,MAAM,UAAU,YAAY,CAC1B,MAAc,EAC8C;IAC5D,MAAM,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC1C,IAAI,MAAM,GAAG,CAAC,CAAC;IAEf,OAAO,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;QAC9B,qCAAqC;QACrC,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC/C,IAAI,OAAO,KAAK,CAAC,CAAC,EAAE,CAAC;YACnB,OAAO,IAAI,CAAC,CAAC,qBAAqB;QACpC,CAAC;QAED,oCAAoC;QACpC,IAAI,OAAO,KAAK,MAAM,EAAE,CAAC;YACvB,OAAO,E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mBAAmB,KAAK,oBAAoB,EAAE;QACjD,EAAE;QACF,EAAE;KACH,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAEf,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAElD,yBAAyB;IACzB,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC,CAAC;AAAA,CAClD"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON-RPC 2.0 message types following MCP SDK patterns
|
|
3
|
+
* Custom implementation without vscode-jsonrpc dependency
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Base JSON-RPC 2.0 message
|
|
7
|
+
*/
|
|
8
|
+
export interface BaseMessage {
|
|
9
|
+
jsonrpc: '2.0';
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* JSON-RPC 2.0 Request Message
|
|
13
|
+
*/
|
|
14
|
+
export interface RequestMessage extends BaseMessage {
|
|
15
|
+
id: string | number;
|
|
16
|
+
method: string;
|
|
17
|
+
params?: unknown;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* JSON-RPC 2.0 Notification Message (no response expected)
|
|
21
|
+
*/
|
|
22
|
+
export interface NotificationMessage extends BaseMessage {
|
|
23
|
+
method: string;
|
|
24
|
+
params?: unknown;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* JSON-RPC 2.0 Response Error
|
|
28
|
+
*/
|
|
29
|
+
export interface ResponseError {
|
|
30
|
+
code: number;
|
|
31
|
+
message: string;
|
|
32
|
+
data?: unknown;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* JSON-RPC 2.0 Success Response Message
|
|
36
|
+
*/
|
|
37
|
+
export interface SuccessResponseMessage extends BaseMessage {
|
|
38
|
+
id: string | number;
|
|
39
|
+
result: unknown;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* JSON-RPC 2.0 Error Response Message
|
|
43
|
+
*/
|
|
44
|
+
export interface ErrorResponseMessage extends BaseMessage {
|
|
45
|
+
id: string | number;
|
|
46
|
+
error: ResponseError;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* JSON-RPC 2.0 Response Message (success or error)
|
|
50
|
+
*/
|
|
51
|
+
export type ResponseMessage = SuccessResponseMessage | ErrorResponseMessage;
|
|
52
|
+
/**
|
|
53
|
+
* Union of all JSON-RPC message types
|
|
54
|
+
*/
|
|
55
|
+
export type Message = RequestMessage | NotificationMessage | ResponseMessage;
|
|
56
|
+
/**
|
|
57
|
+
* Type guards for message discrimination
|
|
58
|
+
*/
|
|
59
|
+
export declare function isRequestMessage(message: Message): message is RequestMessage;
|
|
60
|
+
export declare function isNotificationMessage(message: Message): message is NotificationMessage;
|
|
61
|
+
export declare function isResponseMessage(message: Message): message is ResponseMessage;
|
|
62
|
+
export declare function isSuccessResponse(message: ResponseMessage): message is SuccessResponseMessage;
|
|
63
|
+
export declare function isErrorResponse(message: ResponseMessage): message is ErrorResponseMessage;
|
|
64
|
+
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/jsonrpc/messages.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,KAAK,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,cAAe,SAAQ,WAAW;IACjD,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAoB,SAAQ,WAAW;IACtD,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,sBAAuB,SAAQ,WAAW;IACzD,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,MAAM,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,WAAW;IACvD,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,KAAK,EAAE,aAAa,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,sBAAsB,GAAG,oBAAoB,CAAC;AAE5E;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,cAAc,GAAG,mBAAmB,GAAG,eAAe,CAAC;AAE7E;;GAEG;AAEH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,IAAI,cAAc,CAE5E;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,IAAI,mBAAmB,CAEtF;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,IAAI,eAAe,CAE9E;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,IAAI,sBAAsB,CAE7F;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,IAAI,oBAAoB,CAEzF"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON-RPC 2.0 message types following MCP SDK patterns
|
|
3
|
+
* Custom implementation without vscode-jsonrpc dependency
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Type guards for message discrimination
|
|
7
|
+
*/
|
|
8
|
+
export function isRequestMessage(message) {
|
|
9
|
+
return 'id' in message && 'method' in message;
|
|
10
|
+
}
|
|
11
|
+
export function isNotificationMessage(message) {
|
|
12
|
+
return 'method' in message && !('id' in message);
|
|
13
|
+
}
|
|
14
|
+
export function isResponseMessage(message) {
|
|
15
|
+
return 'id' in message && !('method' in message);
|
|
16
|
+
}
|
|
17
|
+
export function isSuccessResponse(message) {
|
|
18
|
+
return 'result' in message;
|
|
19
|
+
}
|
|
20
|
+
export function isErrorResponse(message) {
|
|
21
|
+
return 'error' in message;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=messages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/jsonrpc/messages.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA6DH;;GAEG;AAEH,MAAM,UAAU,gBAAgB,CAAC,OAAgB,EAA6B;IAC5E,OAAO,IAAI,IAAI,OAAO,IAAI,QAAQ,IAAI,OAAO,CAAC;AAAA,CAC/C;AAED,MAAM,UAAU,qBAAqB,CAAC,OAAgB,EAAkC;IACtF,OAAO,QAAQ,IAAI,OAAO,IAAI,CAAC,CAAC,IAAI,IAAI,OAAO,CAAC,CAAC;AAAA,CAClD;AAED,MAAM,UAAU,iBAAiB,CAAC,OAAgB,EAA8B;IAC9E,OAAO,IAAI,IAAI,OAAO,IAAI,CAAC,CAAC,QAAQ,IAAI,OAAO,CAAC,CAAC;AAAA,CAClD;AAED,MAAM,UAAU,iBAAiB,CAAC,OAAwB,EAAqC;IAC7F,OAAO,QAAQ,IAAI,OAAO,CAAC;AAAA,CAC5B;AAED,MAAM,UAAU,eAAe,CAAC,OAAwB,EAAmC;IACzF,OAAO,OAAO,IAAI,OAAO,CAAC;AAAA,CAC3B"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MessageReader class for parsing JSON-RPC messages with framing
|
|
3
|
+
* Pattern: MCP SDK's JSONRPCMessage handling
|
|
4
|
+
*/
|
|
5
|
+
import { EventEmitter } from 'node:events';
|
|
6
|
+
import type { Readable } from 'node:stream';
|
|
7
|
+
/**
|
|
8
|
+
* MessageReader reads JSON-RPC messages from a stream
|
|
9
|
+
*/
|
|
10
|
+
export declare class MessageReader extends EventEmitter {
|
|
11
|
+
private readonly stream;
|
|
12
|
+
private buffer;
|
|
13
|
+
private closed;
|
|
14
|
+
constructor(stream: Readable);
|
|
15
|
+
/**
|
|
16
|
+
* Handle incoming data
|
|
17
|
+
*/
|
|
18
|
+
private onData;
|
|
19
|
+
/**
|
|
20
|
+
* Parse all complete messages from buffer
|
|
21
|
+
*/
|
|
22
|
+
private parseMessages;
|
|
23
|
+
/**
|
|
24
|
+
* Handle stream error
|
|
25
|
+
*/
|
|
26
|
+
private onError;
|
|
27
|
+
/**
|
|
28
|
+
* Handle stream end
|
|
29
|
+
*/
|
|
30
|
+
private onEnd;
|
|
31
|
+
/**
|
|
32
|
+
* Handle stream close
|
|
33
|
+
*/
|
|
34
|
+
private onClose;
|
|
35
|
+
/**
|
|
36
|
+
* Close the reader
|
|
37
|
+
*/
|
|
38
|
+
close(): void;
|
|
39
|
+
/**
|
|
40
|
+
* Check if reader is closed
|
|
41
|
+
*/
|
|
42
|
+
isClosed(): boolean;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=reader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reader.d.ts","sourceRoot":"","sources":["../../src/jsonrpc/reader.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAG5C;;GAEG;AACH,qBAAa,aAAc,SAAQ,YAAY;IAIjC,OAAO,CAAC,QAAQ,CAAC,MAAM;IAHnC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,MAAM,CAAU;IAExB,YAA6B,MAAM,EAAE,QAAQ,EAU5C;IAED;;OAEG;IACH,OAAO,CAAC,MAAM;IAYd;;OAEG;IACH,OAAO,CAAC,aAAa;IA0BrB;;OAEG;IACH,OAAO,CAAC,OAAO;IAMf;;OAEG;IACH,OAAO,CAAC,KAAK;IAMb;;OAEG;IACH,OAAO,CAAC,OAAO;IAMf;;OAEG;IACH,KAAK,IAAI,IAAI,CAaZ;IAED;;OAEG;IACH,QAAQ,IAAI,OAAO,CAElB;CACF"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MessageReader class for parsing JSON-RPC messages with framing
|
|
3
|
+
* Pattern: MCP SDK's JSONRPCMessage handling
|
|
4
|
+
*/
|
|
5
|
+
import { EventEmitter } from 'node:events';
|
|
6
|
+
import { parseMessage } from './framing.js';
|
|
7
|
+
/**
|
|
8
|
+
* MessageReader reads JSON-RPC messages from a stream
|
|
9
|
+
*/
|
|
10
|
+
export class MessageReader extends EventEmitter {
|
|
11
|
+
stream;
|
|
12
|
+
buffer;
|
|
13
|
+
closed;
|
|
14
|
+
constructor(stream) {
|
|
15
|
+
super();
|
|
16
|
+
this.stream = stream;
|
|
17
|
+
this.buffer = Buffer.alloc(0);
|
|
18
|
+
this.closed = false;
|
|
19
|
+
// Set up stream event handlers
|
|
20
|
+
this.stream.on('data', this.onData.bind(this));
|
|
21
|
+
this.stream.on('error', this.onError.bind(this));
|
|
22
|
+
this.stream.on('end', this.onEnd.bind(this));
|
|
23
|
+
this.stream.on('close', this.onClose.bind(this));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Handle incoming data
|
|
27
|
+
*/
|
|
28
|
+
onData(chunk) {
|
|
29
|
+
if (this.closed) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
// Append to buffer
|
|
33
|
+
this.buffer = Buffer.concat([this.buffer, chunk]);
|
|
34
|
+
// Try to parse messages
|
|
35
|
+
this.parseMessages();
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Parse all complete messages from buffer
|
|
39
|
+
*/
|
|
40
|
+
parseMessages() {
|
|
41
|
+
while (this.buffer.length > 0 && !this.closed) {
|
|
42
|
+
try {
|
|
43
|
+
const result = parseMessage(this.buffer);
|
|
44
|
+
if (!result) {
|
|
45
|
+
// Incomplete message, wait for more data
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
const { message, bytesRead } = result;
|
|
49
|
+
// Emit message
|
|
50
|
+
this.emit('message', message);
|
|
51
|
+
// Remove parsed bytes from buffer
|
|
52
|
+
this.buffer = this.buffer.subarray(bytesRead);
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
this.emit('error', error instanceof Error ? error : new Error(String(error)));
|
|
56
|
+
// Clear buffer on parse error
|
|
57
|
+
this.buffer = Buffer.alloc(0);
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Handle stream error
|
|
64
|
+
*/
|
|
65
|
+
onError(error) {
|
|
66
|
+
if (!this.closed) {
|
|
67
|
+
this.emit('error', error);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Handle stream end
|
|
72
|
+
*/
|
|
73
|
+
onEnd() {
|
|
74
|
+
if (!this.closed) {
|
|
75
|
+
this.close();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Handle stream close
|
|
80
|
+
*/
|
|
81
|
+
onClose() {
|
|
82
|
+
if (!this.closed) {
|
|
83
|
+
this.close();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Close the reader
|
|
88
|
+
*/
|
|
89
|
+
close() {
|
|
90
|
+
if (this.closed) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
this.closed = true;
|
|
94
|
+
this.buffer = Buffer.alloc(0);
|
|
95
|
+
// Remove stream listeners
|
|
96
|
+
this.stream.removeAllListeners();
|
|
97
|
+
// Emit close event
|
|
98
|
+
this.emit('close');
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Check if reader is closed
|
|
102
|
+
*/
|
|
103
|
+
isClosed() {
|
|
104
|
+
return this.closed;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=reader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reader.js","sourceRoot":"","sources":["../../src/jsonrpc/reader.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,YAAY;IAIhB,MAAM;IAH3B,MAAM,CAAS;IACf,MAAM,CAAU;IAExB,YAA6B,MAAgB,EAAE;QAC7C,KAAK,EAAE,CAAC;sBADmB,MAAM;QAEjC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC9B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QAEpB,+BAA+B;QAC/B,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAC/C,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACjD,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAC7C,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAAA,CAClD;IAED;;OAEG;IACK,MAAM,CAAC,KAAa,EAAQ;QAClC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,OAAO;QACT,CAAC;QAED,mBAAmB;QACnB,I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,GAAS;QACpB,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,IAAI,CAAC,KAAK,EAAE,CAAC;QACf,CAAC;IAAA,CACF;IAED;;OAEG;IACK,OAAO,GAAS;QACtB,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,IAAI,CAAC,KAAK,EAAE,CAAC;QACf,CAAC;IAAA,CACF;IAED;;OAEG;IACH,KAAK,GAAS;QACZ,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,OAAO;QACT,CAAC;QAED,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAE9B,0BAA0B;QAC1B,IAAI,CAAC,MAAM,CAAC,kBAAkB,EAAE,CAAC;QAEjC,mBAAmB;QACnB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAAA,CACpB;IAED;;OAEG;IACH,QAAQ,GAAY;QAClB,OAAO,IAAI,CAAC,MAAM,CAAC;IAAA,CACpB;CACF"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod schemas for JSON-RPC message validation
|
|
3
|
+
* Pattern: MCP SDK's z.discriminatedUnion for message types
|
|
4
|
+
*/
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
/**
|
|
7
|
+
* Schema for JSON-RPC 2.0 Request Message
|
|
8
|
+
*/
|
|
9
|
+
export declare const requestMessageSchema: z.ZodObject<{
|
|
10
|
+
jsonrpc: z.ZodLiteral<"2.0">;
|
|
11
|
+
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
12
|
+
method: z.ZodString;
|
|
13
|
+
params: z.ZodOptional<z.ZodUnknown>;
|
|
14
|
+
}, z.core.$strip>;
|
|
15
|
+
/**
|
|
16
|
+
* Schema for JSON-RPC 2.0 Notification Message
|
|
17
|
+
*/
|
|
18
|
+
export declare const notificationMessageSchema: z.ZodObject<{
|
|
19
|
+
jsonrpc: z.ZodLiteral<"2.0">;
|
|
20
|
+
method: z.ZodString;
|
|
21
|
+
params: z.ZodOptional<z.ZodUnknown>;
|
|
22
|
+
}, z.core.$strip>;
|
|
23
|
+
/**
|
|
24
|
+
* Schema for JSON-RPC 2.0 Response Error
|
|
25
|
+
*/
|
|
26
|
+
export declare const responseErrorSchema: z.ZodObject<{
|
|
27
|
+
code: z.ZodNumber;
|
|
28
|
+
message: z.ZodString;
|
|
29
|
+
data: z.ZodOptional<z.ZodUnknown>;
|
|
30
|
+
}, z.core.$strip>;
|
|
31
|
+
/**
|
|
32
|
+
* Schema for JSON-RPC 2.0 Success Response Message
|
|
33
|
+
*/
|
|
34
|
+
export declare const successResponseMessageSchema: z.ZodObject<{
|
|
35
|
+
jsonrpc: z.ZodLiteral<"2.0">;
|
|
36
|
+
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
37
|
+
result: z.ZodUnknown;
|
|
38
|
+
}, z.core.$strip>;
|
|
39
|
+
/**
|
|
40
|
+
* Schema for JSON-RPC 2.0 Error Response Message
|
|
41
|
+
*/
|
|
42
|
+
export declare const errorResponseMessageSchema: z.ZodObject<{
|
|
43
|
+
jsonrpc: z.ZodLiteral<"2.0">;
|
|
44
|
+
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
45
|
+
error: z.ZodObject<{
|
|
46
|
+
code: z.ZodNumber;
|
|
47
|
+
message: z.ZodString;
|
|
48
|
+
data: z.ZodOptional<z.ZodUnknown>;
|
|
49
|
+
}, z.core.$strip>;
|
|
50
|
+
}, z.core.$strip>;
|
|
51
|
+
/**
|
|
52
|
+
* Schema for JSON-RPC 2.0 Response Message (success or error)
|
|
53
|
+
*/
|
|
54
|
+
export declare const responseMessageSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
55
|
+
jsonrpc: z.ZodLiteral<"2.0">;
|
|
56
|
+
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
57
|
+
result: z.ZodUnknown;
|
|
58
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
59
|
+
jsonrpc: z.ZodLiteral<"2.0">;
|
|
60
|
+
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
61
|
+
error: z.ZodObject<{
|
|
62
|
+
code: z.ZodNumber;
|
|
63
|
+
message: z.ZodString;
|
|
64
|
+
data: z.ZodOptional<z.ZodUnknown>;
|
|
65
|
+
}, z.core.$strip>;
|
|
66
|
+
}, z.core.$strip>]>;
|
|
67
|
+
/**
|
|
68
|
+
* Schema for any JSON-RPC 2.0 Message
|
|
69
|
+
* Uses discriminated union based on presence of 'method' and 'id'
|
|
70
|
+
*/
|
|
71
|
+
export declare const messageSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
72
|
+
jsonrpc: z.ZodLiteral<"2.0">;
|
|
73
|
+
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
74
|
+
method: z.ZodString;
|
|
75
|
+
params: z.ZodOptional<z.ZodUnknown>;
|
|
76
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
77
|
+
jsonrpc: z.ZodLiteral<"2.0">;
|
|
78
|
+
method: z.ZodString;
|
|
79
|
+
params: z.ZodOptional<z.ZodUnknown>;
|
|
80
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
81
|
+
jsonrpc: z.ZodLiteral<"2.0">;
|
|
82
|
+
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
83
|
+
result: z.ZodUnknown;
|
|
84
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
85
|
+
jsonrpc: z.ZodLiteral<"2.0">;
|
|
86
|
+
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
87
|
+
error: z.ZodObject<{
|
|
88
|
+
code: z.ZodNumber;
|
|
89
|
+
message: z.ZodString;
|
|
90
|
+
data: z.ZodOptional<z.ZodUnknown>;
|
|
91
|
+
}, z.core.$strip>;
|
|
92
|
+
}, z.core.$strip>]>;
|
|
93
|
+
/**
|
|
94
|
+
* Type exports
|
|
95
|
+
*/
|
|
96
|
+
export type RequestMessage = z.infer<typeof requestMessageSchema>;
|
|
97
|
+
export type NotificationMessage = z.infer<typeof notificationMessageSchema>;
|
|
98
|
+
export type ResponseError = z.infer<typeof responseErrorSchema>;
|
|
99
|
+
export type SuccessResponseMessage = z.infer<typeof successResponseMessageSchema>;
|
|
100
|
+
export type ErrorResponseMessage = z.infer<typeof errorResponseMessageSchema>;
|
|
101
|
+
export type ResponseMessage = z.infer<typeof responseMessageSchema>;
|
|
102
|
+
export type Message = z.infer<typeof messageSchema>;
|
|
103
|
+
//# sourceMappingURL=schemas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../src/jsonrpc/schemas.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AASxB;;GAEG;AACH,eAAO,MAAM,oBAAoB;;;;;iBAI/B,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,yBAAyB;;;;iBAGpC,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,mBAAmB;;;;iBAI9B,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,4BAA4B;;;;iBAGvC,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,0BAA0B;;;;;;;;iBAGrC,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;mBAGhC,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;mBAKxB,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAClE,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAC5E,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAChE,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,4BAA4B,CAAC,CAAC;AAClF,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,0BAA0B,CAAC,CAAC;AAC9E,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AACpE,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod schemas for JSON-RPC message validation
|
|
3
|
+
* Pattern: MCP SDK's z.discriminatedUnion for message types
|
|
4
|
+
*/
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
/**
|
|
7
|
+
* Schema for JSON-RPC 2.0 base message
|
|
8
|
+
*/
|
|
9
|
+
const baseMessageSchema = z.object({
|
|
10
|
+
jsonrpc: z.literal('2.0')
|
|
11
|
+
});
|
|
12
|
+
/**
|
|
13
|
+
* Schema for JSON-RPC 2.0 Request Message
|
|
14
|
+
*/
|
|
15
|
+
export const requestMessageSchema = baseMessageSchema.extend({
|
|
16
|
+
id: z.union([z.string(), z.number()]),
|
|
17
|
+
method: z.string(),
|
|
18
|
+
params: z.unknown().optional()
|
|
19
|
+
});
|
|
20
|
+
/**
|
|
21
|
+
* Schema for JSON-RPC 2.0 Notification Message
|
|
22
|
+
*/
|
|
23
|
+
export const notificationMessageSchema = baseMessageSchema.extend({
|
|
24
|
+
method: z.string(),
|
|
25
|
+
params: z.unknown().optional()
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* Schema for JSON-RPC 2.0 Response Error
|
|
29
|
+
*/
|
|
30
|
+
export const responseErrorSchema = z.object({
|
|
31
|
+
code: z.number(),
|
|
32
|
+
message: z.string(),
|
|
33
|
+
data: z.unknown().optional()
|
|
34
|
+
});
|
|
35
|
+
/**
|
|
36
|
+
* Schema for JSON-RPC 2.0 Success Response Message
|
|
37
|
+
*/
|
|
38
|
+
export const successResponseMessageSchema = baseMessageSchema.extend({
|
|
39
|
+
id: z.union([z.string(), z.number()]),
|
|
40
|
+
result: z.unknown()
|
|
41
|
+
});
|
|
42
|
+
/**
|
|
43
|
+
* Schema for JSON-RPC 2.0 Error Response Message
|
|
44
|
+
*/
|
|
45
|
+
export const errorResponseMessageSchema = baseMessageSchema.extend({
|
|
46
|
+
id: z.union([z.string(), z.number()]),
|
|
47
|
+
error: responseErrorSchema
|
|
48
|
+
});
|
|
49
|
+
/**
|
|
50
|
+
* Schema for JSON-RPC 2.0 Response Message (success or error)
|
|
51
|
+
*/
|
|
52
|
+
export const responseMessageSchema = z.union([
|
|
53
|
+
successResponseMessageSchema,
|
|
54
|
+
errorResponseMessageSchema
|
|
55
|
+
]);
|
|
56
|
+
/**
|
|
57
|
+
* Schema for any JSON-RPC 2.0 Message
|
|
58
|
+
* Uses discriminated union based on presence of 'method' and 'id'
|
|
59
|
+
*/
|
|
60
|
+
export const messageSchema = z.union([
|
|
61
|
+
requestMessageSchema,
|
|
62
|
+
notificationMessageSchema,
|
|
63
|
+
successResponseMessageSchema,
|
|
64
|
+
errorResponseMessageSchema
|
|
65
|
+
]);
|
|
66
|
+
//# sourceMappingURL=schemas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../src/jsonrpc/schemas.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;GAEG;AACH,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACjC,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;CAC1B,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,CAAC,MA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AM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC;IAC3C,4BAA4B;IAC5B,0BAA0B;CAC3B,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC;IACnC,oBAAoB;IACpB,yBAAyB;IACzB,4BAA4B;IAC5B,0BAA0B;CAC3B,CAAC,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MessageWriter class for serializing JSON-RPC messages with framing
|
|
3
|
+
* Pattern: MCP SDK's message serialization
|
|
4
|
+
*/
|
|
5
|
+
import { EventEmitter } from 'node:events';
|
|
6
|
+
import type { Writable } from 'node:stream';
|
|
7
|
+
import type { Message } from './messages.js';
|
|
8
|
+
/**
|
|
9
|
+
* MessageWriter writes JSON-RPC messages to a stream
|
|
10
|
+
*/
|
|
11
|
+
export declare class MessageWriter extends EventEmitter {
|
|
12
|
+
private readonly stream;
|
|
13
|
+
private closed;
|
|
14
|
+
private writing;
|
|
15
|
+
private queue;
|
|
16
|
+
constructor(stream: Writable);
|
|
17
|
+
/**
|
|
18
|
+
* Write a message to the stream
|
|
19
|
+
*/
|
|
20
|
+
write(message: Message): Promise<void>;
|
|
21
|
+
private flush;
|
|
22
|
+
/**
|
|
23
|
+
* Write a buffer to the stream
|
|
24
|
+
*/
|
|
25
|
+
private writeBuffer;
|
|
26
|
+
/**
|
|
27
|
+
* Handle stream error
|
|
28
|
+
*/
|
|
29
|
+
private onError;
|
|
30
|
+
/**
|
|
31
|
+
* Handle stream close
|
|
32
|
+
*/
|
|
33
|
+
private onClose;
|
|
34
|
+
/**
|
|
35
|
+
* Close the writer
|
|
36
|
+
*/
|
|
37
|
+
close(): void;
|
|
38
|
+
/**
|
|
39
|
+
* Check if writer is closed
|
|
40
|
+
*/
|
|
41
|
+
isClosed(): boolean;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=writer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"writer.d.ts","sourceRoot":"","sources":["../../src/jsonrpc/writer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAE7C;;GAEG;AACH,qBAAa,aAAc,SAAQ,YAAY;IAKjC,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJnC,OAAO,CAAC,MAAM,CAAU;IACxB,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,KAAK,CAAW;IAExB,YAA6B,MAAM,EAAE,QAAQ,EAS5C;IAED;;OAEG;IACG,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAW3C;YAKa,KAAK;IAqBnB;;OAEG;IACH,OAAO,CAAC,WAAW;IAYnB;;OAEG;IACH,OAAO,CAAC,OAAO;IAMf;;OAEG;IACH,OAAO,CAAC,OAAO;IAMf;;OAEG;IACH,KAAK,IAAI,IAAI,CAaZ;IAED;;OAEG;IACH,QAAQ,IAAI,OAAO,CAElB;CACF"}
|