Skip to content

Commit 07002ac

Browse files
committed
style: ruff format
1 parent 256e33f commit 07002ac

2 files changed

Lines changed: 12 additions & 15 deletions

File tree

deploy/proxy/mempalace_mcp_proxy.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@
6969
# ALLOWED_HOSTS: comma-separated list of permitted Host headers (no Origin).
7070
# INBOUND_TOKEN: optional bearer token required for all /mcp endpoints.
7171
ALLOWED_ORIGINS = frozenset(
72-
o.strip()
73-
for o in os.environ.get("ALLOWED_ORIGINS", "").split(",")
74-
if o.strip()
72+
o.strip() for o in os.environ.get("ALLOWED_ORIGINS", "").split(",") if o.strip()
7573
)
7674
ALLOWED_HOSTS = frozenset(
7775
h.strip().lower()
@@ -264,9 +262,7 @@ def _is_valid_jsonrpc_request(body: bytes) -> tuple[bool, str | None, int]:
264262
return False, "method must be a non-empty string", -32600
265263

266264
# id may be absent (notification), but if present must be a valid type.
267-
if "id" in req and not (
268-
isinstance(req["id"], (str, int, float)) or req["id"] is None
269-
):
265+
if "id" in req and not (isinstance(req["id"], (str, int, float)) or req["id"] is None):
270266
return False, "id must be a string, number, or null", -32600
271267

272268
params = req.get("params")

tests/test_proxy.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ def test_invalid_json_shape_is_not_retried(self):
557557
"""Malformed JSON-RPC is not safe to retry."""
558558
import mempalace_mcp_proxy as proxy
559559

560-
body = b'not json'
560+
body = b"not json"
561561
assert not proxy._is_retry_safe(body)
562562

563563
def test_missing_jsonrpc_field_is_not_retried(self):
@@ -612,9 +612,7 @@ def test_final_5xx_with_json_body_is_failure_and_preserves_status(self):
612612
FakeResponse(503, b"{}"),
613613
FakeResponse(
614614
503,
615-
json.dumps(
616-
{"jsonrpc": "2.0", "id": 1, "error": {"code": -32000}}
617-
).encode(),
615+
json.dumps({"jsonrpc": "2.0", "id": 1, "error": {"code": -32000}}).encode(),
618616
),
619617
],
620618
restore_circuit=False,
@@ -737,9 +735,7 @@ def test_repeated_json_5xx_opens_circuit_and_persists_status(self):
737735
body = json.dumps(
738736
{"jsonrpc": "2.0", "id": 1, "method": "tools/list", "params": {}}
739737
).encode()
740-
upstream_body = json.dumps(
741-
{"jsonrpc": "2.0", "id": 1, "error": {"code": -32000}}
742-
).encode()
738+
upstream_body = json.dumps({"jsonrpc": "2.0", "id": 1, "error": {"code": -32000}}).encode()
743739

744740
async def test():
745741
# Reset proxy state for a clean circuit.
@@ -940,7 +936,10 @@ async def post(self, *args, **kwargs):
940936
(b"null", "null"),
941937
(b'"string"', "string"),
942938
(b"123", "number"),
943-
(b'[{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}, {"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}]', "batch array"),
939+
(
940+
b'[{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}, {"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}]',
941+
"batch array",
942+
),
944943
]
945944
for body, label in cases:
946945
resp = await client.post("/mcp", data=body)
@@ -993,7 +992,9 @@ async def aclose(self):
993992

994993
async def post(self, *args, **kwargs):
995994
CountingClient.calls += 1
996-
return FakeResponse(200, json.dumps({"jsonrpc": "2.0", "id": 1, "result": []}).encode())
995+
return FakeResponse(
996+
200, json.dumps({"jsonrpc": "2.0", "id": 1, "result": []}).encode()
997+
)
997998

998999
proxy._http_client = CountingClient()
9991000

0 commit comments

Comments
 (0)