Skip to main content
Glama

search-movies

Find movies by title or keywords using the TMDB MCP Server API. Submit a search query to retrieve results and navigate pages for detailed listings.

Instructions

Search for movies by title or keywords

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pageNoPage number for results
queryYesSearch query

Implementation Reference

  • The handler function for the "search-movies" tool. It receives the input parameters and calls the underlying searchMovies function from tmdb-api.ts, with error handling.
    "search-movies": async ({ query, page = 1, }: { query: string; page?: number; }) => { try { // Return the raw results directly return await searchMovies(query, page); } catch (error: unknown) { if (error instanceof Error) { throw new Error(`Failed to search movies: ${error.message}`); } throw new Error("Failed to search movies: Unknown error"); } },
  • The schema definition for the "search-movies" tool, used for listing tools and input validation.
    "search-movies": { name: "search-movies", description: "Search for movies by title or keywords", inputSchema: { type: "object", properties: { query: { type: "string", description: "Search query", }, page: { type: "number", description: "Page number for results", }, }, required: ["query"], }, },
  • Core implementation of movie search using TMDB API via axios, with retry logic via axiosWithRetry.
    export async function searchMovies(query: string, page: number = 1): Promise<SearchMoviesResponse> { try { const response = await axiosWithRetry<SearchMoviesResponse>({ url: '/search/movie', params: { query: query, page: page } }); return response.data; } catch (error) { const err = error as Error; console.error('Error searching movies:', err.message); throw new Error(`Failed to search movies: ${err.message}`); } }
  • src/handlers.ts:56-98 (registration)
    Registers the ListTools and CallTool request handlers on the MCP server, using the tools schemas and toolHandlers to handle tool listing and execution for all tools including "search-movies".
    // 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); // 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" }; } });

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

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