Skip to main content
Glama

get_popular_content

Retrieve top-performing Plex media content based on plays or duration within a specified time range. Filter by media type and set limit for precise results.

Instructions

Get most popular content by plays or duration

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNoNumber of items to return (default: 10)
mediaTypeNoFilter by media typeall
metricNoSort by plays or total durationplays
timeRangeNoTime range in days (default: 30)

Implementation Reference

  • The main handler function that implements the get_popular_content tool. It fetches content from all Plex libraries, sorts by viewCount (plays) or lastViewedAt (duration proxy), filters to viewed items only, and returns the top N most popular items.
    private async getPopularContent(timeRange: number, metric: string, mediaType: string, limit: number) {
      try {
        // Get all library content
        const librariesData = await this.makeRequest("/library/sections");
        const libraries = librariesData.MediaContainer?.Directory || [];
        
        let allContent: any[] = [];
        
        for (const library of libraries) {
          try {
            const params: Record<string, any> = {
              "X-Plex-Container-Size": 500,
              sort: metric === "plays" ? "viewCount:desc" : "lastViewedAt:desc",
            };
            
            if (mediaType !== "all") {
              params.type = this.getPlexTypeId(mediaType);
            }
            
            const contentData = await this.makeRequest(`/library/sections/${library.key}/all`, params);
            const content = contentData.MediaContainer?.Metadata || [];
            allContent.push(...content);
          } catch (error) {
            // Skip libraries that can't be accessed
            continue;
          }
        }
        
        // Filter and sort content
        let filteredContent = allContent.filter((item: any) => 
          item.viewCount && item.viewCount > 0
        );
        
        if (metric === "plays") {
          filteredContent.sort((a: any, b: any) => (b.viewCount || 0) - (a.viewCount || 0));
        } else {
          filteredContent.sort((a: any, b: any) => (b.lastViewedAt || 0) - (a.lastViewedAt || 0));
        }
        
        filteredContent = filteredContent.slice(0, limit);
        
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify({
                metric,
                mediaType,
                timeRange: `${timeRange} days`,
                popularContent: filteredContent.map((item: any) => ({
                  ratingKey: item.ratingKey,
                  title: item.title,
                  type: item.type,
                  year: item.year,
                  viewCount: item.viewCount,
                  lastViewedAt: item.lastViewedAt,
                  rating: item.rating,
                  duration: item.duration,
                })),
              }, null, 2),
            },
          ],
        };
      } catch (error) {
        throw new McpError(ErrorCode.InternalError, `Error getting popular content: ${error}`);
      }
    }
  • The input schema definition for the get_popular_content tool, defining parameters like timeRange, metric (plays/duration), mediaType, and limit.
    name: "get_popular_content",
    description: "Get most popular content by plays or duration",
    inputSchema: {
      type: "object",
      properties: {
        timeRange: {
          type: "number",
          description: "Time range in days (default: 30)",
          default: 30,
        },
        metric: {
          type: "string",
          description: "Sort by plays or total duration",
          enum: ["plays", "duration"],
          default: "plays",
        },
        mediaType: {
          type: "string",
          description: "Filter by media type",
          enum: ["movie", "show", "episode", "all"],
          default: "all",
        },
        limit: {
          type: "number",
          description: "Number of items to return (default: 10)",
          default: 10,
        },
      },
    },
  • src/index.ts:298-304 (registration)
    The switch case in the CallToolRequestSchema handler that routes calls to the getPopularContent method, extracting and defaulting arguments.
    case "get_popular_content":
      return await this.getPopularContent(
        ((args as any)?.timeRange as number) || 30,
        (args as any)?.metric as string || "plays",
        (args as any)?.mediaType as string || "all",
        ((args as any)?.limit as number) || 10
      );
  • src/index.ts:201-231 (registration)
    The tool registration in the ListToolsRequestSchema response, including name, description, and input schema.
    {
      name: "get_popular_content",
      description: "Get most popular content by plays or duration",
      inputSchema: {
        type: "object",
        properties: {
          timeRange: {
            type: "number",
            description: "Time range in days (default: 30)",
            default: 30,
          },
          metric: {
            type: "string",
            description: "Sort by plays or total duration",
            enum: ["plays", "duration"],
            default: "plays",
          },
          mediaType: {
            type: "string",
            description: "Filter by media type",
            enum: ["movie", "show", "episode", "all"],
            default: "all",
          },
          limit: {
            type: "number",
            description: "Number of items to return (default: 10)",
            default: 10,
          },
        },
      },
    },
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions sorting by 'plays or duration' but doesn't describe what 'most popular' means (e.g., top-ranked items), whether results are paginated, if authentication is required, or the format of returned data. For a tool with no annotations and no output schema, this leaves significant gaps in understanding its behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence: 'Get most popular content by plays or duration'. It's front-loaded with the core purpose, has zero redundant words, and appropriately sized for a straightforward tool. Every part of the sentence contributes meaning without waste.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (4 parameters, no annotations, no output schema), the description is incomplete. It lacks details on behavioral traits (e.g., authentication, rate limits), output format, and differentiation from siblings. While the schema covers parameters well, the description doesn't compensate for missing annotations or output schema, leaving the agent with insufficient context for reliable use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents all 4 parameters (limit, mediaType, metric, timeRange). The description adds minimal value beyond the schema—it implies the 'metric' parameter controls sorting but doesn't explain semantics like how 'duration' is calculated or what 'most popular' entails. With high schema coverage, the baseline score of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Get most popular content by plays or duration'. It specifies the verb ('Get'), resource ('most popular content'), and sorting criteria ('by plays or duration'). However, it doesn't explicitly differentiate this tool from sibling tools like 'get_recently_watched' or 'get_watch_stats', which might also involve content popularity metrics.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools like 'get_recently_watched' (for recent activity) or 'get_watch_stats' (for statistical analysis), nor does it specify use cases, prerequisites, or exclusions. The agent must infer usage from the purpose alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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