mcp-headless-youtube-transcript 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/build/index.js +33 -4
  2. package/package.json +1 -1
package/build/index.js CHANGED
@@ -31,6 +31,11 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
31
31
  description: 'Language code for captions (e.g., "en", "es", "ko"). Defaults to "en"',
32
32
  default: 'en',
33
33
  },
34
+ segment: {
35
+ type: 'number',
36
+ description: 'Segment number to retrieve (1-based). Each segment is ~98k characters. Defaults to 1',
37
+ default: 1,
38
+ },
34
39
  },
35
40
  required: ['videoId'],
36
41
  },
@@ -43,7 +48,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
43
48
  const { name, arguments: args } = request.params;
44
49
  if (name === 'get_youtube_transcript') {
45
50
  try {
46
- const { videoId, lang = 'en' } = args;
51
+ const { videoId, lang = 'en', segment = 1 } = args;
47
52
  // Extract video ID from URL if a full URL is provided
48
53
  const extractedVideoId = extractVideoId(videoId);
49
54
  if (!extractedVideoId) {
@@ -54,13 +59,37 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
54
59
  videoID: extractedVideoId,
55
60
  lang: lang,
56
61
  });
57
- // Just get the raw text content, no timestamps
58
- const transcript = subtitles.map(s => s.text).join(' ');
62
+ // Get the full raw text content
63
+ const fullTranscript = subtitles.map(s => s.text).join(' ');
64
+ // Split into 98k character chunks
65
+ const chunkSize = 98000;
66
+ const chunks = [];
67
+ for (let i = 0; i < fullTranscript.length; i += chunkSize) {
68
+ chunks.push(fullTranscript.substring(i, i + chunkSize));
69
+ }
70
+ // Validate segment number
71
+ if (segment < 1 || segment > chunks.length) {
72
+ return {
73
+ content: [
74
+ {
75
+ type: 'text',
76
+ text: `Error: Invalid segment ${segment}. Available segments: 1-${chunks.length}`,
77
+ },
78
+ ],
79
+ isError: true,
80
+ };
81
+ }
82
+ // Get the requested segment (convert to 0-based index)
83
+ const requestedChunk = chunks[segment - 1];
84
+ // Add metadata about segmentation
85
+ const segmentInfo = chunks.length > 1
86
+ ? `[Segment ${segment} of ${chunks.length}]\n\n`
87
+ : '';
59
88
  return {
60
89
  content: [
61
90
  {
62
91
  type: 'text',
63
- text: transcript,
92
+ text: segmentInfo + requestedChunk,
64
93
  },
65
94
  ],
66
95
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-headless-youtube-transcript",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "MCP server for extracting YouTube video transcripts using headless-youtube-captions",
5
5
  "main": "build/index.js",
6
6
  "bin": {