Add helper functions to distinguish between jsonRPC message types
This commit is contained in:
parent
df8701937d
commit
8215651552
1 changed files with 20 additions and 4 deletions
|
|
@ -3,6 +3,9 @@ import {
|
|||
CancelledNotificationSchema,
|
||||
ClientCapabilities,
|
||||
ErrorCode,
|
||||
isJSONRPCRequest,
|
||||
isJSONRPCResponse,
|
||||
isJSONRPCNotification,
|
||||
JSONRPCError,
|
||||
JSONRPCNotification,
|
||||
JSONRPCRequest,
|
||||
|
|
@ -271,12 +274,14 @@ export abstract class Protocol<
|
|||
};
|
||||
|
||||
this._transport.onmessage = (message) => {
|
||||
if (!("method" in message)) {
|
||||
if (isJSONRPCResponse(message)) {
|
||||
this._onresponse(message);
|
||||
} else if ("id" in message) {
|
||||
} else if (isJSONRPCRequest(message)) {
|
||||
this._onrequest(message);
|
||||
} else {
|
||||
} else if (isJSONRPCNotification(message)) {
|
||||
this._onnotification(message);
|
||||
} else {
|
||||
this._onerror(new Error(`Unknown message type: ${JSON.stringify(message)}`));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -437,7 +442,7 @@ export abstract class Protocol<
|
|||
this._progressHandlers.delete(messageId);
|
||||
this._cleanupTimeout(messageId);
|
||||
|
||||
if ("result" in response) {
|
||||
if (isJSONRPCResponse(response)) {
|
||||
handler(response);
|
||||
} else {
|
||||
const error = new McpError(
|
||||
|
|
|
|||
Loading…
Reference in a new issue