MCPcopy Create free account
hub / github.com/bearlyai/OpenADE / handleMessage

Method handleMessage

projects/runtime/src/server.ts:234–258  ·  view source on GitHub ↗
(connection: RuntimeConnection, raw: string)

Source from the content-addressed store, hash-verified

232 }
233
234 async handleMessage(connection: RuntimeConnection, raw: string): Promise<void> {
235 let message: unknown
236 try {
237 message = JSON.parse(raw)
238 } catch (error) {
239 connection.send({
240 id: "parse-error",
241 error: runtimeError("parse_error", error instanceof Error ? error.message : "Invalid JSON"),
242 })
243 return
244 }
245
246 const request = validateRuntimeRequest(message)
247 if (!request.ok) {
248 const id = typeof (message as { id?: unknown })?.id === "string" || typeof (message as { id?: unknown })?.id === "number" ? (message as { id: string | number }).id : "invalid-message"
249 connection.send({
250 id,
251 error: runtimeError(request.error.code, request.error.message, { path: request.error.path }),
252 })
253 return
254 }
255
256 const response = await this.handleRequest(request.value, connection, { requireInitialized: true })
257 connection.send(response)
258 }
259
260 async handleRequest(request: RuntimeRequest, connection: RuntimeConnection, options: { requireInitialized?: boolean } = {}): Promise<RuntimeResponse> {
261 if (options.requireInitialized && request.method !== "initialize" && !this.initializedConnections.has(connection.id)) {

Callers 2

attachRuntimeSocketFunction · 0.45

Calls 4

handleRequestMethod · 0.95
runtimeErrorFunction · 0.90
validateRuntimeRequestFunction · 0.90
sendMethod · 0.65

Tested by

no test coverage detected