Skip to main content
Glama

search-problems

Filter and retrieve LeetCode problems by tags, difficulty, or limit results. Use this tool to find specific coding challenges for practice or preparation.

Input Schema

NameRequiredDescriptionDefault
difficultyNoDifficulty level
limitNoMaximum number of problems to return
skipNoNumber of problems to skip
tagsNoTags to filter by, separated by '+' (e.g., 'array+dynamic-programming')

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "difficulty": { "description": "Difficulty level", "enum": [ "EASY", "MEDIUM", "HARD" ], "type": "string" }, "limit": { "default": 20, "description": "Maximum number of problems to return", "maximum": 100, "minimum": 1, "type": "number" }, "skip": { "default": 0, "description": "Number of problems to skip", "type": "number" }, "tags": { "description": "Tags to filter by, separated by '+' (e.g., 'array+dynamic-programming')", "type": "string" } }, "type": "object" }

Implementation Reference

  • The handler function for the "search-problems" MCP tool. It receives input parameters, calls LeetCodeService.searchProblems, formats the result as JSON text content, and handles errors.
    async ({ tags, difficulty, limit, skip }) => { try { const data = await leetcodeService.searchProblems(tags, difficulty, limit, skip); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] }; } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : String(error); return { content: [{ type: "text", text: `Error: ${errorMessage}` }], isError: true }; } }
  • Zod input schema defining parameters for the search-problems tool: optional tags, difficulty, limit, and skip.
    { tags: z.string().optional().describe("Tags to filter by, separated by '+' (e.g., 'array+dynamic-programming')"), difficulty: z.enum(["EASY", "MEDIUM", "HARD"]).optional().describe("Difficulty level"), limit: z.number().min(1).max(100).optional().default(20).describe("Maximum number of problems to return"), skip: z.number().optional().default(0).describe("Number of problems to skip") },
  • Registration of the "search-problems" tool using McpServer.tool(), including schema and handler.
    // Search problems server.tool( "search-problems", { tags: z.string().optional().describe("Tags to filter by, separated by '+' (e.g., 'array+dynamic-programming')"), difficulty: z.enum(["EASY", "MEDIUM", "HARD"]).optional().describe("Difficulty level"), limit: z.number().min(1).max(100).optional().default(20).describe("Maximum number of problems to return"), skip: z.number().optional().default(0).describe("Number of problems to skip") }, async ({ tags, difficulty, limit, skip }) => { try { const data = await leetcodeService.searchProblems(tags, difficulty, limit, skip); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] }; } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : String(error); return { content: [{ type: "text", text: `Error: ${errorMessage}` }], isError: true }; } } );
  • Helper method in LeetCodeService that executes the GraphQL search query for problems based on tags, difficulty, limit, and skip.
    async searchProblems(tags?: string, difficulty?: string, limit: number = 20, skip: number = 0) { return this.executeQuery(searchProblemsQuery, { categorySlug: "", limit, skip, filters: { tags: tags ? tags.split("+") : [], difficulty: difficulty || null } }); }
  • GraphQL query definition used by LeetCodeService.searchProblems to fetch problem list from LeetCode API.
    export const searchProblemsQuery = ` query problemsetQuestionList($categorySlug: String, $limit: Int, $skip: Int, $filters: QuestionListFilterInput) { problemsetQuestionList: questionList( categorySlug: $categorySlug limit: $limit skip: $skip filters: $filters ) { total: totalNum questions: data { acRate difficulty freqBar frontendQuestionId: questionFrontendId isFavor paidOnly: isPaidOnly status title titleSlug topicTags { name id slug } hasSolution hasVideoSolution } } } `;

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

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