feat: MCP server mode for AI agents#27
Conversation
Wrap existing CLI surface as FastMCP tools so AI agents can manage a YouTube channel via the Model Context Protocol. Read tools always on; write tools gated behind YTSTUDIO_MCP_ALLOW_WRITE=1 or --allow-write. Adds ytstudio mcp serve, ytstudio mcp tools, ytstudio mcp print-config. Optional install: uv tool install "ytstudio-cli[mcp]".
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
Warning Review the following alerts detected in dependencies. According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.
|
|
Closing per current direction; only the playlists PR (#25) is being shipped from this trio. Branch left in place in case we revisit. |
Summary
ytstudio mcpsub-app exposes the CLI surface as FastMCP tools so AI agents (Claude Desktop, Cursor, custom clients) can manage a channel through the Model Context Protocol.--allow-writeor withYTSTUDIO_MCP_ALLOW_WRITE=1set in the environment.--read-onlyforces a read-only server regardless.uv tool install "ytstudio-cli[mcp]".fastmcpis a lazy import; the cold CLI startup cost is unchanged for non-MCP commands and the rest of the CLI still works when the extra is not installed.Highlights
ytstudio mcp serve [--transport stdio|http] [--host] [--port] [--allow-write] [--read-only] [--profile] [--log-level]ytstudio mcp tools [--output table|json] [--allow-write]ytstudio mcp print-config [--client claude-desktop|cursor|generic] [--name] [--allow-write](no fastmcp import, no API calls)whoami,list_videos,get_video,list_categories,analytics_overview,analytics_query,list_comments,list_broadcasts,get_broadcast,list_playlists,get_playlist,list_playlist_items,list_captions.update_video,publish_comments,reject_comments,schedule_broadcast,transition_broadcast,update_broadcast,create_playlist,update_playlist,delete_playlist,add_to_playlist,remove_from_playlist._redact_keyhelper, even when the server is started with--allow-write.ToolErrorinstead ofSystemExit, so a single failing call no longer kills the server.127.0.0.1by default;--host 0.0.0.0prints a stderr warning about the lack of transport-level auth.YTSTUDIO_MCP_ALLOW_WRITE=1. Precedence:--read-only>--allow-write> env var > default off.docs/mcp.mddocument the install snippet, Claude Desktop config, full tool inventory, and the security model.mkdocs.ymlnav updated.Example Claude Desktop snippet emitted by
ytstudio mcp print-config:{ "mcpServers": { "ytstudio": { "command": "/usr/local/bin/ytstudio", "args": ["mcp", "serve"] } } }Test plan
uv sync --group dev --extra mcpuv run ruff check .uv run ruff format --check .uv run pytest -q(full suite: 232 passed, including 27 new MCP tests)tests/test_mcp_cli.py), in-memory FastMCP client interaction with read + write tools (tests/test_mcp_server.py), and write-gate precedence (tests/test_mcp_env_gating.py).ytstudio mcp servefrom Claude Desktop using the generated config snippet and confirm tool discovery.ToolErrors instead of killing the server.get_broadcastredacts the stream key in--allow-writemode.Out of scope
src/ytstudio/mcp/playlists.pyso the new tools are not blocked on the CLI work.captions().insert/update/delete) are deliberately deferred; onlylist_captionsis exposed in this PR.127.0.0.1by default and warns on non-loopback bindings.