File tree Expand file tree Collapse file tree 2 files changed +18
-14
lines changed Expand file tree Collapse file tree 2 files changed +18
-14
lines changed Original file line number Diff line number Diff line change 1
1
import {
2
- CONNECTION_CLOSED_ERROR ,
3
- INTERNAL_ERROR ,
2
+ ErrorCode ,
4
3
JSONRPCError ,
5
4
JSONRPCNotification ,
6
5
JSONRPCRequest ,
7
6
JSONRPCResponse ,
8
7
McpError ,
9
- METHOD_NOT_FOUND ,
10
8
Notification ,
11
9
PingRequestSchema ,
12
10
Progress ,
@@ -124,7 +122,7 @@ export class Protocol<
124
122
this . _transport = undefined ;
125
123
this . onclose ?.( ) ;
126
124
127
- const error = new McpError ( CONNECTION_CLOSED_ERROR , "Connection closed" ) ;
125
+ const error = new McpError ( ErrorCode . ConnectionClosed , "Connection closed" ) ;
128
126
for ( const handler of responseHandlers . values ( ) ) {
129
127
handler ( error ) ;
130
128
}
@@ -161,7 +159,7 @@ export class Protocol<
161
159
jsonrpc : "2.0" ,
162
160
id : request . id ,
163
161
error : {
164
- code : METHOD_NOT_FOUND ,
162
+ code : ErrorCode . MethodNotFound ,
165
163
message : "Method not found" ,
166
164
} ,
167
165
} )
@@ -189,7 +187,7 @@ export class Protocol<
189
187
error : {
190
188
code : error [ "code" ]
191
189
? Math . floor ( Number ( error [ "code" ] ) )
192
- : INTERNAL_ERROR ,
190
+ : ErrorCode . InternalError ,
193
191
message : error . message ?? "Internal error" ,
194
192
} ,
195
193
} ) ;
Original file line number Diff line number Diff line change @@ -82,12 +82,20 @@ export const JSONRPCResponseSchema = z
82
82
} )
83
83
. strict ( ) ;
84
84
85
- // Standard JSON-RPC error codes
86
- export const PARSE_ERROR = - 32700 ;
87
- export const INVALID_REQUEST = - 32600 ;
88
- export const METHOD_NOT_FOUND = - 32601 ;
89
- export const INVALID_PARAMS = - 32602 ;
90
- export const INTERNAL_ERROR = - 32603 ;
85
+ /**
86
+ * An incomplete set of error codes that may appear in JSON-RPC responses.
87
+ */
88
+ export enum ErrorCode {
89
+ // SDK error codes
90
+ ConnectionClosed = - 1 ,
91
+
92
+ // Standard JSON-RPC error codes
93
+ ParseError = - 32700 ,
94
+ InvalidRequest = - 32600 ,
95
+ MethodNotFound = - 32601 ,
96
+ InvalidParams = - 32602 ,
97
+ InternalError = - 32603 ,
98
+ }
91
99
92
100
/**
93
101
* A response to a request that indicates an error occurred.
@@ -802,8 +810,6 @@ export const ServerResultSchema = z.union([
802
810
ListToolsResultSchema ,
803
811
] ) ;
804
812
805
- export const CONNECTION_CLOSED_ERROR = - 1 ;
806
-
807
813
export class McpError extends Error {
808
814
constructor (
809
815
public readonly code : number ,
You can’t perform that action at this time.
0 commit comments