Add versioned metric graph authority, owned browser evidence, paginated and all-tab traversal, deterministic sampling policies, and analyst-facing run inspection. Provision the DEV/PREPROD/PROD Superset, Gitea and million-row ClickHouse lab; retain reproducible lifecycle evidence and explicit incomplete-traversal limits.
61 lines
3.2 KiB
Python
61 lines
3.2 KiB
Python
# #region Tooling.FullFlowMcpClient [C:3] [TYPE Module] [SEMANTICS test,mcp,http,evidence]
|
|
# @BRIEF Retain actual external MCP transport and domain responses for the local flow.
|
|
import json
|
|
|
|
from common import Blocked
|
|
|
|
|
|
# #region Tooling.FullFlowMcpClient.Client [C:3] [TYPE Class]
|
|
# @BRIEF Use the authenticated HTTP client and server-issued MCP session identifiers.
|
|
class McpClient:
|
|
# #region Tooling.FullFlowMcpClient.Init [C:2] [TYPE Function]
|
|
# @POST Initialize a real external session; no domain operation is simulated.
|
|
def __init__(self, driver):
|
|
self.driver = driver
|
|
self.headers = {"Accept": "application/json, text/event-stream", "Content-Type": "application/json"}
|
|
self.sequence = 0
|
|
self.rpc("mcp-initialize", {"method": "initialize", "params": {
|
|
"protocolVersion": "2025-03-26", "capabilities": {},
|
|
"clientInfo": {"name": "docker-full-flow-verifier", "version": "1"}}})
|
|
self.headers["MCP-Protocol-Version"] = "2025-03-26"
|
|
self.rpc("mcp-initialized", {"method": "notifications/initialized"}, notification=True)
|
|
# #endregion Tooling.FullFlowMcpClient.Init
|
|
|
|
# #region Tooling.FullFlowMcpClient.Rpc [C:3] [TYPE Function]
|
|
# @POST HTTP, JSON-RPC and tool errors retain blocked evidence and stop dependent work.
|
|
def rpc(self, name, payload, notification=False):
|
|
self.sequence += 1
|
|
request = {"jsonrpc": "2.0", **payload}
|
|
if not notification:
|
|
request["id"] = self.sequence
|
|
response = self.driver.client.post("/mcp/", json=request, headers=self.headers)
|
|
if response.headers.get("mcp-session-id"):
|
|
self.headers["Mcp-Session-Id"] = response.headers["mcp-session-id"]
|
|
if not response.content:
|
|
value = {}
|
|
elif "text/event-stream" in response.headers.get("content-type", ""):
|
|
data = [line[6:] for line in response.text.splitlines() if line.startswith("data: ")]
|
|
value = json.loads(data[-1]) if data else {}
|
|
else:
|
|
value = response.json()
|
|
success = response.status_code in (200, 202) and "error" not in value and not value.get("result", {}).get("isError")
|
|
self.driver.record(name, "PASS" if success else "BLOCKED", http_status=response.status_code, response=value)
|
|
if not success:
|
|
raise Blocked(name)
|
|
return value
|
|
# #endregion Tooling.FullFlowMcpClient.Rpc
|
|
|
|
# #region Tooling.FullFlowMcpClient.Call [C:2] [TYPE Function]
|
|
# @POST Return the actual structured tool result; blocked domain results remain failures.
|
|
def call(self, name, tool, request):
|
|
response = self.rpc(name, {"method": "tools/call", "params": {"name": tool, "arguments": {"request": request}}})
|
|
result = response.get("result", {})
|
|
value = result.get("structuredContent")
|
|
if value is None:
|
|
value = json.loads(next(item["text"] for item in result.get("content", []) if item.get("type") == "text"))
|
|
self.driver.require(name + "-domain", value.get("status") not in {"blocked", "permission_denied"}, response=value)
|
|
return value
|
|
# #endregion Tooling.FullFlowMcpClient.Call
|
|
# #endregion Tooling.FullFlowMcpClient.Client
|
|
# #endregion Tooling.FullFlowMcpClient
|