Skip to main content
Glama
YouTube Transcript to Markdown MCP Server

YouTube Transcript to Markdown MCP Server

by ncockram
README.md
# YouTube Transcript to Markdown MCP Server

An MCP (Model Context Protocol) server that converts YouTube video transcripts to Markdown format using the `youtube-transcript-api` Python package.

## Features

- Extract transcripts from YouTube videos
- Convert transcripts to well-formatted Markdown
- Include video metadata (title, URL) in output
- Support multiple YouTube URL formats
- Comprehensive error handling
- MCP tool integration

## Installation

### Prerequisites

- Python 3.9 or higher
- pip package manager

### Install from Source

1. Clone this repository:
```bash
git clone <repository-url>
cd youtube-transcript-to-markdown-mcp
```

2. Create and activate a virtual environment (recommended):
```bash
python -m venv venv
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activate
```

3. Install dependencies:
```bash
pip install -r requirements.txt
```

Or install in development mode with test dependencies:
```bash
pip install -e ".[dev]"
```

### Quick Test

To quickly test the installation and basic functionality, you can run the test implementation (if available in your workspace):

```bash
python test_implementation.py
```

Or use the VS Code task if available.

## MCP Integration

This server implements the Model Context Protocol (MCP) and can be used with any MCP-compatible client. The server runs using stdio transport for communication.

### Adding to MCP Client Configuration

To use this server with an MCP client, add it to your client's configuration:

```json
{
  "mcpServers": {
    "youtube-transcript": {
      "command": "youtube-transcript-mcp",
      "args": []
    }
  }
}
```

For development or if installed from source:
```json
{
  "mcpServers": {
    "youtube-transcript": {
      "command": "python",
      "args": ["-m", "youtube_transcript_mcp.server"]
    }
  }
}
```

## Usage

### As MCP Server

The server provides a `get_youtube_transcript` tool that can be called by MCP clients.

#### Tool Schema

```json
{
  "name": "get_youtube_transcript",
  "description": "Extract transcript from YouTube video and save as Markdown file",
  "inputSchema": {
    "type": "object",
    "properties": {
      "youtube_url": {
        "type": "string",
        "description": "YouTube video URL (supports various formats like youtube.com/watch?v=ID or youtu.be/ID)"
      },
      "output_filename": {
        "type": "string",
        "description": "Local filename to save the Markdown transcript (will be sanitized and .md extension added if missing)"
      }
    },
    "required": ["youtube_url", "output_filename"]
  }
}
```

#### Example Usage

```json
{
  "youtube_url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
  "output_filename": "transcript.md"
}
```

### Running the Server

```bash
youtube-transcript-mcp
```

Or run directly:
```bash
python -m youtube_transcript_mcp.server
```

## Configuration

The server supports the following command-line options:

- `--debug`: Enable debug logging
- `--transport`: Transport type (default: stdio)

Example:
```bash
youtube-transcript-mcp --debug
```

## Supported YouTube URL Formats

- `https://www.youtube.com/watch?v=VIDEO_ID`
- `https://youtu.be/VIDEO_ID`
- `https://youtube.com/watch?v=VIDEO_ID`
- `https://m.youtube.com/watch?v=VIDEO_ID`

## Output Format

The generated Markdown file includes:

1. Video title as main header
2. Video metadata block with URL, video ID, and generation timestamp
3. Formatted transcript content with timestamps (if available)
4. Generator attribution

Example output:
```markdown
# Video Title Here

> **Video URL:** https://www.youtube.com/watch?v=VIDEO_ID  
> **Video ID:** `VIDEO_ID`  
> **Generated:** 2025-07-20 10:30:45

---

## šŸ“ Transcript

[00:00] First line of transcript...
[00:05] Second line of transcript...

---

> *This transcript was generated using the YouTube Transcript to Markdown MCP Server.*
```

## Error Handling

The server handles various error scenarios:

- Invalid YouTube URLs
- Videos without available transcripts
- Private or unavailable videos
- Network connectivity issues
- File system permission errors

## Development

### Running Tests

Run the test suite:
```bash
pytest
```

Run tests with coverage:
```bash
pytest --cov=youtube_transcript_mcp
```

Run a specific test file:
```bash
pytest tests/test_transcript_extractor.py
```

### Code Formatting

Format code with Black:
```bash
black src/ tests/
```

Sort imports with isort:
```bash
isort src/ tests/
```

### Type Checking

```bash
mypy src/
```

## Project Structure

```
youtube-transcript-to-markdown-mcp/
ā”œā”€ā”€ src/
│   └── youtube_transcript_mcp/
│       ā”œā”€ā”€ __init__.py                 # Package initialization
│       ā”œā”€ā”€ server.py                   # MCP server implementation
│       ā”œā”€ā”€ transcript_extractor.py     # YouTube transcript extraction
│       ā”œā”€ā”€ markdown_generator.py       # Markdown formatting
│       └── utils.py                    # Utility functions
ā”œā”€ā”€ tests/                              # Test suite
ā”œā”€ā”€ pyproject.toml                      # Project configuration
ā”œā”€ā”€ requirements.txt                    # Dependencies
└── README.md                          # This file
```

## Dependencies

- `mcp`: Model Context Protocol Python SDK
- `youtube-transcript-api`: YouTube transcript extraction
- `pydantic`: Data validation and settings management
- `typing-extensions`: Type hint extensions

## License

MIT License - see LICENSE file for details.

## Contributing

1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests for new functionality
5. Ensure all tests pass
6. Submit a pull request

## Troubleshooting

### Common Issues

1. **"No transcript available"**: Some videos don't have transcripts, they may be disabled, or only auto-generated captions are available
2. **"Video not found"**: The URL may be invalid, the video may be private/deleted, or region-restricted
3. **Permission errors**: Ensure you have write permissions to the output directory
4. **Import errors**: Make sure all dependencies are installed and you're using Python 3.9+
5. **MCP connection issues**: Verify the server is running and the MCP client configuration is correct

### Debug Mode

Enable debug logging to get more detailed error information:
```bash
youtube-transcript-mcp --debug
```

## Support

For issues and questions, please open an issue on the GitHub repository.