@pipeworx/mcp-youtube 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Pipeworx
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # mcp-youtube
2
+
3
+ YouTube MCP — wraps the YouTube Data API v3 (BYO API key)
4
+
5
+ Part of the [Pipeworx](https://pipeworx.io) open MCP gateway.
6
+
7
+ ## Tools
8
+
9
+ | Tool | Description |
10
+ |------|-------------|
11
+
12
+ ## Quick Start
13
+
14
+ Add to your MCP client config:
15
+
16
+ ```json
17
+ {
18
+ "mcpServers": {
19
+ "youtube": {
20
+ "url": "https://gateway.pipeworx.io/youtube/mcp"
21
+ }
22
+ }
23
+ }
24
+ ```
25
+
26
+ Or use the CLI:
27
+
28
+ ```bash
29
+ npx pipeworx use youtube
30
+ ```
31
+
32
+ ## License
33
+
34
+ MIT
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@pipeworx/mcp-youtube",
3
+ "version": "0.1.0",
4
+ "description": "YouTube MCP — wraps the YouTube Data API v3 (BYO API key)",
5
+ "type": "module",
6
+ "main": "src/index.ts",
7
+ "types": "src/index.ts",
8
+ "keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "youtube"],
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/pipeworx-io/mcp-youtube"
13
+ },
14
+ "scripts": {
15
+ "typecheck": "tsc --noEmit"
16
+ },
17
+ "devDependencies": {
18
+ "typescript": "^5.7.0"
19
+ }
20
+ }
package/server.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
3
+ "name": "io.github.pipeworx-io/youtube",
4
+ "title": "youtuue",
5
+ "description": "YouTube MCP — wraps the YouTube Data API v3 (BYO API key)",
6
+ "version": "0.1.0",
7
+ "websiteUrl": "https://pipeworx.io/packs/youtube",
8
+ "repository": {
9
+ "url": "https://github.com/pipeworx-io/mcp-youtube",
10
+ "source": "github"
11
+ },
12
+ "remotes": [
13
+ {
14
+ "type": "streamable-http",
15
+ "url": "https://gateway.pipeworx.io/youtube/mcp"
16
+ }
17
+ ]
18
+ }
package/src/index.ts ADDED
@@ -0,0 +1,466 @@
1
+ interface McpToolDefinition {
2
+ name: string;
3
+ description: string;
4
+ inputSchema: {
5
+ type: 'object';
6
+ properties: Record<string, unknown>;
7
+ required?: string[];
8
+ };
9
+ }
10
+
11
+ interface McpToolExport {
12
+ tools: McpToolDefinition[];
13
+ callTool: (name: string, args: Record<string, unknown>) => Promise<unknown>;
14
+ }
15
+
16
+ /**
17
+ * YouTube MCP — wraps the YouTube Data API v3 (BYO API key)
18
+ *
19
+ * Tools:
20
+ * - yt_search: search videos, channels, or playlists
21
+ * - yt_video_details: get video details including stats
22
+ * - yt_channel_details: get channel info and stats
23
+ * - yt_channel_videos: list videos from a channel
24
+ * - yt_video_comments: get comments on a video
25
+ */
26
+
27
+
28
+ const BASE = 'https://www.googleapis.com/youtube/v3';
29
+
30
+ // ── Tool definitions ──────────────────────────────────────────────────
31
+
32
+ const tools: McpToolExport['tools'] = [
33
+ {
34
+ name: 'yt_search',
35
+ description:
36
+ 'Search YouTube for videos, channels, or playlists. Returns snippet info including title, description, channel, thumbnails, and publish date.',
37
+ inputSchema: {
38
+ type: 'object' as const,
39
+ properties: {
40
+ _apiKey: { type: 'string', description: 'YouTube Data API v3 key from Google Cloud Console' },
41
+ query: { type: 'string', description: 'Search term' },
42
+ type: {
43
+ type: 'string',
44
+ description: 'Resource type to search: "video", "channel", or "playlist" (default: "video")',
45
+ },
46
+ max_results: {
47
+ type: 'number',
48
+ description: 'Number of results to return (default 10, max 50)',
49
+ },
50
+ channel_id: {
51
+ type: 'string',
52
+ description: 'Filter results to a specific channel ID',
53
+ },
54
+ order: {
55
+ type: 'string',
56
+ description: 'Sort order: "date", "rating", "relevance", or "viewCount" (default: "relevance")',
57
+ },
58
+ published_after: {
59
+ type: 'string',
60
+ description: 'Filter results published after this ISO 8601 date (e.g. "2024-01-01T00:00:00Z")',
61
+ },
62
+ },
63
+ required: ['_apiKey', 'query'],
64
+ },
65
+ },
66
+ {
67
+ name: 'yt_video_details',
68
+ description:
69
+ 'Get detailed information about one or more YouTube videos including title, description, channel, duration, view/like/comment counts, and tags.',
70
+ inputSchema: {
71
+ type: 'object' as const,
72
+ properties: {
73
+ _apiKey: { type: 'string', description: 'YouTube Data API v3 key from Google Cloud Console' },
74
+ video_id: {
75
+ type: 'string',
76
+ description: 'Video ID or comma-separated list of video IDs (max 50)',
77
+ },
78
+ },
79
+ required: ['_apiKey', 'video_id'],
80
+ },
81
+ },
82
+ {
83
+ name: 'yt_channel_details',
84
+ description:
85
+ 'Get YouTube channel information and statistics including subscriber count, video count, view count, description, and custom URL.',
86
+ inputSchema: {
87
+ type: 'object' as const,
88
+ properties: {
89
+ _apiKey: { type: 'string', description: 'YouTube Data API v3 key from Google Cloud Console' },
90
+ channel_id: { type: 'string', description: 'Channel ID (starts with UC...)' },
91
+ username: {
92
+ type: 'string',
93
+ description: 'Channel username (alternative to channel_id)',
94
+ },
95
+ },
96
+ required: ['_apiKey'],
97
+ },
98
+ },
99
+ {
100
+ name: 'yt_channel_videos',
101
+ description:
102
+ 'List recent videos from a YouTube channel, ordered by date. Returns video ID, title, description, and publish date.',
103
+ inputSchema: {
104
+ type: 'object' as const,
105
+ properties: {
106
+ _apiKey: { type: 'string', description: 'YouTube Data API v3 key from Google Cloud Console' },
107
+ channel_id: { type: 'string', description: 'Channel ID to list videos from' },
108
+ max_results: {
109
+ type: 'number',
110
+ description: 'Number of videos to return (default 10, max 50)',
111
+ },
112
+ published_after: {
113
+ type: 'string',
114
+ description: 'Filter videos published after this ISO 8601 date',
115
+ },
116
+ published_before: {
117
+ type: 'string',
118
+ description: 'Filter videos published before this ISO 8601 date',
119
+ },
120
+ },
121
+ required: ['_apiKey', 'channel_id'],
122
+ },
123
+ },
124
+ {
125
+ name: 'yt_video_comments',
126
+ description:
127
+ 'Get top-level comment threads on a YouTube video. Returns author, text, like count, and publish date.',
128
+ inputSchema: {
129
+ type: 'object' as const,
130
+ properties: {
131
+ _apiKey: { type: 'string', description: 'YouTube Data API v3 key from Google Cloud Console' },
132
+ video_id: { type: 'string', description: 'Video ID to fetch comments for' },
133
+ max_results: {
134
+ type: 'number',
135
+ description: 'Number of comment threads to return (default 20, max 100)',
136
+ },
137
+ order: {
138
+ type: 'string',
139
+ description: 'Sort order: "time" or "relevance" (default: "relevance")',
140
+ },
141
+ },
142
+ required: ['_apiKey', 'video_id'],
143
+ },
144
+ },
145
+ ];
146
+
147
+ // ── Helpers ───────────────────────────────────────────────────────────
148
+
149
+ function extractKey(args: Record<string, unknown>): string {
150
+ const key = args._apiKey as string;
151
+ if (!key) throw new Error('YouTube Data API key required. Pass _apiKey parameter.');
152
+ return key;
153
+ }
154
+
155
+ async function ytGet(key: string, path: string, params: Record<string, string>): Promise<unknown> {
156
+ params.key = key;
157
+ const qs = new URLSearchParams(params).toString();
158
+ const res = await fetch(`${BASE}${path}?${qs}`);
159
+ if (!res.ok) {
160
+ const text = await res.text();
161
+ throw new Error(`YouTube API error ${res.status}: ${text}`);
162
+ }
163
+ return res.json();
164
+ }
165
+
166
+ // ── Tool implementations ─────────────────────────────────────────────
167
+
168
+ async function search(
169
+ key: string,
170
+ query: string,
171
+ type?: string,
172
+ maxResults?: number,
173
+ channelId?: string,
174
+ order?: string,
175
+ publishedAfter?: string,
176
+ ) {
177
+ const count = Math.min(50, Math.max(1, maxResults ?? 10));
178
+ const params: Record<string, string> = {
179
+ part: 'snippet',
180
+ q: query,
181
+ type: type ?? 'video',
182
+ maxResults: String(count),
183
+ order: order ?? 'relevance',
184
+ };
185
+ if (channelId) params.channelId = channelId;
186
+ if (publishedAfter) params.publishedAfter = publishedAfter;
187
+
188
+ const data = (await ytGet(key, '/search', params)) as {
189
+ items: {
190
+ id: { kind: string; videoId?: string; channelId?: string; playlistId?: string };
191
+ snippet: {
192
+ title: string;
193
+ description: string;
194
+ channelTitle: string;
195
+ channelId: string;
196
+ publishedAt: string;
197
+ thumbnails: { default?: { url: string } };
198
+ };
199
+ }[];
200
+ pageInfo: { totalResults: number; resultsPerPage: number };
201
+ };
202
+
203
+ return {
204
+ total_results: data.pageInfo.totalResults,
205
+ results: data.items.map((item) => ({
206
+ id: item.id.videoId ?? item.id.channelId ?? item.id.playlistId ?? null,
207
+ kind: item.id.kind,
208
+ title: item.snippet.title,
209
+ description: item.snippet.description,
210
+ channel_title: item.snippet.channelTitle,
211
+ channel_id: item.snippet.channelId,
212
+ published_at: item.snippet.publishedAt,
213
+ thumbnail: item.snippet.thumbnails?.default?.url ?? null,
214
+ })),
215
+ };
216
+ }
217
+
218
+ async function videoDetails(key: string, videoId: string) {
219
+ const params: Record<string, string> = {
220
+ part: 'snippet,statistics,contentDetails',
221
+ id: videoId,
222
+ };
223
+
224
+ const data = (await ytGet(key, '/videos', params)) as {
225
+ items: {
226
+ id: string;
227
+ snippet: {
228
+ title: string;
229
+ description: string;
230
+ channelTitle: string;
231
+ channelId: string;
232
+ publishedAt: string;
233
+ tags?: string[];
234
+ categoryId: string;
235
+ thumbnails: { default?: { url: string } };
236
+ };
237
+ statistics: {
238
+ viewCount?: string;
239
+ likeCount?: string;
240
+ commentCount?: string;
241
+ };
242
+ contentDetails: {
243
+ duration: string;
244
+ definition: string;
245
+ };
246
+ }[];
247
+ };
248
+
249
+ return {
250
+ videos: data.items.map((v) => ({
251
+ id: v.id,
252
+ title: v.snippet.title,
253
+ description: v.snippet.description,
254
+ channel_title: v.snippet.channelTitle,
255
+ channel_id: v.snippet.channelId,
256
+ published_at: v.snippet.publishedAt,
257
+ tags: v.snippet.tags ?? [],
258
+ category_id: v.snippet.categoryId,
259
+ thumbnail: v.snippet.thumbnails?.default?.url ?? null,
260
+ duration: v.contentDetails.duration,
261
+ definition: v.contentDetails.definition,
262
+ view_count: v.statistics.viewCount ? Number(v.statistics.viewCount) : null,
263
+ like_count: v.statistics.likeCount ? Number(v.statistics.likeCount) : null,
264
+ comment_count: v.statistics.commentCount ? Number(v.statistics.commentCount) : null,
265
+ })),
266
+ };
267
+ }
268
+
269
+ async function channelDetails(key: string, channelId?: string, username?: string) {
270
+ if (!channelId && !username) {
271
+ throw new Error('Either channel_id or username is required.');
272
+ }
273
+
274
+ const params: Record<string, string> = {
275
+ part: 'snippet,statistics,contentDetails',
276
+ };
277
+ if (channelId) {
278
+ params.id = channelId;
279
+ } else if (username) {
280
+ params.forUsername = username;
281
+ }
282
+
283
+ const data = (await ytGet(key, '/channels', params)) as {
284
+ items: {
285
+ id: string;
286
+ snippet: {
287
+ title: string;
288
+ description: string;
289
+ customUrl?: string;
290
+ publishedAt: string;
291
+ country?: string;
292
+ thumbnails: { default?: { url: string } };
293
+ };
294
+ statistics: {
295
+ viewCount?: string;
296
+ subscriberCount?: string;
297
+ videoCount?: string;
298
+ hiddenSubscriberCount: boolean;
299
+ };
300
+ contentDetails: {
301
+ relatedPlaylists: { uploads: string };
302
+ };
303
+ }[];
304
+ };
305
+
306
+ if (!data.items || data.items.length === 0) {
307
+ throw new Error('Channel not found.');
308
+ }
309
+
310
+ return {
311
+ channels: data.items.map((ch) => ({
312
+ id: ch.id,
313
+ title: ch.snippet.title,
314
+ description: ch.snippet.description,
315
+ custom_url: ch.snippet.customUrl ?? null,
316
+ published_at: ch.snippet.publishedAt,
317
+ country: ch.snippet.country ?? null,
318
+ thumbnail: ch.snippet.thumbnails?.default?.url ?? null,
319
+ view_count: ch.statistics.viewCount ? Number(ch.statistics.viewCount) : null,
320
+ subscriber_count: ch.statistics.hiddenSubscriberCount
321
+ ? null
322
+ : ch.statistics.subscriberCount
323
+ ? Number(ch.statistics.subscriberCount)
324
+ : null,
325
+ video_count: ch.statistics.videoCount ? Number(ch.statistics.videoCount) : null,
326
+ uploads_playlist: ch.contentDetails.relatedPlaylists.uploads,
327
+ })),
328
+ };
329
+ }
330
+
331
+ async function channelVideos(
332
+ key: string,
333
+ channelId: string,
334
+ maxResults?: number,
335
+ publishedAfter?: string,
336
+ publishedBefore?: string,
337
+ ) {
338
+ const count = Math.min(50, Math.max(1, maxResults ?? 10));
339
+ const params: Record<string, string> = {
340
+ part: 'snippet',
341
+ channelId,
342
+ type: 'video',
343
+ order: 'date',
344
+ maxResults: String(count),
345
+ };
346
+ if (publishedAfter) params.publishedAfter = publishedAfter;
347
+ if (publishedBefore) params.publishedBefore = publishedBefore;
348
+
349
+ const data = (await ytGet(key, '/search', params)) as {
350
+ items: {
351
+ id: { videoId?: string };
352
+ snippet: {
353
+ title: string;
354
+ description: string;
355
+ publishedAt: string;
356
+ thumbnails: { default?: { url: string } };
357
+ };
358
+ }[];
359
+ pageInfo: { totalResults: number };
360
+ };
361
+
362
+ return {
363
+ total_results: data.pageInfo.totalResults,
364
+ videos: data.items.map((item) => ({
365
+ video_id: item.id.videoId ?? null,
366
+ title: item.snippet.title,
367
+ description: item.snippet.description,
368
+ published_at: item.snippet.publishedAt,
369
+ thumbnail: item.snippet.thumbnails?.default?.url ?? null,
370
+ })),
371
+ };
372
+ }
373
+
374
+ async function videoComments(key: string, videoId: string, maxResults?: number, order?: string) {
375
+ const count = Math.min(100, Math.max(1, maxResults ?? 20));
376
+ const params: Record<string, string> = {
377
+ part: 'snippet',
378
+ videoId,
379
+ maxResults: String(count),
380
+ order: order ?? 'relevance',
381
+ };
382
+
383
+ const data = (await ytGet(key, '/commentThreads', params)) as {
384
+ items: {
385
+ id: string;
386
+ snippet: {
387
+ topLevelComment: {
388
+ id: string;
389
+ snippet: {
390
+ authorDisplayName: string;
391
+ authorChannelUrl: string;
392
+ textDisplay: string;
393
+ likeCount: number;
394
+ publishedAt: string;
395
+ updatedAt: string;
396
+ };
397
+ };
398
+ totalReplyCount: number;
399
+ };
400
+ }[];
401
+ pageInfo: { totalResults: number };
402
+ };
403
+
404
+ return {
405
+ total_results: data.pageInfo.totalResults,
406
+ comments: data.items.map((thread) => {
407
+ const c = thread.snippet.topLevelComment.snippet;
408
+ return {
409
+ comment_id: thread.snippet.topLevelComment.id,
410
+ author: c.authorDisplayName,
411
+ author_channel_url: c.authorChannelUrl,
412
+ text: c.textDisplay,
413
+ like_count: c.likeCount,
414
+ reply_count: thread.snippet.totalReplyCount,
415
+ published_at: c.publishedAt,
416
+ updated_at: c.updatedAt,
417
+ };
418
+ }),
419
+ };
420
+ }
421
+
422
+ // ── callTool dispatcher ──────────────────────────────────────────────
423
+
424
+ async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
425
+ const apiKey = extractKey(args);
426
+
427
+ switch (name) {
428
+ case 'yt_search':
429
+ return search(
430
+ apiKey,
431
+ args.query as string,
432
+ args.type as string | undefined,
433
+ args.max_results as number | undefined,
434
+ args.channel_id as string | undefined,
435
+ args.order as string | undefined,
436
+ args.published_after as string | undefined,
437
+ );
438
+ case 'yt_video_details':
439
+ return videoDetails(apiKey, args.video_id as string);
440
+ case 'yt_channel_details':
441
+ return channelDetails(
442
+ apiKey,
443
+ args.channel_id as string | undefined,
444
+ args.username as string | undefined,
445
+ );
446
+ case 'yt_channel_videos':
447
+ return channelVideos(
448
+ apiKey,
449
+ args.channel_id as string,
450
+ args.max_results as number | undefined,
451
+ args.published_after as string | undefined,
452
+ args.published_before as string | undefined,
453
+ );
454
+ case 'yt_video_comments':
455
+ return videoComments(
456
+ apiKey,
457
+ args.video_id as string,
458
+ args.max_results as number | undefined,
459
+ args.order as string | undefined,
460
+ );
461
+ default:
462
+ throw new Error(`Unknown tool: ${name}`);
463
+ }
464
+ }
465
+
466
+ export default { tools, callTool, meter: { credits: 5 } } satisfies McpToolExport;
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "strict": true,
7
+ "esModuleInterop": true,
8
+ "skipLibCheck": true,
9
+ "outDir": "dist",
10
+ "rootDir": "src",
11
+ "declaration": true
12
+ },
13
+ "include": ["src"]
14
+ }