This repository was archived by the owner on Nov 27, 2026. It is now read-only.
Repository navigation
Raise ServiceError and return it with add_error_contract (SDK 0.7) - #20
Merged
Merged
Conversation
Pin nimblebrain-server-sdk to the 0.7 minor, install add_error_contract where the server is built, and have tools raise ServiceError instead of returning to_tool_error at each site. Tests annotate their protocol-era parameter with nimblebrain_server_sdk.testing.Mode. The result a caller receives is the same.
Contributor
Author
QA Review: sdk-0-7Scope: 6 files, +59/−49 · prepared worktree · reviewed: 20e97b2 · CI: green Critical (must fix)None. Fix in-PRNone. SuggestionsNone. What Looks Good
Body claims
machine record{
"kind": "review",
"pr": 20,
"round": 1,
"reviewed": "20e97b2066dae3c1cdbb483237178f302686c705",
"delta_base": null,
"ci": "green",
"risk": "LOW",
"stop_gate": "n/a",
"verdict": "Approve; no actionable findings.",
"label": "eligible-on-green",
"findings": []
} |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
What
Moves the template onto the idiom
nimblebrain-server-sdk0.7 provides, so a server started from it begins there.nimblebrain-server-sdk>=0.7,<0.8. The SDK is pre-stable and a minor release may change the Python API, so its compatibility page recommends pinning a minor.add_error_contract(mcp)is called once where the server is built, and tools raiseServiceError(...)/ServiceError.from_upstream(...). No tool wraps its body intry/return to_tool_error(...).nimblebrain_server_sdk.testing.Mode.ServiceError;add_error_contractreturns it", and keep the warning never to return an error as a plain dict.Why
Returning
to_tool_error(...)at every failure site means each tool repeats the sameexcept ServiceErrorclause, and a helper that raises (get_client,read_item) needs a catch in every tool that calls it. With the contract installed once, a tool reads as its happy path and a raisedServiceErrorfrom any depth reaches the caller in the same shape.Caller-visible behaviour: unchanged
Modeannotations.is_error,structuredContent,content), the tool listing, and the resource-read errors were recorded onmainand on this branch, on both protocol eras, and are byte-identical. The calls cover bad input, a missing API key, upstream statuses 400, 401, 402, 403, 404, 408, 409, 429, 500, 503 and 504 for both tools, an argument of the wrong type, and an unclassified exception.item_resourcestill turns aServiceErrorinto aResourceErrorcarrying the message safe to show.service_errorlog line.One difference, in the server's own log only
FastMCP logs
Error calling tool '<name>'with a traceback to stderr for any exception a tool raises, before the middleware turns it into the result. A raisedServiceErrortherefore adds a traceback to the server's stderr beside theservice_errorline, including forbad_input. Nothing in it reaches the caller.Testing
make check(ruff format, ruff check, ty, pytest): 49 passed onmain, 49 passed here. Python 3.13.pytest.ini, and it type-checks withty).pytest.ini'serror::mcp.MCPDeprecationWarningfilter, the ruff rules, the scan workflow and the licence are untouched.