get_user_stats
Retrieve user-specific watch statistics from Plex Media Server, analyzing viewing habits within a specified time range for insights.
Instructions
Get user-specific watch statistics
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| timeRange | No | Time range in days (default: 30) |
Implementation Reference
- src/index.ts:1041-1075 (handler)The core handler function for the 'get_user_stats' tool. Fetches Plex user accounts from the '/accounts' API endpoint and returns a list with id, name, email, and thumbnail for each user. Includes error handling. Note: The timeRange parameter is not utilized in the current implementation.private async getUserStats(timeRange: number) { try { const data = await this.makeRequest("/accounts"); const users = data.MediaContainer?.Account || []; return { content: [ { type: "text", text: JSON.stringify({ users: users.map((user: any) => ({ id: user.id, name: user.name, email: user.email, thumb: user.thumb, })), totalUsers: users.length, }, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: JSON.stringify({ message: "User statistics not available", error: "Unable to access user data", }, null, 2), }, ], }; } }
- src/index.ts:174-187 (registration)Tool registration entry in the ListTools handler. Defines the tool name, description, and input schema for MCP protocol compliance.{ name: "get_user_stats", description: "Get user-specific watch statistics", inputSchema: { type: "object", properties: { timeRange: { type: "number", description: "Time range in days (default: 30)", default: 30, }, }, }, },
- src/index.ts:177-186 (schema)Input schema definition specifying the optional 'timeRange' parameter (number, default 30 days).inputSchema: { type: "object", properties: { timeRange: { type: "number", description: "Time range in days (default: 30)", default: 30, }, }, },
- src/index.ts:294-295 (helper)Dispatcher case in the main CallToolRequestSchema handler that routes calls to the specific getUserStats method, extracting and defaulting the timeRange argument.case "get_user_stats": return await this.getUserStats(((args as any)?.timeRange as number) || 30);