MCPcopy Index your code
hub / github.com/github/copilot-sdk / _handleBroadcastEvent

Method _handleBroadcastEvent

nodejs/src/session.ts:471–555  ·  view source on GitHub ↗

* Handles broadcast request events by executing local handlers and responding via RPC. * Handlers are dispatched as fire-and-forget — rejections propagate as unhandled promise * rejections, consistent with standard EventEmitter / event handler semantics. * @internal

(event: SessionEvent)

Source from the content-addressed store, hash-verified

469 * @internal
470 */
471 private _handleBroadcastEvent(event: SessionEvent): void {
472 if (this.disconnected) {
473 return;
474 }
475 if (event.type === "external_tool.requested") {
476 const { requestId, toolName } = event.data as {
477 requestId: string;
478 toolName: string;
479 arguments: unknown;
480 toolCallId: string;
481 sessionId: string;
482 };
483 const args = (event.data as { arguments: unknown }).arguments;
484 const toolCallId = (event.data as { toolCallId: string }).toolCallId;
485 const traceparent = (event.data as { traceparent?: string }).traceparent;
486 const tracestate = (event.data as { tracestate?: string }).tracestate;
487 const handler = this.toolHandlers.get(toolName);
488 if (handler) {
489 void this._executeToolAndRespond(
490 requestId,
491 toolName,
492 toolCallId,
493 args,
494 handler,
495 traceparent,
496 tracestate
497 );
498 }
499 } else if (event.type === "permission.requested") {
500 const { requestId, permissionRequest, resolvedByHook } = event.data as {
501 requestId: string;
502 permissionRequest: PermissionRequest;
503 resolvedByHook?: boolean;
504 };
505 if (resolvedByHook) {
506 return; // Already resolved by a permissionRequest hook; no client action needed.
507 }
508 if (this.permissionHandler) {
509 void this._executePermissionAndRespond(requestId, permissionRequest);
510 }
511 } else if (event.type === "mcp.oauth_required") {
512 const data = event.data as McpAuthRequest | undefined;
513 if (!data?.requestId) {
514 return;
515 }
516 if (!this.mcpAuthHandler) {
517 console.warn(
518 "Received MCP OAuth request without a registered MCP auth handler. " +
519 `SessionId=${this.sessionId}, RequestId=${data.requestId}`
520 );
521 return;
522 }
523 void this._executeMcpAuthAndRespond(data);
524 } else if (event.type === "command.execute") {
525 const { requestId, commandName, command, args } = event.data as {
526 requestId: string;
527 command: string;
528 commandName: string;

Callers 1

_dispatchEventMethod · 0.95

Calls 8

getMethod · 0.45

Tested by

no test coverage detected