-
Notifications
You must be signed in to change notification settings - Fork 658
Add structured output to the Python weather server and client and update to v2 #164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,13 @@ | ||
| # An LLM-Powered Chatbot MCP Client written in Python | ||
|
|
||
| See the [Build an MCP client](https://modelcontextprotocol.io/docs/develop/build-client) tutorial for more information. | ||
|
|
||
| ## Structured output | ||
|
|
||
| `call_tool` validates every result against the tool's declared output schema, so the spec's client-side SHOULD needs no code here. | ||
|
|
||
| The two channels go to different readers: `content` is forwarded to the model, while `structured_content` is used as data — the client counts the items it returns. See [Structured Content](https://modelcontextprotocol.io/specification/draft/server/tools#structured-content). | ||
|
|
||
| `Client(transport, mode="auto")` probes `server/discover` and falls back to the `2025-11-25` handshake; `client.protocol_version` reports which era you got. See [Protocol versions](https://py.sdk.modelcontextprotocol.io/v2/protocol-versions/). | ||
|
|
||
| Requires the `mcp` 2.0 prereleases, so `pyproject.toml` sets `[tool.uv] prerelease = "allow"`. | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,13 @@ | ||
| # A Simple MCP Weather Server written in Python | ||
|
|
||
| See the [Build an MCP server](https://modelcontextprotocol.io/docs/develop/build-server) tutorial for more information. | ||
|
|
||
| ## Structured output | ||
|
|
||
| Both tools declare an output schema and return `structured_content`. `get_forecast` returns an object; `get_alerts` returns a top-level JSON array, which protocol revision `2026-07-28` is the first to allow — see [Structured Content](https://modelcontextprotocol.io/specification/draft/server/tools#structured-content) in the spec. | ||
|
|
||
| `Alerts` is a `RootModel[list[Alert]]` rather than a plain `list[Alert]` because the SDK wraps non-object return types as `{"result": ...}`; a `RootModel` is taken as the schema exactly as written. See [Structured Output](https://py.sdk.modelcontextprotocol.io/v2/servers/structured-output/) in the SDK docs. | ||
|
|
||
| Note that an array-rooted schema requires a `2026-07-28` client. This SDK does not project it down for older ones — it raises instead. | ||
|
|
||
| Requires the `mcp` 2.0 prereleases, so `pyproject.toml` sets `[tool.uv] prerelease = "allow"`. | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will remove this before un-drafting. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,9 +4,10 @@ version = "0.1.0" | |
| description = "A simple MCP weather server" | ||
| readme = "README.md" | ||
| requires-python = ">=3.10" | ||
| # httpx2 is a hard dependency of mcp, so it is not listed here — installing | ||
| # `mcp` already brings it in, and adding httpx would install a second HTTP stack. | ||
| dependencies = [ | ||
| "httpx>=0.28.1", | ||
| "mcp[cli]>=1.26.0", | ||
| "mcp[cli]>=2.0.0b2", | ||
| ] | ||
|
|
||
| [build-system] | ||
|
|
@@ -18,6 +19,11 @@ dev = [ | |
| "ruff>=0.15.8", | ||
| ] | ||
|
|
||
| # The 2026-07-28 protocol revision only ships in the mcp 2.0 prereleases, so | ||
| # allow them without every command needing --prerelease=allow. | ||
| [tool.uv] | ||
| prerelease = "allow" | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will remove this before un-drafting. |
||
|
|
||
| [project.scripts] | ||
| weather = "weather:main" | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will remove this before un-drafting.