Skip to main content
Glama

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
NameRequiredDescriptionDefault
attendedNoWhether to include only the contests the user has participated in (true) or all contests (false); defaults to true
usernameYesLeetCode username to retrieve contest ranking information for

Implementation Reference

  • 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 }) } ] }; } }
  • 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" ) },
  • 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; }

Other Tools

Related 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