MCPcopy Create free account
hub / github.com/agent0ai/agent-zero / process

Method process

api/mcp_server_scan.py:23–94  ·  view source on GitHub ↗
(self, input: dict[Any, Any], request: Request)

Source from the content-addressed store, hash-verified

21
22class 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",

Callers

nothing calls this directly

Calls 10

_normalize_serverMethod · 0.95
_static_warningsMethod · 0.95
_tool_warningsMethod · 0.95
_redact_serverMethod · 0.95
_risk_levelMethod · 0.95
MCPConfigClass · 0.90
get_servers_statusMethod · 0.80
get_server_detailMethod · 0.80
getMethod · 0.45
extendMethod · 0.45

Tested by

no test coverage detected