* Creates a SandboxAskCallback that forwards sandbox network permission * requests to the SDK host as can_use_tool control_requests. * * This piggybacks on the existing can_use_tool protocol with a synthetic * tool name so that SDK hosts (VS Code, CCR, etc.) can prompt the user * for
()
| 728 | * for network access without requiring a new protocol subtype. |
| 729 | */ |
| 730 | createSandboxAskCallback(): (hostPattern: { |
| 731 | host: string |
| 732 | port?: number |
| 733 | }) => Promise<boolean> { |
| 734 | return async (hostPattern): Promise<boolean> => { |
| 735 | try { |
| 736 | const result = await this.sendRequest<PermissionToolOutput>( |
| 737 | { |
| 738 | subtype: 'can_use_tool', |
| 739 | tool_name: SANDBOX_NETWORK_ACCESS_TOOL_NAME, |
| 740 | input: { host: hostPattern.host }, |
| 741 | tool_use_id: randomUUID(), |
| 742 | description: `Allow network connection to ${hostPattern.host}?`, |
| 743 | }, |
| 744 | permissionToolOutputSchema(), |
| 745 | ) |
| 746 | return result.behavior === 'allow' |
| 747 | } catch { |
| 748 | // If the request fails (stream closed, abort, etc.), deny the connection |
| 749 | return false |
| 750 | } |
| 751 | } |
| 752 | } |
| 753 | |
| 754 | /** |
| 755 | * Sends an MCP message to an SDK server and waits for the response |
no test coverage detected