Skip to main content
Glama

get-similar

Find movies similar to a specific film using its TMDB ID. This tool helps users discover related content based on movie preferences.

Instructions

Get similar movies to a given movie

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
movieIdYesID of the movie to find similar movies for

Implementation Reference

  • MCP tool handler for 'get-similar' that invokes getSimilarMovies with error handling.
    "get-similar": async ({ movieId }: { movieId: string }) => { try { // Return the raw results directly return await getSimilarMovies(movieId); } catch (error: unknown) { if (error instanceof Error) { throw new Error(`Failed to get similar movies: ${error.message}`); } throw new Error("Failed to get similar movies: Unknown error"); } },
  • JSON Schema definition for the input parameters of the 'get-similar' tool.
    "get-similar": { name: "get-similar", description: "Get similar movies to a given movie", inputSchema: { type: "object", properties: { movieId: { type: "string", description: "ID of the movie to find similar movies for", }, }, required: ["movieId"], }, },
  • Helper function that fetches similar movies from TMDB API using axios.
    export async function getSimilarMovies(movieId: number | string): Promise<SearchMoviesResponse> { try { const response = await axiosWithRetry<SearchMoviesResponse>({ url: `/movie/${movieId}/similar` }); return response.data; } catch (error) { const err = error as Error; console.error('Error getting similar movies:', err.message); throw new Error(`Failed to get similar movies: ${err.message}`); } }
  • src/handlers.ts:13-72 (registration)
    Import of toolHandlers and tools (schemas) in the MCP server handlers setup.
    import { toolHandlers, tools } from "./tools.js"; import type { Server } from "@modelcontextprotocol/sdk/server/index.js"; export const setupHandlers = (server: Server): void => { // Resource handlers server.setRequestHandler( ListResourcesRequestSchema, async () => ({ resources }), ); server.setRequestHandler(ListResourceTemplatesRequestSchema, async () => ({ resourceTemplates, })); server.setRequestHandler(ReadResourceRequestSchema, async (request) => { const { uri } = request.params; // Using type assertion to tell TypeScript this is a valid key const resourceHandler = resourceHandlers[uri as keyof typeof resourceHandlers]; if (resourceHandler) return await resourceHandler(); const resourceTemplateHandler = await getResourceTemplate(uri); if (resourceTemplateHandler) return await resourceTemplateHandler(); throw new Error(`Resource not found: ${uri}`); }); // Prompt handlers server.setRequestHandler(ListPromptsRequestSchema, async () => ({ prompts: Object.values(prompts), })); server.setRequestHandler(GetPromptRequestSchema, async (request) => { const { name, arguments: args } = request.params; // Using type assertion to tell TypeScript this is a valid key const promptHandler = promptHandlers[name as keyof typeof promptHandlers]; if (promptHandler) { return promptHandler(args as any); } throw new Error(`Prompt not found: ${name}`); }); // Tool handlers server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: Object.values(tools), })); // This is the key fix - we need to format the response properly server.setRequestHandler(CallToolRequestSchema, async (request) => { try { const { name, arguments: args } = request.params; // Using type assertion to tell TypeScript this is a valid key const handler = toolHandlers[name as keyof typeof toolHandlers]; if (!handler) throw new Error(`Tool not found: ${name}`); // Execute the handler but wrap the response in the expected format const result = await handler(args as any);
  • src/handlers.ts:62-98 (registration)
    MCP CallTool request handler that dispatches to specific toolHandlers including 'get-similar'.
    server.setRequestHandler(CallToolRequestSchema, async (request) => { try { const { name, arguments: args } = request.params; // Using type assertion to tell TypeScript this is a valid key const handler = toolHandlers[name as keyof typeof toolHandlers]; if (!handler) throw new Error(`Tool not found: ${name}`); // Execute the handler but wrap the response in the expected format const result = await handler(args as any); // Return in the format expected by the SDK return { tools: [{ name, inputSchema: { type: "object", properties: {} // This would ideally be populated with actual schema }, description: `Tool: ${name}`, result }] }; } catch (error) { // Properly handle errors if (error instanceof Error) { return { tools: [], error: error.message }; } return { tools: [], error: "An unknown error occurred" }; } });

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/ShubhanshuSondhiya/MCP-TMDB'

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