MCPcopy Create free account
hub / github.com/modelcontextprotocol/typescript-sdk / handleMessage

Method handleMessage

src/server/sse.ts:195–205  ·  view source on GitHub ↗

* Handle a client message, regardless of how it arrived. This can be used to inform the server of messages that arrive via a means different than HTTP POST.

(message: unknown, extra?: MessageExtraInfo)

Source from the content-addressed store, hash-verified

193 * Handle a client message, regardless of how it arrived. This can be used to inform the server of messages that arrive via a means different than HTTP POST.
194 */
195 async handleMessage(message: unknown, extra?: MessageExtraInfo): Promise<void> {
196 let parsedMessage: JSONRPCMessage;
197 try {
198 parsedMessage = JSONRPCMessageSchema.parse(message);
199 } catch (error) {
200 this.onerror?.(error as Error);
201 throw error;
202 }
203
204 this.onmessage?.(parsedMessage, extra);
205 }
206
207 async close(): Promise<void> {
208 this._sseResponse?.end();

Callers 1

handlePostMessageMethod · 0.95

Calls 3

parseMethod · 0.80
onerrorMethod · 0.80
onmessageMethod · 0.80

Tested by

no test coverage detected