feat(mcp): add optional auth cookie injection for authenticated requests#90
Open
Itish2003 wants to merge 5 commits intoalfaarghya:mainfrom
Open
feat(mcp): add optional auth cookie injection for authenticated requests#90Itish2003 wants to merge 5 commits intoalfaarghya:mainfrom
Itish2003 wants to merge 5 commits intoalfaarghya:mainfrom
Conversation
…ode API requests Reads session cookies from a JSON file specified by the LEETCODE_COOKIES_FILE env var and injects Cookie + x-csrftoken headers into all GraphQL requests. When no cookie file is configured, behavior is unchanged (unauthenticated). This unlocks authenticated endpoints: submission history, private problem lists, contest participation, and user-specific profile data. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Documents the LEETCODE_COOKIES_FILE env var for optional cookie-based authentication, including cookie file format and MCP client config example. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Adds scripts/extract-cookies.ts that opens a browser to LeetCode login, waits for the user to authenticate, then automatically saves session cookies to a JSON file with 600 permissions. Supports all login methods (username/password, Google, GitHub, Apple) since it polls the cookie jar rather than listening for specific redirects. Co-Authored-By: Claude Opus 4.6 <[email protected]>
… script - Prevent accidental commit of leetcode-cookies.json (contains session secrets) - Add playwright as optional dependency (heavy, only needed for cookie extraction) - Add npm run extract-cookies convenience script Co-Authored-By: Claude Opus 4.6 <[email protected]>
… and favorites Add tools that leverage the cookie auth injection to provide authenticated LeetCode API access: user status, daily streak, favorites lists, submission details with source code, problem notes (read/write), favorite management (add/remove), and lightweight problem status checks. Includes requireAuth() guard that gives clear error messages when cookies aren't configured, and 8 new GraphQL query/mutation definitions. Co-Authored-By: Claude Opus 4.6 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
LEETCODE_COOKIES_FILEenv varCookieandx-csrftokenheaders into all outgoing requests when configuredWhat this unlocks
Authenticated LeetCode API endpoints including:
New auth-required tools (9)
All tools include
[Auth Required]prefix in their descriptions and callrequireAuth()before any API request, giving a clear error when cookies aren't configured.User tools (3)
leetcode_user_statusleetcode_user_streakleetcode_user_favoritesProblem tools (6)
leetcode_submission_detailsleetcode_problem_noteleetcode_problem_note_updateleetcode_problem_favorite_addleetcode_problem_favorite_removeleetcode_problem_statusChanges
mcp/serverUtils.tsloadAuthData()for cookie injection +requireAuth()guardmcp/types.tsSubmissionDetailArgs,QuestionNoteArgs,ToggleFavoriteArgstypesmcp/leetCodeService.tsmcp/modules/userTools.tsmcp/modules/problemTools.tssrc/GQLQueries/index.tssrc/GQLQueries/*.tsscripts/extract-cookies.tsREADME.md.gitignoreleetcode-cookies.jsonto prevent accidental secret commitspackage.jsonplaywrightas optional dep +npm run extract-cookiesscriptCookie file format
{ "LEETCODE_SESSION": "<session cookie>", "csrftoken": "<csrf token>", "cf_clearance": "<cloudflare clearance cookie>" }Test plan
x-csrftokenheader is correctly injectedscripts/extract-cookies.tsopens browser and saves cookies on loginleetcode-cookies.jsonis ignored by gitrequireAuth()guard returns clear error when cookies not configuredleetcode_submission_detailsreturns full source code + runtime/memory percentilesleetcode_problem_note_updateround-trip: write note → read back confirms persistenceleetcode_problem_favorite_add/removeboth return{ ok: true }npm run lintclean, all 236 existing tests pass (0 regressions)🤖 Generated with Claude Code