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
| Name | Required | Description | Default |
|---|---|---|---|
| libraryKey | No | Library section key (optional) |
Implementation Reference
- src/index.ts:1077-1127 (handler)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);
- src/index.ts:191-199 (schema)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)", }, }, },