Title: docs: load media examples from disk instead of inline base64 by maxisbey · Pull Request #3108 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: docs: load media examples from disk instead of inline base64 by maxisbey · Pull Request #3108 · modelcontextprotocol/python-sdk
X Title: docs: load media examples from disk instead of inline base64 by maxisbey · Pull Request #3108 · modelcontextprotocol/python-sdk
Description: Rework the media docs examples to load their files from disk instead of embedding a base64 blob. Motivation and Context The image/audio tutorials on the media page opened with LOGO_PNG = base64.b64decode("iVBORw0KGgo...") — the first thing a reader met was an opaque blob rather than the API being taught, and it read as if conjuring base64 by hand were part of the job. The examples now show the realistic pattern: Image(path=...) / Audio(path=...) pointing at logo.png / chime.wav beside the server. The paths are anchored with Path(__file__).parent so the example keeps working when a host launches the stdio server from an arbitrary working directory (hosts generally do — a bare relative path would resolve against wherever that happens to be), and the page now says so explicitly. The data= + format= mode is still taught in "Bytes or a file", reframed as the mode for bytes that never touch disk (Pillow output, screenshots, ...). No binary asset is committed: the tests fabricate the files in tmp_path and repoint the tutorials' module-level path constants (the same pattern FastAPI's docs tests use for its FileResponse examples). The SDK never parses the contents, so opaque bytes suffice. Also fixed while here: the audio wire-format illustration showed the base64 of the now-deleted placeholder (its RIFF size field included), which no reader's own WAV would reproduce — truncated to the universal prefix. How Has This Been Tested? tests/docs_src/test_media.py updated: fabricated assets in tmp_path, exact ImageContent/AudioContent round-trip assertions, plus a new test pinning that path= files are read when the result is built (which is what makes the fabricate-then-call pattern sound). Drove both tutorial files end-to-end over a real stdio subprocess (mcp run + stdio_client): image and audio round-trip byte-for-byte with the files on disk; a missing file surfaces as a clean tool error naming the path; launching the server from a different working directory still resolves the files (the __file__ anchoring at work). Breaking Changes None — docs and tests only. Types of changes Bug fix (non-breaking change which fixes an issue) New feature (non-breaking change which adds functionality) Breaking change (fix or feature that would cause existing functionality to change) Documentation update Checklist I have read the MCP Documentation My code follows the repository's style guidelines New and existing tests pass locally I have added appropriate error handling I have added or updated documentation as needed Additional context The old examples' data= mode (with the format= caveat) is still covered by test_raw_data_without_a_format_falls_back_to_a_default_mime_type and the !!! check admonition — nothing the page previously taught was dropped, the two construction modes just swapped billing. AI Disclaimer
Open Graph Description: Rework the media docs examples to load their files from disk instead of embedding a base64 blob. Motivation and Context The image/audio tutorials on the media page opened with LOGO_PNG = base64.b64...
X Description: Rework the media docs examples to load their files from disk instead of embedding a base64 blob. Motivation and Context The image/audio tutorials on the media page opened with LOGO_PNG = base64.b64...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/pull/3108
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:3f0fd939-d48e-7af1-e3bd-7c127c8d6c16 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 8D96:12243E:5ADA66:83D951:6A620E36 |
| html-safe-nonce | 9026d7fb8a8d4020f2ae87de0f5e084df53d34065ef1163477d42fd75added38 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RDk2OjEyMjQzRTo1QURBNjY6ODNEOTUxOjZBNjIwRTM2IiwidmlzaXRvcl9pZCI6IjMxNjgyNTkwNjk1MDcxNDUyNzEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 26d12833db3fee93b610da5c8c96bd09e28cca84209bc21ba344f0cdf8fc65d1 |
| hovercard-subject-tag | pull_request:4070700234 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/modelcontextprotocol/python-sdk/pull/3108/files |
| twitter:image | https://avatars.githubusercontent.com/u/224885523?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/224885523?s=400&v=4 |
| og:image:alt | Rework the media docs examples to load their files from disk instead of embedding a base64 blob. Motivation and Context The image/audio tutorials on the media page opened with LOGO_PNG = base64.b64... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | be9a4d9589756e22b427637ffbf1123a96e067050e57f5cec403e3080a650ca4 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git |
| octolytics-dimension-user_id | 182288589 |
| octolytics-dimension-user_login | modelcontextprotocol |
| octolytics-dimension-repository_id | 862584018 |
| octolytics-dimension-repository_nwo | modelcontextprotocol/python-sdk |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 862584018 |
| octolytics-dimension-repository_network_root_nwo | modelcontextprotocol/python-sdk |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7b5509702f01f876c214a2cbb142690847de0019 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width