get-user-profile
Retrieve detailed LeetCode user information by inputting a valid username. This tool enables AI assistants to access user profiles for analysis or integration purposes.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| username | Yes | LeetCode username |
Implementation Reference
- src/tools/user-tools.ts:12-29 (handler)The async handler function for the 'get-user-profile' tool. It fetches the user's LeetCode profile using LeetCodeService, stringifies the data as JSON, and returns it as text content. Handles errors by returning an error message.async ({ username }) => { try { const data = await leetcodeService.fetchUserProfile(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/user-tools.ts:9-11 (schema)Input schema for the 'get-user-profile' tool, validating the 'username' as a required string.{ username: z.string().describe("LeetCode username") },
- src/tools/user-tools.ts:8-29 (registration)Registration of the 'get-user-profile' tool using server.tool(), including the name, input schema, and inline handler function."get-user-profile", { username: z.string().describe("LeetCode username") }, async ({ username }) => { try { const data = await leetcodeService.fetchUserProfile(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 }; } } );
- Supporting helper method in LeetCodeService that executes the GraphQL userProfileQuery to retrieve the profile data.async fetchUserProfile(username: string) { return this.executeQuery(userProfileQuery, { username }); }