Yt-to-transcript-MCP
# Yt-to-transcript-MCP
**Turn any YouTube video into a transcript from inside Claude, Gemini, or ChatGPT.**
A single [Model Context Protocol](https://modelcontextprotocol.io/) server,
written in Python. It speaks `stdio` for desktop clients (Claude Desktop,
Claude Code, Gemini CLI) and `streamable-http` / `sse` for remote clients
(ChatGPT web, the OpenAI Responses API). One codebase, three assistants.
Repository: <https://github.com/YassineBadriDev/Yt-to-transcript-MCP>
---
## What it does
```
YouTube URL / video ID
│
├─ 1. youtube-transcript-api → human captions, then auto-generated captions
├─ 2. yt-dlp → direct caption-track download (fallback if 1 is IP-blocked)
└─ 3. Whisper (optional) → download audio + local speech-to-text (videos with NO captions)
│
▼
text · timestamped lines · Markdown · SRT · WebVTT · JSON
```
It also lists available caption languages, translates auto-captions, searches
inside a transcript, slices a time range, and exposes video metadata
(title, channel, duration, chapters). MCP resources and a prompt template are
included too.
> **No API key required.** It uses YouTube's public caption tracks. Whisper
> runs locally and needs no external service either.
## Tools
| Tool | Purpose |
| --- | --- |
| `get_transcript` | Main tool. URL or ID → transcript in `text`, `timestamped`, `markdown`, `srt`, `vtt`, or `json`. Supports `language`, `translate_to`, `prefer`, `max_chars`. |
| `get_video_info` | Title, channel, duration, chapters, views, upload date (via yt-dlp, with an oEmbed fallback). |
| `list_transcript_languages` | All caption tracks, human vs auto-generated, and available translation targets. |
| `get_transcript_range` | Only the captions between two timestamps — essential for long videos. |
| `search_transcript` | Find a word/phrase and get timestamped matches with surrounding context. |
| `save_transcript` | Write the transcript to `.txt` / `.srt` / `.vtt` / `.md` / `.json`. |
| `transcribe_audio` | Whisper fallback for videos with no captions at all. |
Resources: `youtube://video/{id}/info`, `youtube://video/{id}/transcript/{lang}`.
Prompt: `summarize_video`.
## Install
Requires **Python 3.10+**.
```bash
git clone https://github.com/YassineBadriDev/Yt-to-transcript-MCP.git
cd Yt-to-transcript-MCP
python -m venv .venv
.venv\Scripts\activate # Windows | source .venv/bin/activate on Unix
python -m pip install -e .
python -m youtube_mcp --selftest # offline check, no network needed
```
Or without cloning: `python -m pip install -r requirements.txt` and set
`PYTHONPATH=<repo>/src`.
Optional extras:
```bash
python -m pip install -e ".[whisper]" # audio -> text fallback; also needs ffmpeg on PATH
python -m pip install -e ".[dev]" # pytest
python -m pytest tests -q
```
## Use with Claude
### Claude Desktop
Merge `config/claude_desktop_config.json` into:
| OS | Path |
| --- | --- |
| Windows | `%APPDATA%\Claude\claude_desktop_config.json` |
| macOS | `~/Library/Application Support/Claude/claude_desktop_config.json` |
```json
{
"mcpServers": {
"youtube-transcript": {
"command": "python",
"args": ["-m", "youtube_mcp"],
"env": { "YOUTUBE_MCP_DEFAULT_LANGUAGE": "en" }
}
}
}
```
Restart Claude Desktop. If `python` is not on its `PATH` (common on Windows),
replace `command` with the absolute path to your venv's `python.exe`.
### Claude Code
```bash
claude mcp add youtube-transcript -- python -m youtube_mcp
```
Or copy `config/claude_code.mcp.json` to your project root as `.mcp.json`.
See [config/README.md](config/README.md) for all details.
## Use with Gemini
Gemini CLI uses the same `mcpServers` schema. Add `config/gemini_settings.json`
to `~/.gemini/settings.json` (global) or `<project>/.gemini/settings.json`:
```bash
gemini mcp add youtube-transcript python -- -m youtube_mcp
```
Then run `/mcp` to confirm the tools are discovered. Gemini CLI also supports
reading MCP resources with `@youtube://video/<id>/info`.
> Use a hyphenated server name (`youtube-transcript`), not an underscored one —
> Gemini CLI splits policy names on underscores.
Optionally point it at the HTTP server instead:
```json
{ "mcpServers": { "youtube-transcript": { "httpUrl": "http://127.0.0.1:8000/mcp" } } }
```
## Use with ChatGPT
ChatGPT is **remote-only**: it cannot spawn a local stdio process. Start the
HTTP transport and expose it over HTTPS:
```bash
python -m youtube_mcp --transport streamable-http --port 8000 --auth-token "a-long-random-secret"
cloudflared tunnel --url http://127.0.0.1:8000 # or: ngrok http 8000
```
Then either:
- **ChatGPT web** (Business / Enterprise / Edu; Pro has read/fetch-only):
Settings → Plugins → **Add custom MCP server** → `https://<tunnel>/mcp`.
- **OpenAI Responses API** from code (any plan), using the `mcp` tool type:
```python
from openai import OpenAI
resp = OpenAI().responses.create(
model="gpt-5.2",
tools=[{
"type": "mcp",
"server_label": "youtube_transcript",
"server_url": "https://<tunnel>/mcp",
"authorization": "a-long-random-secret",
"require_approval": "never",
}],
input="Transcribe https://youtu.be/dQw4w9WgXcQ and give 3 timestamped highlights.",
)
print(resp.output_text)
```
- **OpenAI Agents SDK** can use the local stdio server, exactly like Claude/Gemini.
Full instructions (auth options, tunnels, Docker, approvals):
[config/chatgpt.md](config/chatgpt.md). Runnable example:
[examples/openai_responses_api.py](examples/openai_responses_api.py).
## Example prompts
```
Transcribe https://www.youtube.com/watch?v=VIDEO_ID as SRT and save it to talk.srt.
```
```
What does https://youtu.be/VIDEO_ID say about diffusion models?
Find the relevant timestamps and quote them.
```
```
List the caption languages available for this video, then translate the
French auto-captions into English.
```
```
Summarize this 2-hour lecture chapter by chapter using its chapters and
get_transcript_range.
```
## Configuration
All settings are environment variables (see [.env.example](.env.example)).
| Variable | Default | Meaning |
| --- | --- | --- |
| `YOUTUBE_MCP_DEFAULT_LANGUAGE` | `en` | Language used when a tool call omits `language`. |
| `YOUTUBE_MCP_TRANSPORT` | `stdio` | `stdio` \| `streamable-http` \| `sse`. |
| `YOUTUBE_MCP_HTTP_HOST` | `127.0.0.1` | Bind address for HTTP transports. |
| `YOUTUBE_MCP_HTTP_PORT` | `8000` | Bind port for HTTP transports. |
| `YOUTUBE_MCP_AUTH_TOKEN` | *(empty)* | Require `Authorization: Bearer <token>` on HTTP. Empty = no auth. |
| `YOUTUBE_MCP_OUTPUT_DIR` | `./transcripts` | Only directory `save_transcript` may write into. |
| `YOUTUBE_MCP_PROXY` | *(empty)* | HTTP proxy, useful on cloud IPs blocked by YouTube. |
| `YOUTUBE_MCP_COOKIES_FROM_BROWSER` | *(empty)* | e.g. `chrome`, for age-restricted / members-only videos. |
| `YOUTUBE_MCP_COOKIES_FILE` | *(empty)* | Netscape-format cookie file for yt-dlp. |
| `YOUTUBE_MCP_WHISPER_MODEL` | `base` | `tiny` \| `base` \| `small` \| `medium` \| `large-v3`. |
CLI flags override the environment:
```bash
python -m youtube_mcp --transport streamable-http --host 0.0.0.0 --port 8080 --auth-token SECRET
```
`GET /health` is always public so tunnels and load balancers can probe it.
## Output formats
| `format` | Shape |
| --- | --- |
| `text` | One clean paragraph of plain text. |
| `timestamped` | `[00:12] line of speech` — one line per caption segment. |
| `markdown` | Title/metadata header plus bold timestamps. |
| `srt` / `vtt` | Ready-to-use subtitle files. |
| `json` | `full_text` plus `segments[{start, end, text}]` and metadata. |
Long videos: pass `max_chars`, or use `search_transcript` +
`get_transcript_range` instead of loading the whole transcript into context.
## Whisper fallback (videos with no captions)
```bash
python -m pip install -e ".[whisper]" # faster-whisper
# also install ffmpeg (winget install ffmpeg / choco install ffmpeg / apt install ffmpeg)
```
Then ask the model to call `transcribe_audio`. It downloads the audio with
yt-dlp and transcribes locally. This is slow — roughly minutes for a long
video — and is deliberately a separate tool so normal caption retrieval stays
instant.
## Troubleshooting
| Symptom | Fix |
| --- | --- |
| `IpBlocked` / `RequestBlocked` | The server automatically falls back to yt-dlp. If both fail, set `YOUTUBE_MCP_PROXY`, or run from a residential IP. |
| `No 'en' captions` | Call `list_transcript_languages`, pass the right `language`, or use `translate_to`. |
| No captions at all | Use `transcribe_audio` (Whisper). |
| Age-restricted / "Sign in to confirm" | Set `YOUTUBE_MCP_COOKIES_FROM_BROWSER=chrome` (or `YOUTUBE_MCP_COOKIES_FILE`). |
| Client cannot find `python` | Use an absolute interpreter path in the config ([config/README.md](config/README.md)). |
| `save_transcript` refuses the path | Files must stay inside `YOUTUBE_MCP_OUTPUT_DIR`. |
| YouTube layout changed | `yt-dlp` updates fast: `python -m pip install -U yt-dlp youtube-transcript-api`. |
| `WebVTT`/`json3` parse issues | Try `prefer="api"` or a different `language`. |
Debug with the MCP Inspector:
```bash
npx @modelcontextprotocol/inspector python -m youtube_mcp
```
## Security notes
- `save_transcript` is sandboxed to `YOUTUBE_MCP_OUTPUT_DIR`; it cannot write
anywhere else.
- When exposing HTTP publicly, **always set `YOUTUBE_MCP_AUTH_TOKEN`** (or put
the server behind OAuth). `/health` remains unauthenticated.
- Never expose an unauthenticated server to the internet just to test ChatGPT;
use a short-lived tunnel instead.
- Transcripts are third-party content. Treat anything returned by a tool as
untrusted data, and be mindful of prompt-injection text inside captions.
## Legal
This tool reads publicly available caption tracks; it does not bypass DRM or
download protected video streams. YouTube captions and video content may be
copyrighted. Summarise and quote short excerpts rather than reproducing entire
works, and comply with YouTube's Terms of Service and your local law.
## Development
```
src/youtube_mcp/
core.py # retrieval engine (no MCP imports, usable as a library)
formats.py # text / timestamped / markdown / srt / vtt / json
server.py # FastMCP tools, resources, prompts
__main__.py # transports, bearer auth, CLI
config/ # ready-to-edit client configs
examples/ # offline smoke test + Responses API example
tests/ # offline unit tests
```
```bash
python -m pytest tests -q
python -m youtube_mcp --selftest
python examples/smoke_test.py dQw4w9WgXcQ # one real network call
```
## License
MIT — see [LICENSE](LICENSE).
TDQS
Scored across 7 tools
Each tool has a clearly distinct role: metadata, language discovery, full transcript, timestamped range, search, file saving, and audio fallback. The only apparent overlap, get_transcript vs transcribe_audio, is explicitly separated by captions vs no-captions fallback usage.
All tool names use consistent snake_case verb_noun conventions such as get_transcript, search_transcript, list_transcript_languages, and save_transcript. Compound names like get_transcript_range still follow the same predictable pattern.
Seven tools is well-scoped for a YouTube transcript server. Each tool earns its place by covering a distinct workflow step without redundant or filler operations.
The surface covers the full practical lifecycle: inspect video info, discover caption languages, fetch transcripts, search and slice long transcripts, save outputs, and fall back to local speech-to-text when captions are absent. No obvious dead ends exist for the stated transcript-extraction purpose.