Skip to main content
Glama

search_problems

Find LeetCode problems by filtering with categories, tags, difficulty levels, or keywords. Supports pagination for efficient navigation through search results.

Instructions

Searches for LeetCode problems based on multiple filter criteria including categories, tags, difficulty levels, and keywords, with pagination support

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
categoryNoProblem category filter (e.g., 'algorithms', 'database', 'shell') to narrow down the problem domainall-code-essentials
difficultyNoProblem difficulty level filter to show only problems of a specific difficulty
limitNoMaximum number of problems to return in a single request (for pagination)
offsetNoNumber of problems to skip (for pagination)
searchKeywordsNoKeywords to search in problem titles and descriptions
tagsNoList of topic tags to filter problems by (e.g., ['array', 'dynamic-programming', 'tree'])

Implementation Reference

  • MCP tool handler for 'search_problems': delegates to LeetCode service and formats response as text content.
    async ({ category, tags, difficulty, limit, offset, searchKeywords }) => { const data = await this.leetcodeService.searchProblems( category, tags, difficulty, limit, offset, searchKeywords ); return { content: [ { type: "text", text: JSON.stringify({ filters: { tags, difficulty, searchKeywords }, pagination: { limit, offset }, problems: data }) } ] }; }
  • Zod input schema for the search_problems tool parameters.
    { category: z .enum(PROBLEM_CATEGORIES as [string]) .default("all-code-essentials") .describe( "Problem category filter (e.g., 'algorithms', 'database', 'shell') to narrow down the problem domain" ), tags: z .array(z.enum(PROBLEM_TAGS as [string])) .optional() .describe( "List of topic tags to filter problems by (e.g., ['array', 'dynamic-programming', 'tree'])" ), difficulty: z .enum(["EASY", "MEDIUM", "HARD"]) .optional() .describe( "Problem difficulty level filter to show only problems of a specific difficulty" ), searchKeywords: z .string() .optional() .describe( "Keywords to search in problem titles and descriptions" ), limit: z .number() .optional() .default(10) .describe( "Maximum number of problems to return in a single request (for pagination)" ), offset: z .number() .optional() .describe("Number of problems to skip (for pagination)") },
  • src/index.ts:93-93 (registration)
    Top-level registration of problem tools (including search_problems) in the main server initialization.
    registerProblemTools(server, leetcodeService);
  • LeetCode CN service implementation of searchProblems using GraphQL query.
    async searchProblems( category?: string, tags?: string[], difficulty?: string, limit: number = 10, offset: number = 0, searchKeywords?: string ): Promise<any> { const filters: any = {}; if (difficulty) { filters.difficulty = difficulty.toUpperCase(); } if (tags && tags.length > 0) { filters.tags = tags; } if (searchKeywords) { filters.searchKeywords = searchKeywords; } const { data } = await this.leetCodeApi.graphql({ query: SEARCH_PROBLEMS_QUERY, variables: { categorySlug: category, limit, skip: offset, filters } }); const questionList = data?.problemsetQuestionList; if (!questionList) { return { hasMore: false, total: 0, questions: [] }; } return { hasMore: questionList.hasMore, total: questionList.total, questions: questionList.questions.map((q: any) => ({ title: q.title, titleCn: q.titleCn, titleSlug: q.titleSlug, difficulty: q.difficulty, acRate: q.acRate, topicTags: q.topicTags.map((tag: any) => tag.slug) })) }; }
  • LeetCode Global service implementation of searchProblems using GraphQL query.
    async searchProblems( category?: string, tags?: string[], difficulty?: string, limit: number = 10, offset: number = 0, searchKeywords?: string ): Promise<any> { const filters: any = {}; if (difficulty) { filters.difficulty = difficulty.toUpperCase(); } if (tags && tags.length > 0) { filters.tags = tags; } if (searchKeywords) { filters.searchKeywords = searchKeywords; } const response = await this.leetCodeApi.graphql({ query: SEARCH_PROBLEMS_QUERY, variables: { categorySlug: category, limit, skip: offset, filters } }); const questionList = response.data?.problemsetQuestionList; if (!questionList) { return { total: 0, questions: [] }; } return { total: questionList.total, questions: questionList.questions.map((question: any) => ({ title: question.title, titleSlug: question.titleSlug, difficulty: question.difficulty, acRate: question.acRate, topicTags: question.topicTags.map((tag: any) => tag.slug) })) }; }

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/jinzcdev/leetcode-mcp-server'

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