MCP: mcp 2.3 (MCPServer, transport arguments on streamable_http_app, bearer read in middleware); tests for the 2026-07-28 revision and the resource check

Claude-Session: https://claude.ai/code/session_01SSi5AvZ7pFmySK8zy3NPMh
This commit is contained in:
2026-10-28 09:21:01 +01:00
parent 32eb8a327a
commit d1ff0e051d
8 changed files with 224 additions and 55 deletions
+33
View File
@@ -39,3 +39,36 @@ def test_a_name_cannot_climb_out_of_its_route() -> None:
"DELETE /api/v1/flows/%2E%2E",
"GET /api/v1/flows/%2E%2E/nodes/%2E%2E%2Fsource/source",
]
def test_the_assistant_calls_a_tool_as_the_person_chatting() -> None:
"""The in-process path: no MCP request, so the person's token is set by hand."""
from fluksio.ai import agent
seen: list[str | None] = []
def record(request: httpx.Request) -> httpx.Response:
seen.append(request.headers.get("authorization"))
return httpx.Response(200, json=[{"name": "home"}])
async def calls() -> tuple[list[dict], str]:
previous = server._client
mock = httpx.AsyncClient(
transport=httpx.MockTransport(record),
base_url="http://test",
event_hooks={"request": [server.forward_caller_auth]},
)
server.set_client(mock)
try:
specs = await agent.tool_specs()
answer = await agent.mcp_caller("Bearer person")("list_flows", {})
finally:
server.set_client(previous)
await mock.aclose()
return specs, answer
specs, answer = asyncio.run(calls())
assert {"list_flows", "run_flow"} <= {s["function"]["name"] for s in specs}
assert all(s["function"]["parameters"]["type"] == "object" for s in specs)
assert seen == ["Bearer person"]
assert "home" in answer