From eae4a6df14de53025658e902e68035f468f57fee Mon Sep 17 00:00:00 2001 From: "sentry[bot]" <39604003+sentry[bot]@users.noreply.github.com> Date: Mon, 23 Nov 2026 10:54:09 +0000 Subject: [PATCH 1/2] =?UTF-8?q?fix(api):=20=E6=94=AF=E6=8C=81=E7=A9=BA?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E4=BD=93=E6=9F=A5=E8=AF=A2=E5=85=A8=E9=83=A8?= =?UTF-8?q?=E9=98=9F=E5=88=97=E3=80=81=E8=AE=A1=E5=88=92=E4=B8=8E=E6=89=98?= =?UTF-8?q?=E7=AE=A1=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/plan.py | 2 +- app/api/queue.py | 4 +- app/api/scripts/management.py | 4 +- changelog.d/mcp-get-all-empty-body.fix.md | 1 + tests/api/test_get_all_without_body.py | 47 +++++++++++++++++++++++ 5 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 changelog.d/mcp-get-all-empty-body.fix.md create mode 100644 tests/api/test_get_all_without_body.py diff --git a/app/api/plan.py b/app/api/plan.py index da3b1b75f..3826b22ed 100644 --- a/app/api/plan.py +++ b/app/api/plan.py @@ -196,7 +196,7 @@ async def add_plan(plan: PlanCreateIn = Body(...)) -> PlanCreateOut: response_model=PlanGetOut, status_code=200, ) -async def get_plan(plan: PlanGetIn = Body(...)) -> PlanGetOut: +async def get_plan(plan: PlanGetIn = Body(default_factory=PlanGetIn)) -> PlanGetOut: try: raw_index, raw_data = await Config.get_plan(plan.planId) diff --git a/app/api/queue.py b/app/api/queue.py index 56e821a29..b7fe01d66 100644 --- a/app/api/queue.py +++ b/app/api/queue.py @@ -196,7 +196,9 @@ async def add_queue() -> QueueCreateOut: response_model=QueueGetOut, status_code=200, ) -async def get_queues(queue: QueueGetIn = Body(...)) -> QueueGetOut: +async def get_queues( + queue: QueueGetIn = Body(default_factory=QueueGetIn), +) -> QueueGetOut: try: index, config = await Config.get_queue(queue.queueId) diff --git a/app/api/scripts/management.py b/app/api/scripts/management.py index 91c84823f..6d261234d 100644 --- a/app/api/scripts/management.py +++ b/app/api/scripts/management.py @@ -311,7 +311,9 @@ async def add_script(script: ScriptCreateIn = Body(...)) -> ScriptCreateOut: response_model=ScriptGetOut, status_code=200, ) -async def get_script(script: ScriptGetIn = Body(...)) -> ScriptGetOut: +async def get_script( + script: ScriptGetIn = Body(default_factory=ScriptGetIn), +) -> ScriptGetOut: try: index, data = await Config.get_script(script.scriptId) diff --git a/changelog.d/mcp-get-all-empty-body.fix.md b/changelog.d/mcp-get-all-empty-body.fix.md new file mode 100644 index 000000000..83fd10074 --- /dev/null +++ b/changelog.d/mcp-get-all-empty-body.fix.md @@ -0,0 +1 @@ +修复 MCP 以空参数查询全部队列、计划或托管时因缺少请求体返回 422 的问题。 diff --git a/tests/api/test_get_all_without_body.py b/tests/api/test_get_all_without_body.py new file mode 100644 index 000000000..fe51264b5 --- /dev/null +++ b/tests/api/test_get_all_without_body.py @@ -0,0 +1,47 @@ +"""全部查询接口未携带请求体时按查询全部处理,避免 MCP 空参数返回 422。""" + +import uuid +from unittest.mock import AsyncMock, MagicMock + +import httpx +import pytest +from fastapi import FastAPI + +import app.api.plan as plan_api +import app.api.queue as queue_api +import app.api.scripts.management as script_api + + +def _config_stub(method: str) -> MagicMock: + stub = MagicMock() + setattr(stub, method, AsyncMock(return_value=([], {}))) + for name in ("QueueConfig", "PlanConfig", "ScriptConfig"): + getattr(stub, name).uid = uuid.uuid4() + return stub + + +@pytest.mark.asyncio +@pytest.mark.parametrize( + ("module", "method", "path"), + [ + (queue_api, "get_queue", "/api/queue/get"), + (plan_api, "get_plan", "/api/plan/get"), + (script_api, "get_script", "/api/scripts/get"), + ], +) +async def test_get_all_without_body(monkeypatch, module, method, path) -> None: + stub = _config_stub(method) + monkeypatch.setattr(module, "Config", stub) + app = FastAPI() + if module is script_api: + app.include_router(module.router, prefix="/api/scripts") + else: + app.include_router(module.router) + async with httpx.AsyncClient( + transport=httpx.ASGITransport(app=app), base_url="http://test" + ) as client: + for kwargs in ({}, {"json": {}}): + response = await client.post(path, **kwargs) + assert response.status_code == 200, response.text + assert response.json()["code"] == 200, response.text + getattr(stub, method).assert_awaited_with(None) From 319ddd769e2d585eb4e5d62c3cdcffce51d6ecf5 Mon Sep 17 00:00:00 2001 From: "sentry[bot]" <39604003+sentry[bot]@users.noreply.github.com> Date: Mon, 23 Nov 2026 10:59:42 +0000 Subject: [PATCH 2/2] =?UTF-8?q?docs(changelog):=20=E6=9B=B4=E6=96=B0=20MCP?= =?UTF-8?q?=20=E7=A9=BA=E5=8F=82=E6=95=B0=E6=9F=A5=E8=AF=A2=E5=8F=98?= =?UTF-8?q?=E6=9B=B4=E6=97=A5=E5=BF=97=E6=9D=A1=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog.d/mcp-get-all-empty-body.fix.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/changelog.d/mcp-get-all-empty-body.fix.md b/changelog.d/mcp-get-all-empty-body.fix.md index 83fd10074..2200ee023 100644 --- a/changelog.d/mcp-get-all-empty-body.fix.md +++ b/changelog.d/mcp-get-all-empty-body.fix.md @@ -1 +1,2 @@ -修复 MCP 以空参数查询全部队列、计划或托管时因缺少请求体返回 422 的问题。 +project: tools +修复 MCP 空参数查询全部队列、计划或托管时返回 422 的问题