Skip to content

Instantly share code, notes, and snippets.

View samirsaci's full-sized avatar

Samir Saci samirsaci

View GitHub Profile
@samirsaci
samirsaci / docstring_interprete_results.py
Created November 9, 2025 13:42
MCP Server Supply Chain Optimisation - Doc String Interprete Results
"""
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
@samirsaci
samirsaci / docstring_output.py
Created November 9, 2025 13:41
MCP Server Supply Chain Optimisation - Doc String Describe Output
"""
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)
@samirsaci
samirsaci / docstring_input.py
Created November 9, 2025 13:38
MCP Server Supply Chain Optimisation - Doc String Describe Input
"""
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
@samirsaci
samirsaci / context.py
Created November 9, 2025 13:37
MCP Server Supply Chain Optimisation - Doc String Context
"""
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.
"""
@samirsaci
samirsaci / run_network.py
Created November 9, 2025 13:36
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})
@samirsaci
samirsaci / endpoint_config.py
Created November 9, 2025 13:35
MCP Server Supply Chain Optimisation - Endpoint Config
# Endpoint config
API = os.getenv("NETWORK_API_URL")
LAUNCH = f"{API}/network/launch_network" # <- network route
last_run: Optional[Dict[str, Any]] = None
@samirsaci
samirsaci / a_b_too.py
Created November 9, 2025 13:34
MCP Server Supply Chain Optimisation - Example Tool
@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
@samirsaci
samirsaci / config.json
Created November 9, 2025 13:33
MCP Server Supply Chain Optimisation - Config File Claude
{
"mcpServers": {
"Network": {
"command": "wsl",
"args": [
"-d",
"Ubuntu",
"bash",
"-lc",
"cd ~/mcp_tuto && uv run --with mcp[cli] mcp run network.py"
@samirsaci
samirsaci / network.py
Created November 9, 2025 13:32
MCP Server Supply Chain Optimisation - Network py
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"),
@samirsaci
samirsaci / setup.sh
Created November 9, 2025 13:32
MCP Server Supply Chain Optimisation - Setup uv
# 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