Skip to main content
Glama

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
NameRequiredDescriptionDefault
timeRangeNoTime range in days (default: 30)

Implementation Reference

  • 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,
          },
        },
      },
    },
  • 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,
        },
      },
    },
  • 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);
Install Server

Other Tools

Related Tools

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