Skip to main content
Glama

search_problems

Search LeetCode problems by category, tags, difficulty, and keywords to find relevant coding challenges with pagination support.

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
tagsNoList of topic tags to filter problems by (e.g., ['array', 'dynamic-programming', 'tree'])
difficultyNoProblem difficulty level filter to show only problems of a specific difficulty
searchKeywordsNoKeywords to search in problem titles and descriptions
limitNoMaximum number of problems to return in a single request (for pagination)
offsetNoNumber of problems to skip (for pagination)

Implementation Reference

  • Registers the MCP 'search_problems' tool with server.tool(): includes full description, Zod input schema for filters and pagination, and handler that delegates to leetcodeService.searchProblems returning formatted JSON.
    this.server.tool( "search_problems", "Searches for LeetCode problems based on multiple filter criteria including categories, tags, difficulty levels, and keywords, with pagination support", { 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)") }, 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 }) } ] }; } );
  • Handler function for the 'search_problems' tool: destructures input params, calls leetcodeService.searchProblems, formats response as MCP content with JSON text containing filters, pagination info, and problems data.
    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 schema for 'search_problems' tool inputs: category (enum default 'all-code-essentials'), optional tags array (enum), difficulty (EASY/MEDIUM/HARD), optional searchKeywords string, limit number (default 10), optional offset number.
    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)") },
  • LeetCodeCNService.searchProblems implementation: builds filters object, executes SEARCH_PROBLEMS_QUERY GraphQL with variables, processes response to return hasMore, total, questions with title, slug, difficulty, etc.
    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) })) }; }
  • GraphQL query SEARCH_PROBLEMS_QUERY for problemsetQuestionList: supports categorySlug, limit, skip, filters (tags, difficulty, searchKeywords); returns hasMore, total, questions details.
    export const SEARCH_PROBLEMS_QUERY = ` query problemsetQuestionList( $categorySlug: String $limit: Int $skip: Int $filters: QuestionListFilterInput ) { problemsetQuestionList( categorySlug: $categorySlug limit: $limit skip: $skip filters: $filters ) { hasMore total questions { title titleCn titleSlug difficulty acRate topicTags { slug } } } }`;

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