mirror of
https://github.com/yogeshojha/rengine.git
synced 2026-10-20 23:31:31 +02:00
The comment rule in CLAUDE.md is one line maximum, never narration: no multi-line blocks, no module-header explainers, no sentences that explain or justify the code to the reader. The tree had drifted a long way from it, and most of the drift is mine. Removed: 232 lines of multi-line comment blocks 203 single-line comments that argued instead of stating 154 comments joined by so/because/otherwise/rather-than 143 narrating comments in the frontend 112 test docstrings (the test name already says what it asserts) 25 test module docstrings and 25 decorative section dividers Collapsed: 324 multi-line docstrings to one factual line 271 one-line docstrings that had a justifying clause bolted on Kept: functional directives, section dividers, short field labels, alembic revision headers, and the eight FastAPI route docstrings that render in /docs. Where a fact was load-bearing it is in CLAUDE.md, which is where it belongs. 284 python tests and 34 frontend tests pass, ruff and ruff-format clean across ten packages, svelte-check 0 errors, prettier and eslint clean, app.main imports. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013dKUV96WkQQETZBMoAG98C
63 lines
1.7 KiB
Python
63 lines
1.7 KiB
Python
"""JSON-RPC 2.0 framing and the MCP method names."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass
|
|
from typing import Any
|
|
|
|
from mcp.errors import INVALID_REQUEST, ProtocolError
|
|
|
|
VERSION = "2.0"
|
|
|
|
|
|
class Method:
|
|
INITIALIZE = "initialize"
|
|
INITIALIZED = "notifications/initialized"
|
|
PING = "ping"
|
|
TOOLS_LIST = "tools/list"
|
|
TOOLS_CALL = "tools/call"
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class Request:
|
|
id: Any
|
|
method: str
|
|
params: dict
|
|
|
|
@property
|
|
def is_notification(self) -> bool:
|
|
return self.id is None
|
|
|
|
|
|
def parse(payload: Any) -> Request:
|
|
if isinstance(payload, list):
|
|
msg = "Batched requests are not supported."
|
|
raise ProtocolError(msg)
|
|
if not isinstance(payload, dict):
|
|
msg = "A request must be a JSON object."
|
|
raise ProtocolError(msg)
|
|
method = payload.get("method")
|
|
if not isinstance(method, str) or not method:
|
|
msg = "A request must carry a method."
|
|
raise ProtocolError(msg)
|
|
params = payload.get("params") or {}
|
|
if not isinstance(params, dict):
|
|
msg = "params must be an object."
|
|
raise ProtocolError(msg)
|
|
return Request(id=payload.get("id"), method=method, params=params)
|
|
|
|
|
|
def success(request_id: Any, result: dict) -> dict:
|
|
return {"jsonrpc": VERSION, "id": request_id, "result": result}
|
|
|
|
|
|
def failure(request_id: Any, code: int, message: str, data: dict | None = None) -> dict:
|
|
error: dict[str, Any] = {"code": code, "message": message}
|
|
if data:
|
|
error["data"] = data
|
|
return {"jsonrpc": VERSION, "id": request_id, "error": error}
|
|
|
|
|
|
def parse_failure(message: str) -> dict:
|
|
return failure(None, INVALID_REQUEST, message)
|