使用说明
YouTube视频搜索MCP服务器
一种模型上下文协议(MCP)服务器,提供YouTube视频搜索功能,与VS Code中的Claude Code一起使用。该项目包括一个用于Claude集成的MCP服务器和一个用于经济高效的批量视频搜索的独立Python脚本。
概述
该项目通过以下方式提供YouTube视频搜索功能:
- MCP服务器 (
mcp_videos.py)-与Claude Code集成,实现交互式搜索和经济高效的文件操作 - 独立脚本 (
save_videos.py)-用于直接命令行使用的替代批处理工具
特性
- 交互式搜索:使用自然语言查询通过Claude Code搜索YouTube视频
- 经济高效的文件操作:使用Claude进行搜索查询,使用Python进行格式化和保存(降低人工智能成本)
- 双工具MCP服务器:
get_videos-在Claude Code界面中显示搜索结果save_videos-搜索格式化结果并将其保存到文件
- 多种输出格式:将结果保存为Markdown、JSON或纯文本文件
- 自然语言接口:让Claude使用对话命令进行搜索和保存
- 灵活的配置:自定义结果限制、文件路径和输出格式
- 丰富的控制台输出:彩色、风格化的终端界面(独立脚本)
- 结构化数据:完整的视频元数据,包括标题、频道、持续时间、观看次数和描述
安装
先决条件
- Python 3.11.11+
uv包管理器(推荐)
设置
# Clone the repository
git clone <repository-url>
cd mcp-server
# Install dependencies
uv sync
用法
方法1:使用克劳德代码的MCP服务器(推荐)
对于通过自然语言进行具有成本效益的文件操作的交互式搜索:
步骤1:配置克劳德代码MCP
创建一个 .clauderc 项目目录中的文件:
touch .clauderc
将此配置添加到 .clauderc:
{
"mcpServers": {
"youtube-search": {
"command": "uv",
"args": ["run", "python", "mcp_videos.py"],
"cwd": "."
}
}
}
步骤2:使用MCP启动Claude代码
# Make sure you're in the mcp-server directory
cd /Users/tod/Desktop/mcp-server
# Start Claude Code with MCP
claude --mcp-config .clauderc
步骤3:使用自然语言命令
一旦Claude Code开始支持MCP,您就可以使用自然语言搜索和保存视频:
命令示例:
You: Find me 5 Python tutorial videos and save them as markdown to python_tutorials.md
You: Search for "Docker containers" and save the top 10 results as JSON to docker_results.json
You: Look for React hooks tutorials, get 8 videos, and save them as plain text to react_hooks.txt
You: Search for "machine learning basics" and save 15 results as markdown to ml_basics.md
可用的MCP工具:
get_videos-在Claude界面中显示搜索结果以供浏览save_videos-搜索格式化结果并将其保存到文件中(经济高效)
优点:
- 自然语言接口 -用简单的英语问克劳德
- 成本效益高 -Claude处理搜索查询,Python处理格式化/保存
- 灵活的 -自定义结果计数、文件路径和输出格式
- 交互式 -先浏览结果
get_videos,然后保存save_videos
故障排除
未找到MCP服务器:
- 确保你在正确的目录中
- 检查一下
uv已安装:uv --version - 验证依赖关系:
uv sync
没有可用的工具:
- 确保你开始使用Claude Code
claude --mcp-config .clauderc - 检查
.clauderc文件在当前目录中 - 重新启动Claude代码
方法2:独立Python脚本(可选)
无需Claude Code即可直接使用命令行:
# Basic usage - saves to search_results.md
uv run python save_videos.py "Docker tutorials"
# Custom options
uv run python save_videos.py "React hooks" -n 15 -o react_videos.txt -f txt
# JSON format for further processing
uv run python save_videos.py "Machine learning" -f json -o ml_videos.json
可用选项:
search(必填):搜索YouTube视频-n, --max-results:最大结果数(默认值:10)-o, --output:输出文件路径(默认值:search_results.md)-f, --format:输出格式-txt、json或md(默认值:md)
更多使用示例:
# Search with custom result count
uv run python save_videos.py "React tutorials" --max-results 15
# Save as plain text
uv run python save_videos.py "DevOps practices" -f txt -o devops.txt
# Combine short flags
uv run python save_videos.py "AI machine learning" -n 20 -o ai_videos.json -f json
注: 这 --help flag在typer 0.16.0中有一个已知的错误,但所有功能都能完美运行。请参阅上面的使用示例。
MCP工具使用
MCP服务器为不同的用例提供了两种工具:
工具1: get_videos -交互式浏览
在Claude Code界面中显示搜索结果以进行交互式浏览。
参数:
search(string):搜索查询max_results(整数):返回的最大结果数
通过克劳德代码使用:
You: Show me 5 Python tutorial videos
You: Find Docker containerization tutorials, limit to 3 results
工具2: save_videos -经济高效的文件操作
使用Python搜索格式化结果并将其直接保存到文件中(降低AI成本)。
参数:
search(string):搜索查询max_results(整数):返回的最大结果数output_file(string):输出文件路径format_type(string):输出格式-“md”、“json”或“txt”
通过克劳德代码使用:
You: Search for "React hooks" and save 10 results as JSON to react_hooks.json
You: Find Python tutorials, get 15 videos, save as markdown to python_tutorials.md
You: Look for Docker videos and save 8 results as plain text to docker_videos.txt
工具响应示例
get_videos 输出(以克劳德显示):
Title: Python Tutorial - Python Full Course for Beginners
Channel: Programming with Mosh
Duration: 6:14:07
Description: Python tutorial for beginners - Learn Python programming...
Views: 2.1M views
URL: https://www.youtube.com/watch?v=_uQrJ0TkZlc
Published: 2 years ago
---
[Additional results...]
save_videos 输出:
Successfully saved 10 videos to python_tutorials.md in md format.
建筑
该项目使用简单的模块化架构:
yt_helper.py-核心YouTube搜索功能使用youtube-search图书馆mcp_videos.py-具有双重工具的增强型MCP服务器:get_videos-交互式搜索和显示save_videos-经济高效的搜索和文件操作
save_videos.py-具有typer和丰富控制台输出的替代独立CLI脚本
发展
测试
测试MCP服务器(推荐):
# Start Claude Code with MCP
claude --mcp-config .clauderc
# Then test both tools:
# 1. Interactive browsing:
# "Show me 5 Python tutorial videos"
# 2. File saving:
# "Search for Docker tutorials and save 10 results as JSON to test_docker.json"
测试独立脚本(备选):
# Test basic search
uv run python save_videos.py "Python tutorials" -n 3
# Test different formats
uv run python save_videos.py "Docker" -f json -o test.json
# Test with all options
uv run python save_videos.py "JavaScript frameworks" --max-results 5 --output js_test.txt --format txt
注: 这 --help flag在typer 0.16.0中有一个已知的错误,但所有功能都能完美运行。请参阅本README中的使用示例。
依赖项
- 主控程序 -模型上下文协议实现
- youtube搜索 -YouTube搜索功能
- 打字机 -功能丰富的现代CLI框架
- 富有的 -丰富的控制台输出,颜色和样式
许可证
此项目是作为MCP服务器功能的示例实现提供的。