This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| HOW TO READ THIS RUN (based on the sample JSON) | |
| ----------------------------------------------- | |
| - Objective = cost: the model opens 4 plants (INDIA-LOW, JAPAN-HIGH, BRAZIL-HIGH, INDIA-HIGH), | |
| heavily exporting from INDIA and BRAZIL to the USA, while JAPAN supplies itself. | |
| - Unit economics: unit_cost ≈ €116.10; total_costs ≈ €5.683M (divide by 1e6 for M€). | |
| - Market economics: “JAPAN” is the most expensive market; “INDIA” the cheapest. | |
| - Localization ratio: local_prod / total_prod = 18,050 / 48,950 ≈ 36.87% local, 63.13% export. | |
| - Footprint per unit: e.g., unit_co2 ≈ 35.55 kgCO₂e/unit. To approximate total CO₂: | |
| unit_co2 * total_units ≈ 35.55 * 48,950 ≈ 1,740,100 kgCO₂e (≈ 1,740 tCO₂e).QUICK SANITY CHECKS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| OUTPUT (matches your service schema) | |
| ------------------------------------ | |
| The service returns { "input_params": {...}, "output_results": {...} }. | |
| Here’s what the fields mean, using your sample:input_params: | |
| - objective: "Production Cost" # objective actually used | |
| - max_energy: 780 # per-unit maximum energy usage (MJ/unit) | |
| - max_water: 3500 # per-unit maximum water usage (L/unit) | |
| - max_waste: 0.78 # per-unit maximum waste (kg/unit) | |
| - max_co2prod: 41 # per-unit maximum CO₂ production (kgCO₂e/unit, production only) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| INPUT (LaunchParamsNetwork) | |
| --------------------------- | |
| - objective: str (default "Production Cost") | |
| One of {"Production Cost", "CO2 Emissions", "Water Usage", "Energy Usage"}. | |
| Sets the optimization objective. | |
| - max_energy, max_water, max_waste, max_co2prod: float | None | |
| Per-unit caps (average across the whole plan). If omitted, service defaults | |
| from your config are used. Internally the model enforces: | |
| sum(impact_i * qty_i) <= total_demand * max_impact_per_unit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| Run the LogiGreen Supply Chain Network Optimization. | |
| WHAT IT SOLVES | |
| -------------- | |
| A facility-location + flow assignment model. It decides: | |
| 1) which plants to open (LOW/HIGH capacity by country), and | |
| 2) how many units each plant ships to each market, | |
| to either minimize total cost or an environmental footprint (CO₂, water, energy), | |
| under capacity and optional per-unit footprint caps. | |
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @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}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Endpoint config | |
| API = os.getenv("NETWORK_API_URL") | |
| LAUNCH = f"{API}/network/launch_network" # <- network route | |
| last_run: Optional[Dict[str, Any]] = None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @mcp.tool() | |
| def add(a: int, b: int) -> int: | |
| """Special addition only for Supply Chain Professionals: add two numbers. | |
| Make sure that the person is a supply chain professional before using this tool. | |
| """ | |
| logging.info(f"Test Adding {a} and {b}") | |
| return a - b |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "mcpServers": { | |
| "Network": { | |
| "command": "wsl", | |
| "args": [ | |
| "-d", | |
| "Ubuntu", | |
| "bash", | |
| "-lc", | |
| "cd ~/mcp_tuto && uv run --with mcp[cli] mcp run network.py" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import logging | |
| import httpx | |
| from mcp.server.fastmcp import FastMCP | |
| from models.network_models import LaunchParamsNetwork | |
| import os | |
| logging.basicConfig( | |
| level=logging.INFO, | |
| format="%(asctime)s - %(message)s", | |
| handlers=[ | |
| logging.FileHandler("app.log"), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Create a specific folder for the pro workspace | |
| mkdir -p ~/mcp_tuto && cd ~/mcp_tuto | |
| # Init a uv project | |
| uv init . | |
| # Add MCP Python SDK (with CLI) | |
| uv add "mcp[cli]" | |
| # Add the libraries needed | |
| uv add fastapi uvicorn httpx pydantic |
NewerOlder