@hunyed15/codecgc 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/scripts/run_codecgc_task.py +23 -12
package/package.json
CHANGED
|
@@ -106,10 +106,9 @@ def extract_text_content(value: Any) -> str:
|
|
|
106
106
|
|
|
107
107
|
|
|
108
108
|
def normalize_mcp_result(raw: dict[str, Any]) -> dict[str, Any]:
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
109
|
+
# Prefer text content over structuredContent — the tool's actual JSON
|
|
110
|
+
# response is in content[0].text, while structuredContent is an MCP SDK
|
|
111
|
+
# convenience wrapper that may omit top-level fields like "success".
|
|
113
112
|
content = raw.get("content")
|
|
114
113
|
if isinstance(content, list):
|
|
115
114
|
for item in content:
|
|
@@ -127,6 +126,10 @@ def normalize_mcp_result(raw: dict[str, Any]) -> dict[str, Any]:
|
|
|
127
126
|
if isinstance(parsed, dict):
|
|
128
127
|
return parsed
|
|
129
128
|
|
|
129
|
+
structured_content = raw.get("structuredContent")
|
|
130
|
+
if isinstance(structured_content, dict):
|
|
131
|
+
return structured_content
|
|
132
|
+
|
|
130
133
|
return {
|
|
131
134
|
"success": False,
|
|
132
135
|
"error": "Unable to parse structured MCP tool result.",
|
|
@@ -280,15 +283,23 @@ def write_audit_file(audit_root: Path, audit_record: dict[str, Any]) -> Path:
|
|
|
280
283
|
|
|
281
284
|
async def execute_payload(payload: dict[str, Any], timeout_seconds: int) -> dict[str, Any]:
|
|
282
285
|
params = build_server_params(payload["target"])
|
|
286
|
+
raw_result = None
|
|
283
287
|
|
|
284
|
-
|
|
285
|
-
async with
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
288
|
+
try:
|
|
289
|
+
async with stdio_client(params) as (read_stream, write_stream):
|
|
290
|
+
async with ClientSession(read_stream, write_stream) as session:
|
|
291
|
+
await session.initialize()
|
|
292
|
+
raw_result = await session.call_tool(
|
|
293
|
+
payload["tool_name"],
|
|
294
|
+
payload["tool_args"],
|
|
295
|
+
read_timeout_seconds=datetime.timedelta(seconds=timeout_seconds),
|
|
296
|
+
)
|
|
297
|
+
except* ExceptionGroup:
|
|
298
|
+
# MCP SDK 清理阶段的 TaskGroup 异常不影响已获得的结果
|
|
299
|
+
pass
|
|
300
|
+
|
|
301
|
+
if raw_result is None:
|
|
302
|
+
raise RuntimeError("MCP call failed before producing a result.")
|
|
292
303
|
|
|
293
304
|
dumped = raw_result.model_dump(mode="json")
|
|
294
305
|
normalized = normalize_mcp_result(dumped)
|