Skip to main content
Glama

playlists_getPlaylist

Retrieve YouTube playlist details including videos, metadata, and structure using the playlist ID to analyze or display content.

Instructions

Get information about a YouTube playlist

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
playlistIdYesThe YouTube playlist ID

Implementation Reference

  • Core implementation of the playlists_getPlaylist tool logic, calling YouTube Data API v3 playlists.list to retrieve playlist details.
    async getPlaylist({ 
      playlistId 
    }: PlaylistParams): Promise<unknown> {
      try {
        this.initialize();
        
        const response = await this.youtube.playlists.list({
          part: ['snippet', 'contentDetails'],
          id: [playlistId]
        });
        
        return response.data.items?.[0] || null;
      } catch (error) {
        throw new Error(`Failed to get playlist: ${error instanceof Error ? error.message : String(error)}`);
      }
    }
  • Registers the 'playlists_getPlaylist' tool with the MCP server, including input schema, description, and a thin handler that delegates to PlaylistService.getPlaylist.
    server.registerTool(
        'playlists_getPlaylist',
        {
            title: 'Get Playlist Information',
            description: 'Get information about a YouTube playlist',
            annotations: { readOnlyHint: true, idempotentHint: true },
            inputSchema: {
                playlistId: z.string().describe('The YouTube playlist ID'),
            },
        },
        async ({ playlistId }) => {
            const result = await playlistService.getPlaylist({ playlistId });
            return {
                content: [{
                    type: 'text',
                    text: JSON.stringify(result, null, 2)
                }]
            };
        }
    );
  • Zod-based input schema for the tool, defining the required 'playlistId' parameter.
    inputSchema: {
        playlistId: z.string().describe('The YouTube playlist ID'),
    },
  • TypeScript interface defining the parameters for the playlist service method.
    /**
     * Playlist parameters
     */
    export interface PlaylistParams {
      playlistId: string;
    }
  • Helper method to lazily initialize the YouTube API client using the API key from environment variables.
    private initialize() {
      if (this.initialized) return;
      
      const apiKey = process.env.YOUTUBE_API_KEY;
      if (!apiKey) {
        throw new Error('YOUTUBE_API_KEY environment variable is not set.');
      }
    
      this.youtube = google.youtube({
        version: "v3",
        auth: apiKey
      });
      
      this.initialized = true;
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/sfiorini/youtube-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server