Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files- examples/claude_desktop_config.json +8 -0
- examples/curl_cheatsheet.sh +27 -0
- examples/langchain_client.py +17 -0
- examples/n8n_notes.md +14 -0
examples/claude_desktop_config.json
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"mcpServers": {
|
| 3 |
+
"swmm-analysis": {
|
| 4 |
+
"command": "npx",
|
| 5 |
+
"args": ["-y", "mcp-remote", "https://YOUR-SPACE.hf.space/mcp"]
|
| 6 |
+
}
|
| 7 |
+
}
|
| 8 |
+
}
|
examples/curl_cheatsheet.sh
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
# REST surface quick reference. Set SPACE to your deployed URL.
|
| 3 |
+
SPACE="https://YOUR-SPACE.hf.space"
|
| 4 |
+
|
| 5 |
+
# Health + tool catalog
|
| 6 |
+
curl -s $SPACE/health
|
| 7 |
+
curl -s $SPACE/api/tools
|
| 8 |
+
|
| 9 |
+
# Upload a model (raw text; base64 also accepted)
|
| 10 |
+
SID=$(curl -s -X POST $SPACE/api/tool/upload_model \
|
| 11 |
+
-H 'Content-Type: application/json' \
|
| 12 |
+
-d "$(jq -n --rawfile inp model.inp '{inp_content:$inp, filename:"model.inp"}')" | jq -r .session_id)
|
| 13 |
+
|
| 14 |
+
# Run + screen + review
|
| 15 |
+
curl -s -X POST $SPACE/api/tool/run_simulation -H 'Content-Type: application/json' -d "{\"session_id\":\"$SID\"}"
|
| 16 |
+
curl -s -X POST $SPACE/api/tool/calgary_screening -H 'Content-Type: application/json' -d "{\"session_id\":\"$SID\"}"
|
| 17 |
+
curl -s -X POST $SPACE/api/tool/preliminary_design_review -H 'Content-Type: application/json' -d "{\"session_id\":\"$SID\"}"
|
| 18 |
+
|
| 19 |
+
# Scenario + report
|
| 20 |
+
curl -s -X POST $SPACE/api/tool/run_scenario -H 'Content-Type: application/json' \
|
| 21 |
+
-d "{\"session_id\":\"$SID\",\"scenario_name\":\"Upsize\",\"conduit_diameter_overrides\":{\"1000\":0.6}}"
|
| 22 |
+
curl -s -X POST $SPACE/api/tool/generate_report -H 'Content-Type: application/json' \
|
| 23 |
+
-d "{\"session_id\":\"$SID\",\"project_name\":\"My Project\"}"
|
| 24 |
+
|
| 25 |
+
# One-shot agent (server-side orchestration; provider key via Space secret or api_key field)
|
| 26 |
+
curl -s -X POST $SPACE/api/agent -H 'Content-Type: application/json' \
|
| 27 |
+
-d '{"question":"Run my model and screen velocities against Calgary criteria","provider":"gemini"}'
|
examples/langchain_client.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""LangChain / LangGraph: bind the Space's tools to any chat model."""
|
| 2 |
+
import asyncio
|
| 3 |
+
from langchain_mcp_adapters.client import MultiServerMCPClient
|
| 4 |
+
|
| 5 |
+
SPACE = "https://YOUR-SPACE.hf.space"
|
| 6 |
+
|
| 7 |
+
async def main():
|
| 8 |
+
client = MultiServerMCPClient({
|
| 9 |
+
"swmm": {"url": f"{SPACE}/mcp", "transport": "streamable_http"},
|
| 10 |
+
})
|
| 11 |
+
tools = await client.get_tools()
|
| 12 |
+
print([t.name for t in tools])
|
| 13 |
+
# from langgraph.prebuilt import create_react_agent
|
| 14 |
+
# agent = create_react_agent("anthropic:claude-sonnet-4-5", tools)
|
| 15 |
+
# result = await agent.ainvoke({"messages": "Upload and analyse my model ..."})
|
| 16 |
+
|
| 17 |
+
asyncio.run(main())
|
examples/n8n_notes.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# n8n integration
|
| 2 |
+
|
| 3 |
+
**Option A — MCP Client Tool node (AI Agent):**
|
| 4 |
+
Endpoint: `https://YOUR-SPACE.hf.space/mcp` · Transport: HTTP Streamable.
|
| 5 |
+
The agent node auto-discovers all 16 tools.
|
| 6 |
+
|
| 7 |
+
**Option B — HTTP Request nodes (deterministic pipelines):**
|
| 8 |
+
1. POST `/api/tool/upload_model` body: `{"inp_content": "={{ $binary.data.toString() }}", "filename": "model.inp"}`
|
| 9 |
+
2. POST `/api/tool/run_simulation` body: `{"session_id": "={{ $json.session_id }}"}`
|
| 10 |
+
3. POST `/api/tool/calgary_screening` → route flagged links to Slack/email.
|
| 11 |
+
|
| 12 |
+
**Option C — one node total:**
|
| 13 |
+
POST `/api/agent` with `{"question": "...", "provider": "groq", "inp_content": "..."}` —
|
| 14 |
+
the server's own agent plans the tool calls and returns answer + tool_trace.
|