一个全面的模型上下文协议(MCP)服务器,提供基于AI的转录工具,用于YouTube视频和播客,使用YouTube Transcript API和Google Gemini Flash 2.5。
按照以下步骤设置MCP服务器以供Claude桌面使用:
cd transcribe_mcp_server
python3 -m venv mcp_env
macOS/Linux:
source mcp_env/bin/activate
Windows:
mcp_env\Scripts\activate
pip install -r requirements.txt
获取Google Gemini API密钥:
创建 .env 文件:
echo "GOOGLE_API_KEY=your-api-key-here" > .env
替换 your-api-key-here 为第5步中的实际API密钥。
python -m py_compile transcribe_mcp.py
如果没有任何错误出现,则设置完成!
MCP服务器作为基于stdio的服务运行:
python transcribe_mcp.py
注意:MCP服务器设计为与MCP客户端(如Claude桌面)一起使用。直接运行服务器会导致它等待stdio输入。
这是最重要的一步。仔细遵循这些指令以避免常见错误。
打开Claude桌面配置文件:
~/Library/Application\ Support/Claude/claude_desktop_config.json~/.config/Claude/claude_desktop_config.json重要:使用虚拟环境Python的绝对路径,而不是系统Python。
替换 /Users/YOUR-USERNAME/path/to/transcribe_mcp 为你的实际项目路径,然后添加:
{
"mcpServers": {
"transcribe": {
"command": "/Users/YOUR-USERNAME/path/to/transcribe_mcp/transcribe_mcp_server/mcp_env/bin/python3",
"args": ["/Users/YOUR-USERNAME/path/to/transcribe_mcp/transcribe_mcp_server/transcribe_mcp.py"],
"env": {
"GOOGLE_API_KEY": "your-api-key-here"
}
}
}
}
示例(macOS):
{
"mcpServers": {
"transcribe": {
"command": "/Users/omar/Desktop/transcribe_mcp/transcribe_mcp_server/mcp_env/bin/python3",
"args": ["/Users/omar/Desktop/transcribe_mcp/transcribe_mcp_server/transcribe_mcp.py"],
"env": {
"GOOGLE_API_KEY": "your-actual-api-key-here"
}
}
}
}
MCP服务器也可以部署到Google Cloud Run以进行远程访问。
https://transcribe-mcp-515118417864.us-central1.run.app
使服务公开可访问:
gcloud run services update transcribe-mcp \
--region us-central1 \
--allow-unauthenticated
然后配置Claude桌面:
{
"mcpServers": {
"transcribe-remote": {
"url": "https://transcribe-mcp-515118417864.us-central1.run.app/sse"
}
}
}
安装mcp-remote代理:
npm install -g @anthropic/mcp-remote
使用认证配置Claude桌面:
{
"mcpServers": {
"transcribe-remote": {
"command": "mcp-remote",
"args": [
"https://transcribe-mcp-515118417864.us-central1.run.app/sse",
"--header", "Authorization: Bearer $(gcloud auth print-identity-token)"
]
}
}
}
# 健康检查(带认证)
curl -H "Authorization: Bearer $(gcloud auth print-identity-token)" \
https://transcribe-mcp-515118417864.us-central1.run.app/health
# YouTube文字
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-identity-token)" \
-H "Content-Type: application/json" \
https://transcribe-mcp-515118417864.us-central1.run.app/api/youtube/transcript \
-d '{"video_url_or_id": "dQw4w9WgXcQ"}'
参见docs/setup/cloud-run-deploy.md以获取完整的部署说明。
参见docs/setup/webapp-integration.md以了解如何使用Supabase认证将MCP集成到您的Web应用中。
如果您不知道您的绝对路径,请在终端中运行:
cd /Users/YOUR-USERNAME/Desktop/transcribe_mcp/transcribe_mcp_server
pwd
这将打印您的绝对路径。在上面的配置中使用它。
重要:完全关闭Claude桌面并重新打开。
Claude桌面需要重启以加载MCP服务器配置。
在Claude桌面中,您应该看到一个🔌图标,表示MCP工具已加载。尝试询问:
“获取此YouTube视频的文字:https://youtube.com/watch?v=i43kYARbSGM”
如果成功,您就完成了!🎉
错误:“spawn python ENOENT”
python或python3而不是完整的虚拟环境路径/Users/YOUR-USERNAME/.../mcp_env/bin/python3错误:“youtube-transcript-api未安装”
cd transcribe_mcp_server
source mcp_env/bin/activate
pip install -r requirements.txt
错误:“无效的API密钥”
claude_desktop_config.json 中的 GOOGLE_API_KEY工具未显示在Claude桌面中
~/Library/Application\ Support/Claude/claude_desktop_config.json仍然无法工作?
检查虚拟环境是否成功创建:
ls -la /Users/YOUR-USERNAME/path/to/transcribe_mcp/transcribe_mcp_server/mcp_env/bin/python3
如果该文件不存在,则虚拟环境未创建。返回设置步骤2并创建它:
cd transcribe_mcp_server
python3 -m venv mcp_env
source mcp_env/bin/activate
pip install -r requirements.txt
MCP服务器提供了12个强大的转录工具,组织成标准转录和批处理类别。
transcribe_get_youtube_transcript从YouTube视频中提取文字,可通过URL或视频ID,可选自动格式化。
参数:
video_url_or_id(必需) - YouTube URL或11位视频IDinclude_timestamps(默认:true) - 包含时间信息auto_format(默认:false) - 自动格式化为专业文档clean_filler_words(默认:true) - 当auto_format=true时移除填充词response_format(默认:"markdown") - 输出格式:"markdown"或"json"use_cache(默认:true) - 在获取之前检查缓存示例:
原始文字:
video_url_or_id: "dQw4w9WgXcQ"
include_timestamps: true
response_format: "markdown"
专业格式化的文字:
video_url_or_id: "dQw4w9WgXcQ"
auto_format: true
clean_filler_words: true
response_format: "markdown"
输出:原始文字或带有说话者、章节和时间戳的专业文档
transcribe_find_podcast_rss通过名称查找播客的RSS源URL。
搜索策略:
参数:
podcast_name(必需) - 要搜索的播客名称response_format(默认:"markdown") - 输出格式示例:
podcast_name: "Lex Fridman Podcast"
输出:RSS源URL和播客元数据
transcribe_parse_rss_feed解析播客RSS源并列出可用的集数。
参数:
rss_url(必需) - RSS源URLmax_episodes(默认:10,最大:50) - 返回的最大集数response_format(默认:"markdown") - 输出格式示例:
rss_url: "https://feeds.megaphone.fm/lexfridmanpodcast"
max_episodes: 5
输出:带有标题、音频URL、日期和持续时间的集数列表
transcribe_podcast_episode使用Google Gemini下载并转录音频,可选自动格式化。
参数:
audio_url(必需) - 直接音频文件URL(.mp3、.m4a、.wav)episode_title(可选) - 元数据中的集数标题include_timestamps(默认:true) - 包含时间戳speaker_diarization(默认:true) - 识别不同的说话者auto_format(默认:false) - 自动格式化为专业文档clean_filler_words(默认:true) - 当auto_format=true时移除填充词save_to_disk(默认:true) - 将文字保存到./transcripts/use_cache(默认:true) - 在处理之前检查缓存response_format(默认:"markdown") - 输出格式示例:
原始文字:
audio_url: "https://example.com/podcast/episode.mp3"
episode_title: "Episode 1: Introduction"
speaker_diarization: true
专业格式化的文字:
audio_url: "https://example.com/podcast/episode.mp3"
episode_title: "Episode 1: Introduction"
speaker_diarization: true
auto_format: true
clean_filler_words: true
输出:原始文字或带有说话者标签、章节和时间戳的专业文档
注意事项:
transcribe_get_cached_transcript通过缓存键检索先前缓存的文字。
参数:
cache_key(必需) - 来自先前转录的32位MD5哈希response_format(默认:"markdown") - 输出格式示例:
cache_key: "abc123def456..."
输出:带有元数据的缓存文字
transcribe_list_cache列出所有缓存的文字。
参数:
limit(默认:20,最大:100) - 返回的最大结果数response_format(默认:"markdown") - 输出格式输出:带有缓存键、日期和来源的缓存文字列表
transcribe_format_transcript格式化并增强任何原始文字,使其成为专业、可发布的文档。
参数:
raw_transcript(必需) - 要格式化的原始文字(至少10个字符)title(默认:"访谈文字") - 格式化文字的标题include_timestamps(默认:true) - 在输出中包含时间戳clean_filler_words(默认:true) - 移除填充词("um"、"uh"、"like"等)auto_detect_speakers(默认:true) - 自动检测说话者姓名detect_sections(默认:true) - 自动创建章节标题response_format(默认:"markdown") - 输出格式:"markdown"或"json"示例:
raw_transcript: "[全文在这里...]"
title: "专家访谈"
include_timestamps: true
clean_filler_words: true
auto_detect_speakers: true
detect_sections: true
response_format: "markdown"
输出:带有说话者、章节、对话要点和时间戳的专业文档
特性:
处理时间:2-5秒(无API调用,仅本地处理)
示例输出(Markdown):
# 专家访谈
**说话者**:Alice, Bob
**格式**:访谈文字
---
## **引言**
* [00:00] **Alice**:欢迎来到节目...
* **Bob**:感谢邀请...
## **主要讨论**
* [05:30] **Alice**:让我们谈谈这个话题...
* **Bob**:当然,这是我的观点...
## **结论**
* [38:45] **Alice**:感谢这次对话...
批处理工具提供了批量作业的成本效益转录。当转录5个以上集数或整个播客系列时使用这些工具。批处理比标准API调用节省50%成本。
transcribe_submit_batch提交多个播客集数的批处理转录任务。
参数:
episodes(可选) - 包含title和audio_url键的集数数组rss_url(可选) - 或提供RSS源URL以自动解析max_episodes(默认:50,最大:1000) - 处理的最大集数filter_cached(默认:true) - 跳过已缓存的集数job_name(可选) - 用于跟踪批处理任务的自定义名称speaker_diarization(默认:true) - 启用说话者识别include_timestamps(默认:true) - 在文字中包含时间戳auto_format(默认:true) - 自动格式化为专业文档clean_filler_words(默认:true) - 当auto_format=true时移除填充词response_format(默认:"markdown") - 输出格式示例1:通过RSS源提交:
rss_url: "https://feeds.megaphone.fm/lexfridmanpodcast"
max_episodes: 10
auto_format: true
job_name: "lex-batch-001"
示例2:通过集数列表提交:
episodes: [
{"