Skip to content

feat: Add analyze_video tool using TwelveLabs Pegasus#35

Open
mohit-twelvelabs wants to merge 1 commit into
kimtaeyoon83:mainfrom
mohit-twelvelabs:feat/twelvelabs-integration
Open

feat: Add analyze_video tool using TwelveLabs Pegasus#35
mohit-twelvelabs wants to merge 1 commit into
kimtaeyoon83:mainfrom
mohit-twelvelabs:feat/twelvelabs-integration

Conversation

@mohit-twelvelabs

@mohit-twelvelabs mohit-twelvelabs commented Jun 25, 2026

Copy link
Copy Markdown

Hi! I'm Mohit, I work at TwelveLabs (@mohit-twelvelabs).

What this adds

A new optional analyze_video MCP tool that runs prompt-based video understanding via TwelveLabs Pegasus. Where get_transcript only captures spoken words, Pegasus reasons over what is actually shown on screen — so it produces useful summaries and answers even for videos with little or no speech (product demos, gameplay, b-roll, music videos).

Inputs: url (a direct video URL), prompt (instruction/question, defaults to a general summary), model (pegasus1.2 / pegasus1.5), and max_tokens. It returns both content text and structuredContent, matching the shape of the existing get_transcript tool.

Why it helps this project

This server is the go-to MCP tool for getting text out of videos. Pegasus extends that from "what was said" to "what happened on screen", which is a natural complement for the summarize/QA workflows people already point at this server — and it covers the large set of videos that have poor or no captions.

Opt-in / non-breaking

  • The tool only activates when explicitly called and only then constructs a TwelveLabs client.
  • It requires a TWELVELABS_API_KEY env var; without it, the existing transcript functionality is completely unchanged and needs zero TwelveLabs configuration.
  • No existing tool, default, or behavior was modified.
  • The official twelvelabs-js SDK is added as the single new dependency.

How it was tested

  • npm run build passes (strict TypeScript).
  • A no-network unit check asserts the input-validation guards throw clearly.
  • A live end-to-end call against Pegasus (pegasus1.2, a public sample .mp4) returns a correct on-screen summary, exercising the full analyze({ video: { type: "url" }, prompt }) -> data path.
  • Added a matching analyze_video entry to the existing mcp-evals suite.

You can grab a free API key at https://twelvelabs.io — there's a generous free tier.

Note: TwelveLabs fetches the video server-side, so url must be a direct media file (.mp4/.mov/.webm or a pre-signed URL). A YouTube watch-page URL serves HTML, not a raw stream, so it isn't a valid input — this is documented in the tool description and README.

Summary by CodeRabbit

  • New Features
    • 영상 URL을 입력해 화면 내용을 분석하고 요약·질문 응답을 받을 수 있는 새 동영상 분석 기능이 추가되었습니다.
    • 분석 모델 선택과 응답 길이 조절을 지원합니다.
  • Documentation
    • 새 기능 사용 방법과 필요한 환경 설정이 문서에 추가되었습니다.
    • 직접 접근 가능한 영상 링크만 사용할 수 있다는 제한 사항이 안내되었습니다.
  • Dependencies
    • 영상 분석 기능에 필요한 추가 라이브러리가 포함되었습니다.

Adds an optional analyze_video tool that runs prompt-based video
understanding (summary / Q&A) via TwelveLabs Pegasus. Unlike
get_transcript, it reasons over on-screen content, so it works for
videos with little or no speech.

The tool is fully opt-in: it only activates when called and requires a
TWELVELABS_API_KEY. The existing transcript functionality is unchanged
and needs no TwelveLabs configuration.
@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

TwelveLabs Pegasus 기반 analyze_video 도구가 추가되었습니다. 서버는 새 분석 어댑터를 호출하고, 도구 스키마와 디스패치가 연결되며, eval 설정과 README에 환경변수와 구성 예시가 반영되었습니다.

Changes

TwelveLabs 비디오 분석

Layer / File(s) Summary
어댑터와 의존성
src/twelvelabs-analyzer.ts, package.json
새 분석 어댑터가 TWELVELABS_API_KEY를 확인하고 client.analyze를 호출하며, twelvelabs-js 의존성이 추가됩니다.
도구 등록과 호출
src/index.ts
analyze_video 도구 스키마가 추가되고, handleToolCall이 인자를 검증한 뒤 analyzeVideo 결과를 반환하며 비-McpError 예외를 InternalError로 래핑합니다.
Eval과 문서
src/evals/evals.ts, README.md
analyze_videoEval가 추가되고, README가 도구 입력값, 직접 비디오 URL 제약, TWELVELABS_API_KEY, 환경변수 예시를 문서화합니다.

Sequence Diagram(s)

sequenceDiagram
  participant "MCP Client" as MCPClient
  participant "src/index.ts handleToolCall" as HandleToolCall
  participant "src/twelvelabs-analyzer.ts analyzeVideo" as AnalyzeVideo
  participant "TwelveLabs SDK" as TwelveLabsSDK
  participant "TwelveLabs API" as TwelveLabsAPI
  MCPClient->>HandleToolCall: analyze_video args
  HandleToolCall->>AnalyzeVideo: url, prompt, model, max_tokens
  AnalyzeVideo->>TwelveLabsSDK: create client and call analyze
  TwelveLabsSDK->>TwelveLabsAPI: submit analysis request
  TwelveLabsAPI-->>TwelveLabsSDK: response.data / finishReason
  TwelveLabsSDK-->>AnalyzeVideo: analyze result
  AnalyzeVideo-->>HandleToolCall: text, model, finishReason
  HandleToolCall-->>MCPClient: content, structuredContent
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

깡총깡총, analyze_video가 반짝 열렸네 🐰
TwelveLabs 바람 따라 장면들이 춤추고
content는 몽글몽글, meta는 살랑살랑
환경변수 한 방울로 힘이 솟아나고
당근보다 달콤한 요약을 냠냠!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 제목이 TwelveLabs Pegasus 기반 analyze_video 도구 추가라는 핵심 변경을 정확하고 간결하게 요약합니다.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/twelvelabs-analyzer.ts (1)

28-29: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low value

maxTokens 범위 검증 부재 (선택).

주석에 2-4096 (pegasus1.2)로 명시되어 있으나 어댑터/호출부 어디에서도 범위를 검증하지 않아 잘못된 값은 API 호출 시점에야 거부됩니다. 사전 검증을 추가하면 더 명확한 오류 메시지를 줄 수 있습니다. pegasus1.5는 토큰 한도가 다르므로(모델별 컨텍스트 윈도) 모델별 검증이 바람직합니다.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/twelvelabs-analyzer.ts` around lines 28 - 29, The maxTokens option is
only documented in the Twelvelabs analyzer but never validated before requests
are sent. Add upfront range checking in the twelvelabs analyzer flow, ideally
where the request is built or initialized in twelvelabs-analyzer, so invalid
values fail early with a clear error. Make the validation model-aware (for
example, pegasus1.2 versus pegasus1.5) and enforce the appropriate token window
before calling the API.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/twelvelabs-analyzer.ts`:
- Around line 28-29: The maxTokens option is only documented in the Twelvelabs
analyzer but never validated before requests are sent. Add upfront range
checking in the twelvelabs analyzer flow, ideally where the request is built or
initialized in twelvelabs-analyzer, so invalid values fail early with a clear
error. Make the validation model-aware (for example, pegasus1.2 versus
pegasus1.5) and enforce the appropriate token window before calling the API.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0f0a4263-73b2-41f9-921e-c3cd7c977d39

📥 Commits

Reviewing files that changed from the base of the PR and between ef4fdaa and 1d9e57a.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (5)
  • README.md
  • package.json
  • src/evals/evals.ts
  • src/index.ts
  • src/twelvelabs-analyzer.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant