feat: structured output support (MCP 2025-06-18 spec) - #16
Merged
Conversation
Tools now return Pydantic model instances (not json.dumps strings) when response_format=json, so FastMCP emits outputSchema and structuredContent. This enables smolagents structured_output=True — the agent sees tool output schemas up front, reducing wasted steps and silencing the FutureWarning. New output models: - Thingiverse: SearchResult, SearchResultItem, ModelDetails, ModelFile, DownloadResult, DownloadedFile, SkippedFile - Cura: SliceResult, SliceSettings, SliceStats - OctoPrint: StatusResult, ServerInfo, ConnectionInfo, TemperatureReading, FileListResult, FileEntry, JobResult, ConnectResult, UploadResult, StartPrintResult, ControlJobResult, TemperatureResult, HomeResult, MoveResult, DryRunPreview Dry-run paths (confirm=false) on actuation tools now return a DryRunPreview model on the JSON path instead of a descriptive string — the tool always returns the declared type. Backward compatibility: - Markdown path (default) unchanged — still returns str - Error strings still return str - JSON payload shape identical — only the Python object type changed Tests updated to assert Pydantic instances on JSON path and str on markdown. New tests verify all 14 tools emit outputSchema and model schemas match. Bumps version 0.1.1 -> 0.2.0.
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.
Summary
Enable smolagents
structured_output=Truesupport so the agent sees tool output schemas upfront, reducing wasted steps and silencing theFutureWarning.Tools now return Pydantic model instances (not
json.dumpsstrings) whenresponse_format="json", so FastMCP emitsoutputSchemaandstructuredContentper the MCP 2025-06-18 spec.Changes
SearchResult,SearchResultItem,ModelDetails,ModelFile,DownloadResult,DownloadedFile,SkippedFileSliceResult,SliceSettings,SliceStatsStatusResult,ServerInfo,ConnectionInfo,TemperatureReading,FileListResult,FileEntry,JobResult,ConnectResult,UploadResult,StartPrintResult,ControlJobResult,TemperatureResult,HomeResult,MoveResult,DryRunPreviewstr)confirm=false) on actuation tools now return aDryRunPreviewmodel on the JSON path — the tool always returns the declared type regardless of the confirm flag-> strto-> str | <ResultModel>(or-> str | DryRunPreview | <ResultModel>for actuation tools)stron the markdown path. New tests verify all 14 tools emitoutputSchemaand that model schemas match.Backward Compatibility
response_format="markdown"path (the default) is unchanged — still returns a human-readablestr."Error: ...") are still returned asstron all paths.structuredContentcarries the same fields.Reference
Consumer
PrintPal/main.pywill passstructured_output=TruetoMCPClientafter this lands.Test Plan
uv run pytest -q— 83 passeduvx ruff check src tests— all checks passeduvx ruff format --check src tests— 10 files already formatteduv build && uvx twine check dist/*— both PASSEDoutputSchema