Skip to content

Commit 93577cb

Browse files
committed
chore: Improve Python event handlers test coverage
1 parent 7c46144 commit 93577cb

File tree

3 files changed

+360
-204
lines changed

3 files changed

+360
-204
lines changed

DEVELOP.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ uv sync --all-extras --dev
7979
# For development
8080
uv run ruff check .
8181
uv run pyright
82-
uv run pytest
82+
uv run pytest # coverage report will be in htmlcov/index.html
8383
```
8484

8585
### Build the Typescript package
@@ -96,7 +96,7 @@ npm run build
9696
npm link
9797

9898
# For development
99-
npm test (coverage report will be in coverage/index.html)
99+
npm test # coverage report will be in coverage/index.html
100100
npm run lint
101101
```
102102

src/python/src/mcp_lambda/handlers/streamable_http_handler.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ def process_http_request(
187187
)
188188

189189
# Handle both single messages and batches according to MCP spec
190-
if isinstance(parsed_body, list):
190+
is_batch_request = isinstance(parsed_body, list)
191+
if is_batch_request:
191192
messages = parsed_body
192193
else:
193194
messages = [parsed_body]
@@ -268,12 +269,21 @@ def process_http_request(
268269
}
269270

270271
# Return the response(s)
271-
if len(responses) == 1:
272-
response_body = responses[0].model_dump(by_alias=True, exclude_none=True)
273-
else:
272+
# For batch requests, always return an array even if there's only one response
273+
# For single requests, return a single object
274+
if is_batch_request:
274275
response_body = [
275276
r.model_dump(by_alias=True, exclude_none=True) for r in responses
276277
]
278+
else:
279+
# Single request - return single response object
280+
if len(responses) == 1:
281+
response_body = responses[0].model_dump(by_alias=True, exclude_none=True)
282+
else:
283+
# This shouldn't happen for single requests, but handle gracefully
284+
response_body = [
285+
r.model_dump(by_alias=True, exclude_none=True) for r in responses
286+
]
277287

278288
return HttpResponse(
279289
status_code=200, headers=response_headers, body=json.dumps(response_body)

0 commit comments

Comments
 (0)