get-user-contest-ranking
Retrieve a LeetCode user's contest ranking by submitting their username. This tool enables access to contest data through the MCP server for LeetCode.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| username | Yes | LeetCode username |
Implementation Reference
- src/tools/contest-tools.ts:37-52 (handler)The handler function that implements the core logic of the 'get-user-contest-ranking' tool. It calls LeetCodeService.fetchUserContestRanking, formats the result as JSON, or returns an error response.async ({ username }) => { try { const data = await leetcodeService.fetchUserContestRanking(username); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] }; } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : String(error); return { content: [{ type: "text", text: `Error: ${errorMessage}` }], isError: true }; }
- src/tools/contest-tools.ts:34-36 (schema)Input schema using Zod for validating the 'username' parameter of the tool.{ username: z.string().describe("LeetCode username") },
- src/tools/contest-tools.ts:32-54 (registration)The server.tool() registration call that defines and registers the 'get-user-contest-ranking' MCP tool, including its name, input schema, and handler.server.tool( "get-user-contest-ranking", { username: z.string().describe("LeetCode username") }, async ({ username }) => { try { const data = await leetcodeService.fetchUserContestRanking(username); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] }; } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : String(error); return { content: [{ type: "text", text: `Error: ${errorMessage}` }], isError: true }; } } );
- Helper utility method in LeetCodeService that executes the GraphQL query to fetch the user's contest ranking data.async fetchUserContestRanking(username: string) { return this.executeQuery(userContestRankingQuery, { username }); }
- src/index.ts:24-24 (registration)Top-level call to registerContestTools, which includes registration of the 'get-user-contest-ranking' tool.registerContestTools(server, leetcodeService);