Skip to main content
Glama
Talhaz

yt-intel MCP Server

by Talhaz

yt-intel MCP Server — The Markup (Automation 04)

一个MCP服务器,将../yt(yt-intel)的频道数据暴露为诊断工具——适用于任何MCP客户端(Claude Desktop、Claude Code、Cursor、Codex,或任何其他支持MCP的工具),不绑定于某个特定产品。与../yt、../storyboard和../scriptwriter为同级项目。

用途

直接从编辑器或聊天客户端回答“这个频道实际表现如何,以及下一步该做什么”,无需打开yt-intel网页界面。九个工具,围绕制作人实际按顺序提出的诊断问题组织,而不是每个数据库表一个工具:

频道健康

  • channel_overview — 订阅者/观看增长趋势、短视频与长视频比例、上传节奏

  • list_videos — 可筛选/可排序的基础列表

性能诊断

  • diagnose_video — “为什么这个视频会有这样的表现”工具:统计、分析、地理、流量来源、算法对齐、势头和钩子

  • find_underperformers / find_winners — 排名列表,根据内部主题选择清单第8节的逻辑,标注了类型1(执行/钩子不佳)与类型2(主题天花板)的诊断

  • search_tag_gaps — 驱动观看但无匹配标签的搜索词

内容搜索 — Postgres全文搜索(yt-intel模式中已有的GIN索引——ix_transcripts_fts、ix_videos_title_fts——已构建但未使用;这正是最终使用它们的地方),而非简单的LIKE扫描:

  • search_transcripts — 排序,返回高亮片段,而不仅仅是ID

  • search_videos — 相同,但针对标题+描述

主题/脚本审查 — 直接复用scriptwriter已构建、已测试的逻辑(本地路径依赖,而非复制):

  • check_topic — 在确定主题之前进行的最佳国家/最佳来源数据检查

  • qa_script — 完整的机械QA检查清单(字数/节奏、括号验证、重复事实检测、时间戳计算)

Related MCP server: YouTube MCP Server

为什么用Postgres全文搜索,而不是Elasticsearch

在约67个视频和几百KB的转录文本规模下,这远低于Elasticsearch分布式架构值得其运维成本(在与其他三个应用共享的2-4GB VPS上部署并保持同步的第二个服务)的规模。所有比较过的来源都认为Postgres全文搜索无需额外基础设施即可处理绝大多数用例,而且所需的GIN索引已存在于yt-intel的模式中,未被使用。如果关键词搜索在实践中证明不足,pgvector(基于语义/含义的搜索)是自然的v2方案——而不是Elasticsearch,在这个规模下。

快速开始

check_topic/qa_script需要../scriptwriter作为同级目录存在并首先安装——它不在本项目自身的依赖列表中(file://路径依赖被证明是脆弱的:绝对路径只能在一台机器上解析,而pip对相对路径的处理不够一致,足以破坏真实的Docker构建——参见pyproject.toml自身的注释和Dockerfile的注释)。

python -m venv .venv
./.venv/Scripts/python.exe -m pip install -e ../scriptwriter   # first
./.venv/Scripts/python.exe -m pip install -e ".[dev]"          # Windows

cp .env.example .env      # YTINTEL_DATABASE_URL, OWN_CHANNEL_ID

通过stdio本地运行(用于Claude Desktop / Cursor / Codex配置):

python -m ytintel_mcp.server

通过HTTP运行(用于远程/VPS部署):

YTINTEL_MCP_TRANSPORT=http python -m ytintel_mcp.server

连接本地MCP客户端(Claude Desktop / Cursor / Codex)

每个客户端通过stdio将此服务器作为子进程启动——将其指向本项目的venv Python和模块:

{
  "mcpServers": {
    "ytintel": {
      "command": "D:/Axion/ytintel-mcp/.venv/Scripts/python.exe",
      "args": ["-m", "ytintel_mcp.server"],
      "env": {
        "YTINTEL_DATABASE_URL": "postgresql+psycopg://yt:yt@localhost:5432/yt_intel",
        "OWN_CHANNEL_ID": "UCODE52XZvkuimEZfGD10Bcw"
      }
    }
  }
}

Claude Desktop:claude_desktop_config.json(设置 → 开发者 → 编辑配置)。Cursor:设置 → MCP → 添加新的MCP服务器(相同的JSON结构)。Codex:其自己的MCP服务器配置,相同的command/args/env字段。

部署到VPS——与scriptwriter一起

本项目对../scriptwriter有本地路径依赖(用于check_topic/qa_script,它们直接导入scriptwriter的domain/模块,而不是复制副本——参见pyproject.toml)。这意味着Docker镜像只能在两个项目并排存在的地方构建,并且两者必须一起部署,不能独立部署。具体来说,在VPS上:

# 1. Clone (or already have) BOTH projects as siblings under the same parent,
#    e.g. ~/Axion/scriptwriter and ~/Axion/ytintel-mcp — mirroring this dev
#    machine's D:\Axion layout. The path dependency in ytintel-mcp's
#    pyproject.toml is an ABSOLUTE dev-machine path
#    (file:///D:/Axion/scriptwriter) that only matters locally — the
#    Dockerfile does NOT use it; it installs scriptwriter from the shared
#    build context instead (see Dockerfile's own header comment), so the
#    exact clone path on the VPS doesn't need to match this dev machine's.
cd ~/Axion
git clone <scriptwriter repo> scriptwriter
git clone <ytintel-mcp repo> ytintel-mcp

# 2. scriptwriter's own .env (needed for its own deploy — OPENAI_API_KEY /
#    MISTRAL_API_KEY, YTINTEL_DB_PASSWORD, YTINTEL_NETWORK_NAME — see
#    ../scriptwriter/README.md's own Deployment section) and ytintel-mcp's
#    .env (same YTINTEL_DB_*/YTINTEL_NETWORK_NAME vars, plus OWN_CHANNEL_ID)
cp scriptwriter/.env.example scriptwriter/.env && nano scriptwriter/.env
cp ytintel-mcp/.env.example ytintel-mcp/.env && nano ytintel-mcp/.env
chmod 600 scriptwriter/.env ytintel-mcp/.env

# 3. Confirm yt-intel's actual Docker network name BEFORE either deploy —
#    both .env files' YTINTEL_NETWORK_NAME must match this exactly:
docker network ls | grep default

# 4. Deploy scriptwriter first (no cross-project build dependency, so order
#    doesn't strictly matter, but this mirrors provisioning it before the
#    tool that references its code)
cd ~/Axion/scriptwriter
docker compose -f docker-compose.prod.yml up -d --build

# 5. Deploy ytintel-mcp — note the build context is the AXION ROOT, not this
#    directory (the Dockerfile COPYs ../scriptwriter into the image):
cd ~/Axion
docker compose -f ytintel-mcp/docker-compose.prod.yml up -d --build

端口8003(yt-intel=8000,storyboard=8001,scriptwriter=8002,本服务=8003),与其他服务一样绑定到127.0.0.1——如果远程MCP客户端需要通过网络访问它,则将其添加到同一个Caddy反向代理中(远程部署提供的是streamable-http,而不是stdio——参见config.py中的YTINTEL_MCP_TRANSPORT)。

scriptwriter代码更改后重新部署:由于镜像在构建时嵌入了scriptwriter代码的副本(而非实时挂载),每当scriptwriter端的domain/topic_scoring.py或domain/script_qa.py发生变化时,必须重建ytintel-mcp镜像(docker compose -f ytintel-mcp/docker-compose.prod.yml up -d --build)——仅对scriptwriter执行git pull不会更新已构建的ytintel-mcp容器。

测试

./.venv/Scripts/python.exe -m pytest -q
./.venv/Scripts/python.exe -m ruff check .
./.venv/Scripts/python.exe -m mypy src

Related MCP Connectors

Related MCP Servers