Skip to main content
Glama

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; }

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