Skip to content

examples: add interactive media picker MCP app - #5281

Merged
zzstoatzz merged 31 commits into
mainfrom
examples/media-picker-app
Sep 30, 2026
Merged

zzstoatzz merged 31 commits into
mainfrom
examples/media-picker-app

Conversation

@zzstoatzz

@zzstoatzz zzstoatzz commented Sep 26, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Adds an interactive media picker MCP App: the model passes YouTube links it found, the server verifies each through oEmbed and renders the playable ones, and Play and Save run as app-only tools without another model turn. Play can drive a real TV by calling a play_media tool on another MCP server; the smart-home example's Fire TV server provides one.

what's in it
  • examples/apps/media_picker/: the FastMCPApp picker, its CSS, README, and tests. Links that can't be verified are counted, not shown. Without an actuator configured, Play returns a demo receipt.
  • examples/smart_home/: a play_media(source, source_id, url, title) tool on the Fire TV server (YouTube only), and the Fire TV connection now opens on the first tool call instead of at startup, so a sleeping TV no longer takes the lights down with it.
  • examples/smart_home/docs/usage.md: setup and operation, including "No route to host" on macOS, which is Local Network privacy rather than an ADB problem.
  • docs/apps/examples.mdx: an entry for the picker.
design notes
  • YouTube is the only source. Other streaming apps don't share a way to open a specific title (Netflix's deep links stop at the profile picker), so the picker doesn't pretend to be source-agnostic, and there is no per-source configuration.
  • The picker never chooses media itself: whatever the model found and the server could verify is what appears.
  • A device that can't play an item reports it through the actuator tool's error, which the picker surfaces as a playback failure.

Contribution type

  • Bug fix (simple, well-scoped fix for a clearly broken behavior)
  • Documentation improvement
  • Enhancement (maintainers typically implement enhancements — see CONTRIBUTING.md)

Verification

  • uv run pytest examples/apps/media_picker/test_media_picker.py -q (16 passed)
  • PYTHONPATH=src uv run --with 'androidtv[async]==0.0.75' --with pydantic-settings --with phue2==1.0.0a1 pytest -q in examples/smart_home (12 passed)
  • uv run pytest tests/docs -n 0 (67 passed)
  • uv run prek run --all-files

Checklist

  • This PR addresses a self-contained example addition
  • I have read CONTRIBUTING.md
  • I have added tests that cover my changes
  • I have run uv run prek run --all-files and all checks pass
  • I have self-reviewed my changes
  • If I used an LLM, it followed the repo's contributing conventions (not generic output)

🤖 Generated with Claude Code

@marvin-context-protocol marvin-context-protocol Bot added documentation Updates to docs, examples, or guides. Primary change is documentation-related. mcp apps Related to MCP Apps - user-facing applications with frontend bundles served by MCP servers. labels Sep 26, 2026
zzstoatzz and others added 8 commits September 25, 2026 23:02
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017uN3zXKrzsKxYKNmkNK9Dz
…tocol sign-in

Drop the static catalog: the model searches, show_media_picker takes URLs,
and each link is checked with YouTube oEmbed before it renders. Setting
MEDIA_PICKER_BASE_URL requires sign-in through ATProtoProvider.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017uN3zXKrzsKxYKNmkNK9Dz
zzstoatzz and others added 6 commits September 26, 2026 01:13
show_home renders every Hue room with its live color, an on/off switch,
brightness presets and saved scenes, next to the verified TV picks. Light
changes go through app-only tools to the smart-home Hue server over MCP.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017uN3zXKrzsKxYKNmkNK9Dz
With a single allowed DID the server already knows who is signing in, so
the login step goes straight to that account's PDS. The handle page still
renders when there is an error to show.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017uN3zXKrzsKxYKNmkNK9Dz
@marvin-context-protocol

Copy link
Copy Markdown
Contributor

Summary

Failed job: MCP conformance tests — tests/conformance/test_conformance.py::test_mcp_conformance

What failed: The pinned @​modelcontextprotocol/conformance@​0.2.0-alpha.10 suite reported 3 unexpected failures (not present in tests/conformance/expected-failures.yml):

  • tasks-wire-fields (1 passed, 2 failed)
  • tasks-mrtr-input (0 passed, 3 failed)
  • tasks-dispatch-and-envelope (7 passed, 1 failed)

tasks-mrtr-composition also failed but is a documented, already-expected baseline failure (tests/conformance/expected-failures.yml:23). The other 158 scenarios passed.

Evidence traced

The PR (#5281) only touches:

  • docs/apps/examples.mdx, docs/docs.json, docs/integrations/atproto.mdx
  • examples/apps/media_picker/*, examples/smart_home/*
  • fastmcp_slim/fastmcp/experimental/auth/atproto/*, fastmcp_slim/fastmcp/server/auth/ssrf.py (modified)
  • tests/experimental/auth/test_atproto.py

None of these intersect with fastmcp_tasks/, tests/conformance/server.py, or tests/conformance/expected-failures.yml — the code paths exercising the failing scenarios. tests/conformance/server.py:634-720 defines the task fixtures (slow_compute, confirm_delete, multi_input, test_tool_with_task) exactly as the failing scenarios' names describe (wire fields, MRTR input, dispatch/envelope), and the PR diff never touches that file or the fastmcp_tasks package that implements the extension (fastmcp_tasks/fastmcp_tasks/input_loop.py, seen executing normally in the log at lines 1525-1540 for an unrelated protocol_error_job scenario that passed).

The conformance runner (tests/conformance/test_conformance.py:1-14) explicitly notes it pins the npm suite version specifically so that upstream scenario additions "turn CI red on somebody else's release rather than on a change of ours" — implying failures here are expected to sometimes be independent of the PR's own diff, and are meant to be reconciled by updating expected-failures.yml, not the application code.

The log gives no per-assertion detail for the three failing scenarios beyond the pass/fail counts (the npx conformance CLI's own verbose scenario output wasn't captured beyond Running client scenario '...' headers), so the specific protocol mismatch inside tasks-wire-fields / tasks-mrtr-input / tasks-dispatch-and-envelope is not yet identified from this log alone.

What remains unknown / verification needed

I could not execute code or query GitHub to confirm whether this is:

  • (a) a pre-existing regression on main (e.g., a recent change to fastmcp_tasks broke MRTR/task wire-field handling and expected-failures.yml simply hasn't been updated), or
  • (b) newly surfaced only because this run picked up scenario content differences despite the pinned version (unlikely, since alpha versions on npm are still immutable once published, but not something I verified directly), or
  • (c) genuinely triggered by this PR through an indirect path I haven't found (e.g., if fastmcp_slim/fastmcp/server/auth/ssrf.py is imported transitively by something in the conformance server — I did not find such an import, but didn't exhaustively trace every module load).

I lean toward (a): unrelated pre-existing failure, given the complete lack of file overlap and the fact these are task-extension protocol scenarios untouched by this diff. But per instructions I won't label it "pre-existing" without confirming it also fails on the base commit.

Concrete next action

Run (or ask CI to re-run) the same conformance job against the PR's base commit (561c99f91d1315410ff5132c48ceeedeafa6de07, i.e. main before this PR merges) to see if tasks-wire-fields, tasks-mrtr-input, and tasks-dispatch-and-envelope fail there too. If they do, this confirms the failure predates the PR and the fix belongs in fastmcp_tasks/tests/conformance/server.py (or an expected-failures.yml update with a documented reason), not in this docs/example PR — which can then be merged independently.

CI evidence

Revision: 74f05d6

MCP conformance tests

zzstoatzz and others added 3 commits September 26, 2026 03:17
FastMCPApp.ui built its AppConfig without a CSP, so an app UI could not load
images or other resources from outside the renderer's defaults, unlike tools
registered with PrefabAppConfig(csp=...).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017uN3zXKrzsKxYKNmkNK9Dz
…olor

Room rows take their tint, lamp glow, switch and active-scene chip from the
room's live Hue color; scene chips show each scene's palette color. Watch
rows use YouTube thumbnails, which the UI's CSP now allows. Tokens and row
treatment follow plyr.fm, scene swatches follow after-hours.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017uN3zXKrzsKxYKNmkNK9Dz
github-advanced-security[bot]

This comment was marked as resolved.

Level, scene, power and color highlights were rendered from server data,
so they stayed on the old values after a tap. Each room now holds its
state client-side; taps update it before the command is sent, and the
glow, readout and header count follow it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017uN3zXKrzsKxYKNmkNK9Dz
zzstoatzz and others added 5 commits September 26, 2026 16:04
… sign-in

Handles now resolve from their own _atproto TXT record or well-known file
instead of a Bluesky AppView. After the token exchange the provider resolves
the DID, PDS and authorization server again and requires the same issuer,
and the handle claim is set only when the handle resolves back to the DID.
The docs describe handles, DIDs and hosting as separate layers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017uN3zXKrzsKxYKNmkNK9Dz
…hooks

The provider no longer carries its own AT Protocol client: the new
`atproto` extra installs atproto-oauth, which handles resolution, PAR,
DPoP, token exchange, re-verification and revocation. OAuthProxy's
upstream callback now calls two overridable steps, the callback's
transaction ID and the code exchange, so the provider plugs into them
instead of replacing the callback.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017uN3zXKrzsKxYKNmkNK9Dz
zzstoatzz and others added 7 commits September 27, 2026 21:41
The home view, Hue controls and AT Protocol sign-in moved to a separate
deployment; thumbnails need FastMCPApp.ui(csp=), which lands separately.
Changes outside examples/ go back to main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017uN3zXKrzsKxYKNmkNK9Dz
YouTube is the only source the picker verifies, so a required setting whose one legal value is youtube only added configuration. A device that can't play an item now reports it through the actuator's error, which the picker surfaces as a playback failure; a test covers that path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185U3LZpcxFQQJnb6ABuxr1
The lifespan opened the ADB connection at startup and raised when the TV was unavailable, so a sleeping TV stopped the whole server, lights included. FireTVConnection now connects on the first tool call, reconnects on later calls, and raises a ToolError while the TV is unreachable.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185U3LZpcxFQQJnb6ABuxr1
…k privacy

Restarting the ADB daemon only appeared to fix it because the restarted daemon inherited a different launching app's permission. Also document that a sleeping TV no longer blocks startup.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185U3LZpcxFQQJnb6ABuxr1
…ient-specific copy

Links the picker can't parse are reported as "aren't YouTube videos" instead of "can't play on this device", which was wrong without an actuator; state carries unsupported_count. The empty state and "more like this" no longer mention Claude or a home view the example doesn't have.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185U3LZpcxFQQJnb6ABuxr1
…they are

The README still called the picker's input a sample catalog, and both docs described every device connection as pooled at startup; the Fire TV now connects on first use.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185U3LZpcxFQQJnb6ABuxr1
@zzstoatzz
zzstoatzz marked this pull request as ready for review September 30, 2026 04:11
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-30T04:14:49.046333Z 3d1d822 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3d1d82252f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


def youtube_video_id(url: str) -> str | None:
"""Extract a video ID from the common YouTube URL shapes."""
parsed = urlparse(url.strip())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Treat malformed URLs as unsupported links

When the model supplies a syntactically malformed URL such as https://[bad, urlparse() raises ValueError here, causing show_media_picker to fail instead of counting the bad entry and rendering the remaining candidates. This contradicts the behavior documented in examples/apps/media_picker/README.md, where links that cannot be verified or played are counted rather than shown; catch parsing errors per link and return None.

AGENTS.md reference: AGENTS.md:L176-L178

Useful? React with 👍 / 👎.

Comment on lines +54 to +56
if self._client is None:
try:
self._client = await setup_android_tv(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Serialize lazy Fire TV initialization

When two MCP tool calls arrive before the first setup_android_tv() await completes, both observe _client is None and create separate device connections. The later assignment overwrites one connection, so it is never closed by close(), and concurrent commands may use different clients despite this class promising one connection; protect initialization with an async lock and recheck _client inside it.

AGENTS.md reference: AGENTS.md:L180-L182

Useful? React with 👍 / 👎.

@zzstoatzz
zzstoatzz merged commit b67c66e into main Sep 30, 2026
17 of 18 checks passed
@zzstoatzz
zzstoatzz deleted the examples/media-picker-app branch September 30, 2026 04:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Updates to docs, examples, or guides. Primary change is documentation-related. mcp apps Related to MCP Apps - user-facing applications with frontend bundles served by MCP servers.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants