Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/api/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion app/api/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion app/api/scripts/management.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions changelog.d/mcp-get-all-empty-body.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
project: tools
修复 MCP 空参数查询全部队列、计划或托管时返回 422 的问题
47 changes: 47 additions & 0 deletions tests/api/test_get_all_without_body.py
Original file line number Diff line number Diff line change
@@ -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)