-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.ts
More file actions
executable file
·48 lines (39 loc) · 1.3 KB
/
index.ts
File metadata and controls
executable file
·48 lines (39 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env bun
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";
import { YoutubeTranscript } from "./youtube-transcript";
// Create an MCP server
const server = new McpServer({
name: "youtube-transcript-mcp",
version: "0.1.0",
});
// Add an addition tool
server.registerTool(
"get-transcript",
{
title: "Get YouTube Transcript",
description: "Get the transcript of a YouTube video",
inputSchema: { url_or_video_id: z.string() },
},
async ({ url_or_video_id }) => {
const transcript = await YoutubeTranscript.fetchTranscript(url_or_video_id);
// Convert seconds to [XmYs] format
const formatTime = (seconds: number) => {
const minutes = Math.floor(seconds / 60);
const secs = Math.floor(seconds % 60);
return `[${minutes}m${secs}s]`;
};
// Format each segment with timestamp
const formattedSegments = transcript.map(
(item) => `${formatTime(item.offset)} ${item.text}`,
);
const transcriptText = formattedSegments.join(" ");
return {
content: [{ type: "text", text: transcriptText }],
};
},
);
// Start receiving messages on stdin and sending messages on stdout
const transport = new StdioServerTransport();
await server.connect(transport);