YouTube Transcript MCP Server
README.md
# YouTube Transcript MCP Server (Python, read-only)
A beginner-to-intermediate **YouTube MCP server** built with the official
[MCP Python SDK](https://github.com/modelcontextprotocol/python-sdk). It lets an AI
assistant (Claude, Antigravity, VS Code, any MCP client) **read YouTube transcripts and
video metadata for study sessions** and answer with **citations: a timestamp and a link
that jumps to the exact moment** in the lecture.
It is deliberately safe for campus demos and final-year projects:
- **Read-only.** Six tools, all marked `readOnlyHint`. Nothing is posted, liked, edited or uploaded.
- **Permission prompts.** Before fetching anything for a video, the server asks the user
through an **MCP Elicitation** form (*allow*, *I have the right to use these captions*,
*remember for this video*). Declined or cancelled means **NOT FETCHED**.
- **No scraping, no video downloads.** Data comes from caption files you have rights to,
or from the **official YouTube Data API v3** (`videos.list`, `captions.list`, `captions.download`).
- **Offline tests.** 135 pytest tests, the network is blocked in every test, the API is mocked.
Full tutorial: https://getprojects.org/youtube-mcp-server-python/

## Tools
| Tool | What it returns | Asks permission? |
|---|---|---|
| `video_info(video)` | title, channel, date, duration, link, APA-style reference | yes |
| `get_transcript(video, start_seconds, end_seconds, language, max_segments)` | segments with `timestamp` + jump `url`, paging | yes |
| `search_transcript(video, query, max_results)` | best-matching moments with quote, label, url and ready **markdown citation** | yes |
| `study_outline(video, section_minutes)` | time sections with keywords and a link each | yes |
| `cite_moment(video, seconds, quote)` | citation for a moment, no fetch | no |
| `server_status()` | source, permission policy, recent decisions, terms note | no |
Plus a prompt template, `study_notes(video, topic)`, that tells the model to cite every point.
`video` can be an 11-character ID or any normal YouTube link (`watch?v=`, `youtu.be/`, `/shorts/`, `/embed/`, `/live/`).
Playlists, channels and non-YouTube hosts are rejected before anything happens.
## Quick start (offline, 2 minutes)
```bash
git clone https://github.com/GetProjectsIdea/YouTube-Transcript-MCP-Server-Python.git
cd YouTube-Transcript-MCP-Server-Python
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -e ".[dev]"
youtube-transcript-mcp demo # scripted session with a simulated user
python -m pytest -q # 135 passed
```
The demo uses two sample lecture transcripts in `samples/` (DBMS normalization and OS deadlock).
They were written for this project; their IDs (`GPdemoDBMS1`, `GPdemoOSdl2`) are placeholders, so the links do not open real videos.
## Connect it to an MCP client
```json
{
"mcpServers": {
"youtube-study": {
"command": "youtube-transcript-mcp",
"args": ["serve", "--source", "local", "--captions", "/path/to/your/captions", "--ask", "always"]
}
}
}
```
See `examples/mcp-client-config.json` and `examples/sample-session.md`.
### Sources
**Local caption files (default).** Put `<videoId>.<lang>.vtt`, `<videoId>.srt` or `<videoId>.json`
in a folder, with an optional `<videoId>.meta.json` (`title`, `channel`, `published`, `duration_seconds`).
Good sources: captions you exported from **your own channel** in YouTube Studio, a lecture your teacher
shared with you, or Creative Commons content (keep the attribution).
**Official YouTube Data API v3.** `serve --source youtube` with:
- `YOUTUBE_API_KEY` – public metadata through `videos.list`.
- `YOUTUBE_OAUTH_TOKEN` – an OAuth access token (scope `youtube.force-ssl`) for `captions.list` and
`captions.download`. YouTube only allows caption downloads for videos **you own or can edit**,
and each download costs 200 quota units. A 403 is reported as a friendly error.
The HTTP client only ever calls `www.googleapis.com` with `GET` requests.
### Permission policy
`--ask always` (default) asks before the first read of every video. `--ask network` only asks when the
source uses the internet. `--ask never` turns prompts off (local testing only). Ticking *remember* skips
the prompt for that video until the server restarts.
The prompt is filled by a **resolver** (`Annotated[ElicitationResult[FetchPermission], Resolve(...)]`), so the SDK
uses a standalone `elicitation/create` request on protocol 2025-11-25 and an `InputRequiredResult` round trip
on 2026-07-28. Both are tested.
## Project structure
```
yt_transcript_mcp/
server.py MCP server: tools, permission resolver, prompt
consent.py FetchPermission form + ConsentPolicy (always / network / never)
sources.py LocalSource and YouTubeAPISource (official API, injected HTTP)
captions.py WebVTT / SubRip / JSON parsing, roll-up de-duplication, time helpers
citations.py VideoMeta, timestamp citations, APA-style reference
search.py keyword search with context, study outline
video_ids.py URL/ID parsing and watch links
cli.py serve | demo | cite | parse
samples/ two offline sample lectures
tests/ 135 offline pytest tests (network blocked)
```
## Responsible use
- Follow the [YouTube Terms of Service](https://www.youtube.com/t/terms) and the
[YouTube API Services Terms](https://developers.google.com/youtube/terms/api-services-terms-of-service).
- Use only transcripts you have the right to use. Do not republish full transcripts of other people's videos.
- This project never downloads video or audio and does not scrape YouTube pages.
- Keep API keys and OAuth tokens in environment variables, never in the repo.
## License
MIT © 2026 Pardeep Patel. Made for students by [GetProjects](https://getprojects.org/).
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessOutdated data