Skip to main content
Glama

get_library_stats

Retrieve detailed statistics for Plex Media Server libraries, such as media counts and usage insights, using the library section key for specific data. Enhances content management and analysis capabilities.

Instructions

Get library-specific statistics

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
libraryKeyNoLibrary section key (optional)

Implementation Reference

  • The core handler function for the get_library_stats tool. Retrieves detailed statistics for a specific Plex library if libraryKey is provided, or summaries for all libraries otherwise. Uses the Plex API endpoints /library/sections/{key} or /library/sections.
    private async getLibraryStats(libraryKey?: string) { if (libraryKey) { const data = await this.makeRequest(`/library/sections/${libraryKey}`); const library = data.MediaContainer?.Directory?.[0]; if (!library) { throw new McpError(ErrorCode.InvalidRequest, `Library not found: ${libraryKey}`); } return { content: [ { type: "text", text: JSON.stringify({ library: { key: library.key, title: library.title, type: library.type, count: library.count, scannedAt: library.scannedAt, updatedAt: library.updatedAt, language: library.language, locations: library.Location?.map((loc: any) => loc.path) || [], }, }, null, 2), }, ], }; } else { const data = await this.makeRequest("/library/sections"); const libraries = data.MediaContainer?.Directory || []; return { content: [ { type: "text", text: JSON.stringify({ libraries: libraries.map((lib: any) => ({ key: lib.key, title: lib.title, type: lib.type, count: lib.count, scannedAt: lib.scannedAt, })), totalLibraries: libraries.length, }, null, 2), }, ], }; } }
  • src/index.ts:188-200 (registration)
    Tool registration in the ListTools response, including name, description, and input schema defining optional libraryKey parameter.
    { name: "get_library_stats", description: "Get library-specific statistics", inputSchema: { type: "object", properties: { libraryKey: { type: "string", description: "Library section key (optional)", }, }, }, },
  • src/index.ts:296-297 (registration)
    Dispatcher case in the CallToolRequestSchema handler that routes calls to get_library_stats to the appropriate method.
    case "get_library_stats": return await this.getLibraryStats((args as any)?.libraryKey as string);
  • Input schema for the get_library_stats tool, specifying an optional string libraryKey.
    inputSchema: { type: "object", properties: { libraryKey: { type: "string", description: "Library section key (optional)", }, }, },

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/niavasha/plex-mcp-server'

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