MCPcopy Create free account
hub / github.com/WJX20/claude-code / injectControlResponse

Method injectControlResponse

src/cli/structuredIO.ts:287–314  ·  view source on GitHub ↗

* Inject a control_response message to resolve a pending permission request. * Used by the bridge to feed permission responses from claude.ai into the * SDK permission flow. * * Also sends a control_cancel_request to the SDK consumer so its canUseTool * callback is aborted via the sig

(response: SDKControlResponse)

Source from the content-addressed store, hash-verified

285 * callback is aborted via the signal — otherwise the callback hangs.
286 */
287 injectControlResponse(response: SDKControlResponse): void {
288 const responseInner = response.response as { request_id?: string; subtype?: string; error?: string; response?: unknown } | undefined
289 const requestId = responseInner?.request_id
290 if (!requestId) return
291 const request = this.pendingRequests.get(requestId as string)
292 if (!request) return
293 this.trackResolvedToolUseId(request.request)
294 this.pendingRequests.delete(requestId as string)
295 // Cancel the SDK consumer's canUseTool callback — the bridge won.
296 void this.write({
297 type: 'control_cancel_request',
298 request_id: requestId,
299 })
300 if (responseInner.subtype === 'error') {
301 request.reject(new Error(responseInner.error as string))
302 } else {
303 const result = responseInner.response
304 if (request.schema) {
305 try {
306 request.resolve(request.schema.parse(result))
307 } catch (error) {
308 request.reject(error)
309 }
310 } else {
311 request.resolve({})
312 }
313 }
314 }
315
316 /**
317 * Register a callback invoked whenever a can_use_tool control_request

Callers 1

onPermissionResponseFunction · 0.80

Calls 6

writeMethod · 0.95
deleteMethod · 0.80
rejectMethod · 0.80
resolveMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected