MCP-YouTube-Transcribe

MCP-YouTube-Transcribe

Enables fetching transcripts from YouTube videos by searching for videos based on text queries and retrieving either official transcripts or generating them using AI-powered transcription with Whisper when official transcripts are unavailable.

Category
访问服务器

README

MCP-YouTube-Transcribe

License: MIT Python Version Powered by uv

An MCP server that provides a tool to fetch transcripts from YouTube videos. It first attempts to retrieve a pre-existing, official transcript. If one is not available, it downloads the video's audio and uses OpenAI's Whisper model for local AI-powered transcription.

This project is designed to be a simple, self-contained tool that can be easily integrated into any system capable of communicating with an MCP server.

Features

  • YouTube Video Search: Finds the most relevant YouTube video based on a text query.
  • Official Transcript Priority: Intelligently fetches manually created or auto-generated YouTube transcripts first for speed and accuracy.
  • Fast AI-Powered Transcription: Uses whisper.cpp (if available) for blazing fast transcription. Falls back to OpenAI's Python Whisper tiny model if whisper.cpp is not installed.
  • MCP Server Interface: Exposes the transcription functionality as a simple tool (get_youtube_transcript) via the lightweight model context protocol.

Requirements

  • Python 3.12+

  • uv: A fast Python package installer and resolver. You will need to install uv on your system first.

  • FFmpeg: Must be installed and available in your system's PATH. Required for audio processing.

  • whisper.cpp (Highly recommended): MCP-YouTube-Transcribe will first try to use whisper.cpp for lightning-fast local transcription and only fall back to Python Whisper if the executable is not found.

    After installation, make sure the whisper-cli (or whisper-cpp on older versions) command is in your PATH.

    Finally, download a Whisper model. The tiny model offers the best speed-to-quality ratio for most use-cases:

    mkdir -p models
    curl -L -o models/ggml-tiny.bin \
         https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-tiny.bin
    

    Place additional models in the same models/ folder if you wish to experiment.

Installation with uv

Using uv is recommended as it's extremely fast and handles both environment creation and package installation seamlessly.

  1. Clone the repository:

    git clone https://github.com/<your-username>/YouTubeTranscriber.git
    cd YouTubeTranscriber
    
  2. Create and activate a virtual environment: This command creates a .venv folder in your project directory and activates it. uv will automatically use this environment for all subsequent commands.

    uv venv
    
  3. Install the project and its dependencies: This command reads the pyproject.toml file and installs all required libraries into the virtual environment.

    uv sync
    

Usage

Running the MCP Server

Once installed, you can start the server by running the mcp_server.py script. The server will listen for JSON-RPC requests on stdin and send responses to stdout.

python mcp_server.py

The server will log its activity to a file named mcp_server.log in the project's root directory.

Connecting to Gemini CLI on Windows

You can connect this MCP server to the Google Gemini CLI to use the function as a native tool directly from your terminal. These instructions are for a Windows environment.

Step 1: Create a Startup Script run_server.bat

The Gemini CLI needs a single, reliable command to start your server. A batch script is the perfect way to handle this on Windows, as it ensures the correct virtual environment and Python interpreter are used.

  1. Create a new file named in the root of your project directory. run_server.bat
  2. Copy and paste the following content into the file:
    @echo off
    REM This ensures the script's directory is the current directory
    cd /d "%~dp0"
    
    REM --- IMPORTANT ---
    REM Replace the path below with the ABSOLUTE path to your project's venv python.exe
    set PYTHON_EXE="C:\Users\jackp\.pyenv\pyenv-win\versions\3.12.10\python3.12.exe"
    
    echo --- Starting MCP Server using %PYTHON_EXE% ---
    %PYTHON_EXE% mcp_server.py
    
    pause

This script activates the virtual environment in your project and then runs the server, ensuring all the correct dependencies are available..venv

Step 2: Configure the Gemini CLI

Now, you need to tell the Gemini CLI how to find and run your new server.

  1. Locate your Gemini CLI config.json file. On Windows, this is typically found at: C:\Users\<Your-Username>\.gemini\config.json
  2. Open the config.json file in a text editor. Add the following entry to the mcpServers object. If mcpServers doesn't exist, create it as shown below.
    {
      "mcpServers": {
        "MCP-YouTube-Transcribe": {
          "command": "C:\\Windows\\System32\\cmd.exe",
          "args": [
            "/c",
            "<path-to-your-project>\\run_server.bat"
          ],
          "cwd": "<path-to-your-project>"
        }
      }
    }
  1. Crucially, you must replace both instances of <path-to-your-project> with the full, absolute path to where you cloned the YouTubeTranscriber repository.

Example: If your project is located at C:\dev\YouTubeTranscriber, the entry would look like this:

    {
      "mcpServers": {
        "MCP-YouTube-Transcribe": {
          "command": "C:\\Windows\\System32\\cmd.exe",
          "args": [
            "/c",
            "C:\\dev\\YouTubeTranscriber\\run_server.bat"
          ],
          "cwd": "C:\\dev\\YouTubeTranscriber"
        }
      }
    }

Note: JSON requires backslashes to be escaped, so you must use double backslashes (\\) in your paths.

Step 3: Verify the Connection

After saving the config.json file, you can verify that Gemini CLI recognizes and can use your new tool.

Run Gemini CLI and press ctrl+t

You should see MCP-YouTube-Transcribe listed as an available tool.

Connecting to Gemini CLI on Mac/Unix

You can also connect this MCP server to the Google Gemini CLI on Mac or other Unix-like systems. The process is similar to Windows but uses a shell script instead of a batch file.

Step 1: Prepare the Startup Script

The repository already includes a run_server.sh script. Just make it executable:

chmod +x run_server.sh

Step 2: Configure the Gemini CLI

  1. Locate your Gemini CLI config.json file. On Mac/Unix systems, this is typically found at: ~/.gemini/config.json

  2. Open the config.json file in a text editor. Add the following entry to the mcpServers object. If mcpServers doesn't exist, create it as shown below:

{
  "mcpServers": {
    "MCP-YouTube-Transcribe": {
      "command": "/path/to/your/project/run_server.sh",
      "cwd": "/path/to/your/project"
    }
  }
}
  1. Replace both instances of /path/to/your/project with the absolute path to where you cloned the repository.

Example: If your project is located at /Users/username/MCP-YouTube-Transcribe, the entry would look like this:

{
  "mcpServers": {
    "MCP-YouTube-Transcribe": {
      "command": "/Users/username/MCP-YouTube-Transcribe/run_server.sh",
      "cwd": "/Users/username/MCP-YouTube-Transcribe"
    }
  }
}

Step 3: Verify the Connection

After saving the config.json file, you can verify that Gemini CLI recognizes and can use your new tool.

Run Gemini CLI and press ctrl+t

You should see MCP-YouTube-Transcribe listed as an available tool.

MCP Client Example

You can interact with the server using any client that supports the MCP protocol over stdio. The server exposes one primary tool: get_youtube_transcript.

Here is an example of a call_tool request to get a transcript for the query "What is an API? by MuleSoft".

Request:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "call_tool",
  "params": {
    "name": "get_youtube_transcript",
    "arguments": {
      "query": "What is an API? by MuleSoft",
      "force_whisper": false
    }
  }
}
  • query: The search term for the YouTube video.
  • force_whisper: (Optional) A boolean that, if true, skips the check for an official transcript and generates one directly with Whisper. Defaults to false.

Testing

This project includes a test suite to verify its functionality.

  • Core Function Test (simple.py): This script tests the server's handler functions directly without needing to run a separate server process. It's the quickest way to check if the core logic is working.

    python simple.py
    
  • Full Server Test (test_mcp.py): This script starts the MCP server as a subprocess and sends it live JSON-RPC requests, providing an end-to-end test of the server's functionality.

    python test_mcp.py
    

Configuration

  • Logging: Server activity is logged to mcp_server.log.
  • Audio Cache: When Whisper is used, downloaded audio files are temporarily stored in testing/audio_cache/. You may wish to change this path in youtube_tool.py for a production environment.

Contributing

Contributions are welcome! If you'd like to improve the YouTube Transcriber, please feel free to fork the repository and submit a pull request.

Please read our CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests to us.

License

This project is licensed under the MIT License - see the LICENSE file for details.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选