Skip to main content
Glama
terryso

tv-recommender-mcp-server

get_recommendations_by_genre

Find TV shows by genre for personalized viewing. Input a genre (e.g., comedy, sci-fi, mystery) to receive tailored recommendations in your preferred category.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
genreYes电视剧类型,如"喜剧"、"科幻"、"悬疑"等,支持中英文

Implementation Reference

  • src/server.ts:39-48 (registration)
    Registers the MCP tool 'get_recommendations_by_genre' with Zod input schema { genre: z.string() } and an inline async handler that logs the request, calls getRecommendationsByGenre(params), and returns the results as JSON string in MCP content format.
    server.tool("get_recommendations_by_genre",
      { genre: z.string().describe('电视剧类型,如"喜剧"、"科幻"、"悬疑"等,支持中英文') },
      async (params) => {
        console.log(`收到按类型获取推荐请求,类型: ${params.genre}`);
        const results = await getRecommendationsByGenre(params);
        return {
          content: [{ type: "text", text: JSON.stringify(results) }]
        };
      }
    );
  • Core handler function getRecommendationsByGenre that validates input, maps genre name to TMDb ID using mapGenreToId, fetches recommendations via tmdbClient.getRecommendationsByGenre, formats the results using helper functions, and returns a formatted string or error message.
    export async function getRecommendationsByGenre(
      params: GetRecommendationsByGenreParams
    ): Promise<string> {
      try {
        // 检查参数
        if (!params.genre) {
          throw new ApiError('缺少必要参数:genre', 400);
        }
        
        // 将用户输入的类型映射到TMDb类型ID
        const genreId = mapGenreToId(params.genre);
        
        // 如果无法识别类型
        if (!genreId) {
          return `抱歉,无法识别您提供的类型"${params.genre}",请尝试其他类型如"喜剧"、"科幻"等。`;
        }
        
        // 获取类型名称(使用中文)
        const genreName = getGenreNameById(genreId) || params.genre;
        
        // 调用TMDb API获取推荐
        const response = await tmdbClient.getRecommendationsByGenre(genreId);
        
        // 格式化结果
        const recommendations = formatShowResults(response.results);
        
        // 返回格式化的字符串
        return formatRecommendationsToString(genreName, recommendations);
        
      } catch (error) {
        // console.error('获取推荐时发生错误:', error);
        return `获取推荐时发生错误: ${formatErrorMessage(error)}`;
      }
    }
  • TypeScript interface defining the input parameters for the getRecommendationsByGenre function: { genre: string }.
    export interface GetRecommendationsByGenreParams {
      genre: string;  // 类型,如"喜剧"或"Comedy"
    }
  • TMDbClient method that performs the actual API call to /discover/tv with genre filter, vote count threshold, sorted by vote_average.desc, limits results, and handles errors.
    async getRecommendationsByGenre(genreId: number, limit = 10) {
      try {
        const response = await this.getClient().get('/discover/tv', {
          params: {
            with_genres: genreId,
            sort_by: 'vote_average.desc', // 按评分降序排序
            'vote_count.gte': 100, // 至少有100个评分,避免低质量内容
            page: 1
          }
        });
        
        // 限制返回结果数量
        response.data.results = response.data.results.slice(0, limit);
        
        return response.data;
      } catch (error) {
        // 记录错误并重新抛出
        // console.error(`获取类型ID ${genreId} 的推荐失败:`, error);
        throw new Error(`获取类型ID ${genreId} 的推荐失败: ${error instanceof Error ? error.message : String(error)}`);
      }
Behavior1/5

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

Tool has no description.

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

Conciseness1/5

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

Tool has no description.

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

Completeness1/5

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

Tool has no description.

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

Parameters1/5

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

Tool has no description.

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

Purpose1/5

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

Tool has no description.

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

Usage Guidelines1/5

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

Tool has no description.

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/terryso/tv-recommender-mcp-server'

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