Skip to content

Instantly share code, notes, and snippets.

@samirsaci
Created November 9, 2025 13:36
Show Gist options
  • Select an option

  • Save samirsaci/e6e2680efcaaed48209ffb36cb635970 to your computer and use it in GitHub Desktop.

Select an option

Save samirsaci/e6e2680efcaaed48209ffb36cb635970 to your computer and use it in GitHub Desktop.
MCP Server Supply Chain Optimisation - Tool Run Network
@mcp.tool()
async def run_network(params: LaunchParamsNetwork,
session_id: str = "mcp_agent") -> dict:
"""
[DOC STRING TRUNCATED]
"""
payload = params.model_dump(exclude_none=True)
try:
async with httpx.AsyncClient(timeout=httpx.Timeout(5, read=60)) as c:
r = await c.post(LAUNCH, json=payload, headers={"session_id": session_id})
r.raise_for_status()
logging.info(f"[NetworkMCP] Run successful with params: {payload}")
data = r.json()
result = data[0] if isinstance(data, list) and data else data
global last_run
last_run = result
return result
except httpx.HTTPError as e:
code = getattr(e.response, "status_code", "unknown")
logging.error(f"[NetworkMCP] API call failed: {e}")
return {"error": f"{code} {e}"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment