get_user_contest_ranking
Retrieve LeetCode user contest rankings, including participation history, overall rank, and performance metrics, tailored by username and participation status.
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 |
|---|---|---|---|
| attended | No | Whether to include only the contests the user has participated in (true) or all contests (false); defaults to true | |
| username | Yes | LeetCode username to retrieve contest ranking information for |
Implementation Reference
- src/mcp/tools/contest-tools.ts:30-61 (handler)The handler function for the get_user_contest_ranking tool. It fetches the contest ranking data from the LeetCode service and returns it as JSON-formatted text content, or an error message if failed.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/mcp/tools/contest-tools.ts:16-29 (schema)Zod schema defining the input parameters: username (string, required) and attended (boolean, optional, default true).{ 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" ) },
- src/mcp/tools/contest-tools.ts:13-62 (registration)Registration of the get_user_contest_ranking tool using server.tool(), including name, description, input schema using Zod, and inline handler function.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 }) } ] }; } } );
- Implementation of fetchUserContestRanking in LeetCodeGlobalService: fetches user contest info via API and optionally filters to only attended contests.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 in LeetCodeCNService: fetches user contest info via API and optionally filters to only attended contests.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; }