Skip to main content
Glama
jinzcdev

LeetCode MCP Server

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
                }
            }
        }
    }`;
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions 'pagination support' which is useful context, but doesn't describe the return format, error conditions, rate limits, authentication needs, or whether this is a read-only operation. For a search tool with 6 parameters and no annotation coverage, this is insufficient behavioral transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, well-structured sentence that efficiently communicates the core functionality without unnecessary words. It's appropriately sized and front-loaded with the essential information about what the tool does and what parameters it accepts.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a search tool with 6 parameters, 100% schema coverage, but no annotations and no output schema, the description provides adequate basic context about what the tool does. However, it lacks information about return format, error handling, and behavioral characteristics that would be important for an agent to use this tool effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all 6 parameters thoroughly with descriptions and enums. The description mentions the filter criteria (categories, tags, difficulty, keywords) and pagination, but adds no additional semantic meaning beyond what's already in the schema. Baseline 3 is appropriate when the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Searches for LeetCode problems based on multiple filter criteria including categories, tags, difficulty levels, and keywords, with pagination support.' This specifies the verb ('searches'), resource ('LeetCode problems'), and scope ('multiple filter criteria'), but doesn't explicitly differentiate it from sibling tools like 'list_problem_solutions' or 'get_problem'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'get_problem' (for single problem retrieval) or 'list_problem_solutions' (for solutions). It mentions filter criteria but doesn't specify use cases or prerequisites, leaving the agent to infer usage from the tool name alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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