* Executes a permission handler and sends the result back via RPC. * @internal
(
requestId: string,
permissionRequest: PermissionRequest
)
| 649 | * @internal |
| 650 | */ |
| 651 | private async _executePermissionAndRespond( |
| 652 | requestId: string, |
| 653 | permissionRequest: PermissionRequest |
| 654 | ): Promise<void> { |
| 655 | try { |
| 656 | const result = await this.permissionHandler!(permissionRequest, { |
| 657 | sessionId: this.sessionId, |
| 658 | }); |
| 659 | if (result.kind === "no-result") { |
| 660 | return; |
| 661 | } |
| 662 | if (this.disconnected) { |
| 663 | return; |
| 664 | } |
| 665 | await this.rpc.permissions.handlePendingPermissionRequest({ requestId, result }); |
| 666 | } catch (_error) { |
| 667 | if (this.disconnected) { |
| 668 | return; |
| 669 | } |
| 670 | try { |
| 671 | await this.rpc.permissions.handlePendingPermissionRequest({ |
| 672 | requestId, |
| 673 | result: { |
| 674 | kind: "user-not-available", |
| 675 | }, |
| 676 | }); |
| 677 | } catch (rpcError) { |
| 678 | if (!(rpcError instanceof ConnectionError || rpcError instanceof ResponseError)) { |
| 679 | throw rpcError; |
| 680 | } |
| 681 | // Connection lost or RPC error — nothing we can do |
| 682 | } |
| 683 | } |
| 684 | } |
| 685 | |
| 686 | /** |
| 687 | * Executes an MCP auth handler and sends the result back via RPC. |
no test coverage detected