feat: migrate HTTP client to generated ros2-medkit-client#13
Merged
Conversation
Replace hand-written httpx client (~1078 lines) with a wrapper around the generated ros2-medkit-client package. SovdClient interface preserved - zero changes needed in mcp_app.py tool dispatcher. Key changes: - client.py: SovdClient delegates to MedkitClient via _call() with _ENTITY_FUNC_MAP dispatch for entity-type-polymorphic endpoints - Structured SOVD error codes preserved in SovdClientError messages - asyncio.Lock on lazy client init for concurrent safety - SSRF protection on get_bulk_data_info (was missing vs download) - URL-encoded path segments in raw request fallbacks - Extracted _httpx_client(), _extract_filename(), _validate_relative_uri() Also fixes: - update_execution dispatcher used args.request_data instead of args.update_data (pre-existing bug, AttributeError at runtime) - FaultItem model accepts fault_code alias from generated client - Fault formatting fallbacks check both camelCase and snake_case keys Tests updated: mock responses aligned with OpenAPI schema (snake_case field names, required fields). 111 tests pass. Closes #11
There was a problem hiding this comment.
Pull request overview
This PR migrates the MCP server’s SOVD HTTP integration from a large hand-written httpx client to a thin compatibility wrapper around the generated ros2-medkit-client, aiming to preserve the existing SovdClient interface consumed by mcp_app.py.
Changes:
- Replaced the hand-written async HTTP client with a
MedkitClient-backedSovdClientwrapper, including entity-type dispatch via_ENTITY_FUNC_MAP. - Updated fault modeling/formatting to better handle snake_case responses from the generated client.
- Updated tests and mocks to match the generated client’s response shapes; added the
ros2-medkit-clientdependency.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
src/ros2_medkit_mcp/client.py |
Introduces the new MedkitClient-based wrapper, entity dispatch mapping, and raw fallbacks (snapshots/bulk-data). |
src/ros2_medkit_mcp/mcp_app.py |
Adjusts fault formatting fallbacks and fixes update_execution argument wiring. |
src/ros2_medkit_mcp/models.py |
Updates FaultItem to accept the generated client’s fault_code naming. |
tests/test_tools.py |
Updates mocked responses and assertions to the new schema/behavior. |
tests/test_mcp_app.py |
Updates integration-style tests to the new response shapes. |
tests/test_bulkdata_tools.py |
Updates bulk-data test fixtures to new required fields / key casing. |
pyproject.toml |
Adds ros2-medkit-client dependency via a GitHub release wheel URL. |
poetry.lock |
Locks the new dependency and transitive additions. |
- _validate_relative_uri raises SovdClientError instead of ValueError - _raw_request handles JSON decode failures - _call catches ValueError/KeyError from generated client parsing - Narrowed test_non_json_response to assert SovdClientError only - test_get_version_error asserts error code in message - Added comment about URL dependency in pyproject.toml
mfaferek93
reviewed
Mar 30, 2026
mfaferek93
reviewed
Mar 30, 2026
- Auto-wrap body dicts as generated model instances via _wrap_body_dict() (fixes runtime crash in set_configuration and all body-accepting endpoints) - Add import-time validation of _ENTITY_FUNC_MAP function references (fails fast on generator rename instead of silent runtime AttributeError)
mfaferek93
approved these changes
Mar 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request
Summary
Replace hand-written httpx client (~1078 lines) with a wrapper around the generated
ros2-medkit-clientpackage.SovdClientinterface preserved - zero changes needed inmcp_app.pytool dispatcher.Key changes:
client.pydelegates toMedkitClientvia_call()with_ENTITY_FUNC_MAPdispatch for entity-type-polymorphic endpointsSovdClientErrormessagesasyncio.Lockon lazy client init for concurrent safetyget_bulk_data_info(was missing vs download)_httpx_client(),_extract_filename(),_validate_relative_uri()helpersAlso fixes:
update_executiondispatcher usedargs.request_datainstead ofargs.update_data(pre-existing bug)FaultItemmodel acceptsfault_codealias from generated clientNet -209 lines (746 added, 955 removed).
Issue
Type
Testing
poetry run python run_tests.py -v)ruff check), format clean (ruff format --check)Checklist
poetry run ruff check src/ tests/)poetry run ruff format --check src/ tests/)poetry run mypy src/)poetry run python run_tests.py)