From ac185b9e21564f19cc40708a732e9dd35ba2c7bb Mon Sep 17 00:00:00 2001 From: kei Date: Tue, 2 Jun 2026 12:39:53 +0200 Subject: [PATCH] fix(mcp): enforce exact format enum --- app/mcp_tools.py | 9 ++++----- tests/test_api_mcp.py | 3 +++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/mcp_tools.py b/app/mcp_tools.py index 4ddbb2a4..c48885d4 100644 --- a/app/mcp_tools.py +++ b/app/mcp_tools.py @@ -92,15 +92,14 @@ def optional_clean_str_arg(field: str) -> str | None: return clean or None def output_format_arg() -> str: - value = args.get("format", "text") - if value is None: + if "format" not in args: return "text" + value = args["format"] if not isinstance(value, str): raise ValueError("format must be a string") - normalized = value.strip().lower() - if normalized not in {"text", "json"}: + if value not in {"text", "json"}: raise ValueError("format must be text or json") - return normalized + return value def optional_repo_selector_arg() -> str | None: repo = optional_clean_str_arg("repo") diff --git a/tests/test_api_mcp.py b/tests/test_api_mcp.py index fd3c9257..f581df6f 100644 --- a/tests/test_api_mcp.py +++ b/tests/test_api_mcp.py @@ -1810,10 +1810,13 @@ def test_mcp_submit_work_proof_scopes_issue_number_by_repo(sqlite_url: str) -> N ({"bounty_id": 1, "issue_number": 1}, 25), ({"format": "xml"}, 26), ({"format": 1}, 27), + ({"format": None}, 28), ({"repo": "ramimbo/mergework"}, 29), ({"bounty_id": 1, "repo": "ramimbo/mergework"}, 30), ({"issue_number": 1, "repo": 1}, 31), ({"issue_number": 1, "repo": "a" * 201}, 32), + ({"format": "JSON"}, 33), + ({"format": " json "}, 34), ], ) def test_mcp_submit_work_proof_rejects_invalid_bounty_selectors(