Skip to main content
Glama
jinzcdev

LeetCode MCP Server

get_user_contest_ranking

Retrieve a user's LeetCode contest ranking, performance metrics, and participation history to analyze competitive programming progress.

Instructions

Retrieves a user's contest ranking information on LeetCode, including overall ranking, participation history, and performance metrics across contests

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
usernameYesLeetCode username to retrieve contest ranking information for
attendedNoWhether to include only the contests the user has participated in (true) or all contests (false); defaults to true

Implementation Reference

  • MCP tool registration and inline handler for 'get_user_contest_ranking'. Defines input schema with zod, fetches user contest ranking via LeetCode service, and returns JSON-formatted response or error.
    this.server.tool(
        "get_user_contest_ranking",
        "Retrieves a user's contest ranking information on LeetCode, including overall ranking, participation history, and performance metrics across contests",
        {
            username: z
                .string()
                .describe(
                    "LeetCode username to retrieve contest ranking information for"
                ),
            attended: z
                .boolean()
                .optional()
                .default(true)
                .describe(
                    "Whether to include only the contests the user has participated in (true) or all contests (false); defaults to true"
                )
        },
        async ({ username, attended = true }) => {
            try {
                const data =
                    await this.leetcodeService.fetchUserContestRanking(
                        username,
                        attended
                    );
                return {
                    content: [
                        {
                            type: "text",
                            text: JSON.stringify({
                                username,
                                contestRanking: data
                            })
                        }
                    ]
                };
            } catch (error: any) {
                return {
                    content: [
                        {
                            type: "text",
                            text: JSON.stringify({
                                error: "Failed to fetch user contest ranking",
                                message: error.message
                            })
                        }
                    ]
                };
            }
        }
    );
  • src/index.ts:95-95 (registration)
    Top-level registration of contest tools in the main MCP server initialization, which includes the get_user_contest_ranking tool.
    registerContestTools(server, leetcodeService);
  • Implementation of fetchUserContestRanking for LeetCode Global site: fetches contest info via API and optionally filters to attended contests only.
    async fetchUserContestRanking(
        username: string,
        attended: boolean = true
    ): Promise<any> {
        const contestInfo = await this.leetCodeApi.user_contest_info(username);
        if (contestInfo.userContestRankingHistory && attended) {
            contestInfo.userContestRankingHistory =
                contestInfo.userContestRankingHistory.filter((contest: any) => {
                    return contest && contest.attended;
                });
        }
        return contestInfo;
    }
  • Implementation of fetchUserContestRanking for LeetCode CN site: fetches contest info via API and optionally filters to attended contests only.
    async fetchUserContestRanking(
        username: string,
        attended: boolean = true
    ): Promise<any> {
        const contestInfo = await this.leetCodeApi.user_contest_info(username);
        if (contestInfo.userContestRankingHistory && attended) {
            contestInfo.userContestRankingHistory =
                contestInfo.userContestRankingHistory.filter((contest: any) => {
                    return contest && contest.attended;
                });
        }
        return contestInfo;
    }
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. While it indicates this is a retrieval operation (implied read-only), it doesn't specify authentication requirements, rate limits, error conditions, or what happens if the username doesn't exist. For a tool with zero annotation coverage, this leaves significant behavioral gaps.

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

Conciseness4/5

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

The description is a single, efficient sentence that front-loads the core purpose. It could be slightly more structured by separating scope details, but it avoids redundancy and wastes no words. Every part of the sentence contributes meaning.

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 read-only tool with 2 parameters and 100% schema coverage, the description is minimally adequate. However, with no annotations and no output schema, it should provide more behavioral context (e.g., authentication needs, error handling) and clarify the return format. The current description leaves the agent guessing about important operational aspects.

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 fully documents both parameters (username and attended). The description doesn't add any parameter-specific information beyond what's in the schema, such as username format constraints or examples of how the attended flag affects results. Baseline 3 is appropriate when the schema does all the work.

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

Purpose5/5

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

The description clearly states the specific action ('Retrieves'), resource ('user's contest ranking information on LeetCode'), and scope ('including overall ranking, participation history, and performance metrics across contests'). It distinguishes this tool from siblings like get_user_profile (general profile) or get_recent_submissions (recent activity).

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. It doesn't mention when this tool is appropriate compared to siblings like get_user_profile for general user data or get_recent_ac_submissions for recent contest performance. No prerequisites, exclusions, or context for selection are provided.

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