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
| Name | Required | Description | Default |
|---|---|---|---|
| username | Yes | LeetCode username to retrieve contest ranking information for | |
| attended | No | Whether to include only the contests the user has participated in (true) or all contests (false); defaults to true |
Implementation Reference
- src/mcp/tools/contest-tools.ts:13-62 (handler)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; }