fastapi-scaffold
Skill2 starsChanged 2 months agoApache-2.0View on GitHub
Use when adding or modifying async FastAPI routers, Pydantic models, or dependency wiring in the Open-MHS middleware server. Triggers on "add an endpoint", "scaffold a router", "wire up /discover", "expose the execute primitive", "add a JSON-RPC method", or any change under server/.
2 other projects use a version of this.
Adopted by
Most recently taken up by
- erdcpatel/agent-skillstheir own version, first seen Apr 19, 2026
- tae0y/python-project-templatetheir own version, first seen Mar 7, 2026
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 2
- tae0y/python-project-template★ 14same name
- erdcpatel/agent-skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository3 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- pytest-hardware-mockSkill
- schema-validatorSkill
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 3 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 19
Always read these first so the new code matches what exists:
- Distinctive: line 26
If a router for this concern already exists, extend it.
- Very specific: line 45
Every handler is
async def: No blocking I/O in a handler — driver calls go through an awaitable transport, or anyio.to_thread.run_sync … - Very specific: line 51
Pydantic v2 models for every request and response: Never return a bare dict. Declare response_model= on the decorator so the OpenAPI doc is …
- Very specific: line 112
Never add an endpoint that mutates hardware outside the JSON-RPC dispatcher.
- Distinctive: line 123
Add a test alongside the endpoint in the same change.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Open-MHS FastAPI Router Scaffold
Generate async FastAPI routers for the Open-MHS Discovery and Execution layers that match the repo's existing conventions exactly.
When to use
- Adding a new endpoint to the middleware server.
- Adding a JSON-RPC method to
/execute. - Splitting a growing
open_mhs/server/main.pyinto routers.
Read before writing
Always read these first so the new code matches what exists:
sed -n '1,80p' server/main.py
ls server/If a router for this concern already exists, extend it. Do not create a parallel one.
Layout
server/
main.py # app factory + router registration only, no business logic
models.py # Pydantic request/response models, shared
registry.py # in-memory device registry (single source of truth)
safety.py # limit evaluation - the only place bounds are interpreted
errors.py # JSON-RPC error codes + typed exceptions
routers/
discovery.py # GET /discover, POST /register, DELETE /devices/{id}
rpc.py # POST /rpc, POST /execute (JSON-RPC 2.0 dispatcher)
deps.py # FastAPI dependencies (get_registry, etc.)Conventions
- Every handler is
async def. No blocking I/O in a handler — driver calls go through an awaitable transport, oranyio.to_thread.run_syncfor genuinely blocking hardware SDKs. APIRouterper concern, withprefixandtagsset at construction:router = APIRouter(tags=["discovery"])- Pydantic v2 models for every request and response. Never return a bare
dict. Declareresponse_model=on the decorator so the OpenAPI doc is accurate — the OpenAPI doc is how an agent discovers the server. - Shared state via
Depends, never a module-level global reached into directly:async def discover(registry: Registry = Depends(get_registry)) -> DiscoverResponse: ... - Errors are typed. Raise
HTTPExceptionfor transport-level failures; return a JSON-RPCerrorobject for method-level failures. Never leak a driver traceback.
JSON-RPC contract
POST /rpc is the canonical JSON-RPC 2.0 surface. POST /execute is a compatibility alias
onto the same dispatcher. Four methods, and no others:
| Method | Mutating | Purpose |
mhs.discover | no | List registered devices and their capability tags. |
mhs.read | no | Read one sensor or actuator state. |
mhs.write | yes | Command one actuator, inside its safety limits. |
mhs.emergency_stop | yes | Drive a device to its declared safe state. |
Bare read / write are accepted as legacy aliases for mhs.read / mhs.write.
{"jsonrpc": "2.0", "id": 1, "method": "mhs.read",
"params": {"device_id": "mock-temp-01", "target": "ambient_temp"}}{"jsonrpc": "2.0", "id": 2, "method": "mhs.write",
"params": {"device_id": "arm-01", "target": "joint_1", "value": 45.0}}Reserved error codes — use these, do not invent new ones in the JSON-RPC reserved range:
| Code | Meaning |
| -32700 | Parse error |
| -32600 | Invalid request |
| -32601 | Method not found (anything outside the four mhs.* methods and their aliases) |
| -32602 | Invalid params |
| -32000 | Device not found |
| -32001 | Safety limit violation |
| -32002 | Hardware execution error (driver/transport raised) |
| -32003 | State desync (feedback sensor disagrees with commanded value after settle) |
A write aimed at a sensor id is -32602 (invalid params), not a custom code: the target
exists but is not a legal write target, which is a params problem, not a hardware problem.
-32001 must include the attempted value and the violated bound in error.data, so the
agent can correct itself without a second round trip. -32003 must include both the
commanded value and the observed feedback value: a desync means the world and the agent's
model of it have diverged, and the agent cannot recover without seeing both.
Safety rule
The safety check runs in the server, before the driver is called, and again in the
driver. Two independent enforcement points. Never scaffold a write path that reaches
a driver without passing the value through the device's safety_limits.
Never add an endpoint that mutates hardware outside the JSON-RPC dispatcher. One mutating
surface means one place to audit. emergency_stop is the sole exception to limit checking:
it drives to the tag-declared safe state, which is trusted by definition.
After scaffolding
python -m pytest tests/ -q
uvicorn open_mhs.server.main:app --reload # verify /docs rendersAdd a test alongside the endpoint in the same change. An endpoint with no test does not ship.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

