(self, input: dict[Any, Any], request: Request)
| 21 | |
| 22 | class McpServerScan(ApiHandler): |
| 23 | async def process(self, input: dict[Any, Any], request: Request) -> dict[Any, Any] | Response: |
| 24 | server = dict(input.get("server") or {}) |
| 25 | allow_local_execution = bool(input.get("allow_local_execution", False)) |
| 26 | allow_remote_network = bool(input.get("allow_remote_network", False)) |
| 27 | inspect_runtime = input.get("inspect_runtime", True) is not False |
| 28 | |
| 29 | server = self._normalize_server(server) |
| 30 | warnings = self._static_warnings(server) |
| 31 | is_local = not (server.get("url") or server.get("serverUrl")) |
| 32 | has_static_errors = any(warning.get("level") == "error" for warning in warnings) |
| 33 | |
| 34 | runtime_status: list[dict[str, Any]] = [] |
| 35 | runtime_detail: dict[str, Any] = {} |
| 36 | runtime_error = "" |
| 37 | |
| 38 | should_inspect_runtime = ( |
| 39 | inspect_runtime |
| 40 | and not has_static_errors |
| 41 | and ((is_local and allow_local_execution) or (not is_local and allow_remote_network)) |
| 42 | ) |
| 43 | |
| 44 | if should_inspect_runtime: |
| 45 | try: |
| 46 | scan_config = await asyncio.to_thread( |
| 47 | lambda: MCPConfig(servers_list=[server], config_scope="scan") |
| 48 | ) |
| 49 | runtime_status = scan_config.get_servers_status() |
| 50 | runtime_detail = scan_config.get_server_detail(server.get("name", "")) |
| 51 | warnings.extend(self._tool_warnings(runtime_detail.get("tools", []))) |
| 52 | except Exception as exc: |
| 53 | runtime_error = str(exc) |
| 54 | warnings.append( |
| 55 | { |
| 56 | "level": "error", |
| 57 | "title": "Runtime inspection failed", |
| 58 | "message": runtime_error, |
| 59 | } |
| 60 | ) |
| 61 | elif is_local and inspect_runtime: |
| 62 | warnings.append( |
| 63 | { |
| 64 | "level": "warning", |
| 65 | "title": "Local command not executed", |
| 66 | "message": "Local stdio MCP inspection requires explicit trust because it runs the configured command.", |
| 67 | } |
| 68 | ) |
| 69 | elif not is_local and inspect_runtime and has_static_errors: |
| 70 | warnings.append( |
| 71 | { |
| 72 | "level": "info", |
| 73 | "title": "Runtime inspection skipped", |
| 74 | "message": "Fix static scan errors before attempting runtime MCP inspection.", |
| 75 | } |
| 76 | ) |
| 77 | elif not is_local and inspect_runtime: |
| 78 | warnings.append( |
| 79 | { |
| 80 | "level": "info", |
nothing calls this directly
no test coverage detected