Execute an MCP auth handler and respond via RPC.
(
self,
request: McpAuthRequest,
handler: McpAuthHandler,
)
| 2074 | pass # Connection lost or RPC error — nothing we can do |
| 2075 | |
| 2076 | async def _execute_mcp_auth_and_respond( |
| 2077 | self, |
| 2078 | request: McpAuthRequest, |
| 2079 | handler: McpAuthHandler, |
| 2080 | ) -> None: |
| 2081 | """Execute an MCP auth handler and respond via RPC.""" |
| 2082 | request_id = request["requestId"] |
| 2083 | try: |
| 2084 | handler_start = time.perf_counter() |
| 2085 | maybe_result = handler(request, {"sessionId": self.session_id}) |
| 2086 | if inspect.isawaitable(maybe_result): |
| 2087 | result = cast(McpAuthHandlerResult, await maybe_result) |
| 2088 | else: |
| 2089 | result = maybe_result |
| 2090 | log_timing( |
| 2091 | logger, |
| 2092 | logging.DEBUG, |
| 2093 | "CopilotSession._execute_mcp_auth_and_respond dispatch", |
| 2094 | handler_start, |
| 2095 | session_id=self.session_id, |
| 2096 | request_id=request_id, |
| 2097 | ) |
| 2098 | |
| 2099 | if result and result.get("kind", "token") == "token": |
| 2100 | rpc_result = MCPOauthPendingRequestResponse( |
| 2101 | kind=MCPOauthPendingRequestResponseKind.TOKEN, |
| 2102 | access_token=result["accessToken"], |
| 2103 | expires_in=result.get("expiresIn"), |
| 2104 | token_type=result.get("tokenType"), |
| 2105 | ) |
| 2106 | else: |
| 2107 | rpc_result = MCPOauthPendingRequestResponse( |
| 2108 | kind=MCPOauthPendingRequestResponseKind.CANCELLED |
| 2109 | ) |
| 2110 | await self.rpc.mcp.oauth.handle_pending_request( |
| 2111 | MCPOauthHandlePendingRequest( |
| 2112 | request_id=request_id, |
| 2113 | result=rpc_result, |
| 2114 | ) |
| 2115 | ) |
| 2116 | except Exception: |
| 2117 | try: |
| 2118 | await self.rpc.mcp.oauth.handle_pending_request( |
| 2119 | MCPOauthHandlePendingRequest( |
| 2120 | request_id=request_id, |
| 2121 | result=MCPOauthPendingRequestResponse( |
| 2122 | kind=MCPOauthPendingRequestResponseKind.CANCELLED |
| 2123 | ), |
| 2124 | ) |
| 2125 | ) |
| 2126 | except (JsonRpcError, ProcessExitedError, OSError): |
| 2127 | pass # Connection lost or RPC error — nothing we can do |
| 2128 | |
| 2129 | async def _execute_command_and_respond( |
| 2130 | self, |
no test coverage detected