YouTube MCP Integration

by spolepaka
Verified
import { Client } from '@modelcontextprotocol/sdk/client/index.js'; // We need to adapt to the SDK's actual export structure // Use a more generic approach for the transport import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js'; async function main() { console.log('Starting YouTube MCP client...'); console.log('NOTE: This is a simple demo. In a real implementation, you would:'); console.log('1. Install the MCP SDK in your project'); console.log('2. Start the MCP server in a separate terminal with: npm run start'); console.log('3. Adapt the transport to match your environment'); console.log('------------------------------------------------------------'); console.log('This demo is configured to show how you would call the YouTube tools'); console.log('from a client application, but will not actually connect to a server.'); console.log('To use with a real server, modify the transport implementation.'); console.log('------------------------------------------------------------\n'); // In a real implementation, you would use the appropriate transport: // For HTTP: // const transport = new HTTPClientTransport({ // baseUrl: 'http://localhost:3000', // sseEndpoint: '/sse', // messageEndpoint: '/messages', // }); // For demonstration purposes, show the expected tools and arguments const AVAILABLE_TOOLS = [ { name: 'youtube_search', description: 'Search for YouTube videos', arguments: [ { name: 'query', description: 'Search query string', required: true }, { name: 'limit', description: 'Maximum number of results (1-10)', required: false } ] }, { name: 'youtube_get_video_info', description: 'Get information about a YouTube video', arguments: [ { name: 'input', description: 'YouTube video ID or URL', required: true } ] }, { name: 'youtube_get_transcript', description: 'Get the transcript of a YouTube video', arguments: [ { name: 'input', description: 'YouTube video ID or URL', required: true } ] } ]; // Show examples of how to use the tools console.log('Available YouTube MCP Tools:'); AVAILABLE_TOOLS.forEach(tool => { console.log(`\n- ${tool.name}: ${tool.description}`); console.log(' Arguments:'); tool.arguments.forEach(arg => { console.log(` - ${arg.name}: ${arg.description}${arg.required ? ' (required)' : ' (optional)'}`); }); }); console.log('\n\nExample usage with MCP client:'); console.log(` // Search for videos const searchResults = await client.callTool({ name: 'youtube_search', arguments: { query: 'javascript tutorial', limit: 3 } }); // Get video info const videoInfo = await client.callTool({ name: 'youtube_get_video_info', arguments: { input: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ' } }); // Get video transcript const transcript = await client.callTool({ name: 'youtube_get_transcript', arguments: { input: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ' } }); `); } main().catch(console.error);