lc
leetcode mcp server written in golang
claude mcp add --transport stdio moresearch-lc-mcp-server go run auth.go \ --env CSRF_TOKEN="your CSRF token value" \ --env LEETCODE_SESSION="your LeetCode session value"
How to use
This MCP server implements a Go-based utility to extract LeetCode authentication cookies (LEETCODE_SESSION and CSRF_TOKEN) for use in scripts, bots, or custom clients. When run, it launches a browser and guides you through a manual login flow, including any Cloudflare challenges. After you reach the main LeetCode page, you can export the resulting cookies as environment variables for your applications. The tool emphasizes security by avoiding embedded credentials and by requiring you to perform the login in your own browser.
Once authenticated, the utility prints or outputs environment variable assignments that you can export in your shell, such as export LEETCODE_SESSION="..." and export CSRF_TOKEN="...". You can pipe these into your shell or save them to a file and source it in your project. This makes it straightforward to reuse credentials across scripts or services that interact with LeetCode APIs without embedding sensitive tokens directly in code.
How to install
Prerequisites:
- Go installed on your system (go1.18+ recommended)
- Internet access to fetch dependencies
Installation steps:
- Install dependencies (example):
go get -u github.com/chromedp/chromedp
- Run the authentication utility:
# From the project directory
go run auth.go
-
Follow the on-screen prompts to log in via the launched browser. Complete any Cloudflare or LeetCode login steps, then press Enter in the terminal when prompted to finish extraction.
-
Export the credentials for use in your projects:
eval $(go run auth.go)
Alternatively, save to a file and source it:
go run auth.go > .leetcode.env
source .leetcode.env
Your environment will then contain LEETCODE_SESSION and CSRF_TOKEN for immediate use.
Additional notes
Tips and gotchas:
- Treat LEETCODE_SESSION and CSRF_TOKEN as highly sensitive. Do not commit them to version control.
- If Cloudflare challenges persist, ensure you interact with the page (move the mouse, scroll) and consider increasing wait time between steps.
- If cookies aren’t appearing, confirm you reached a logged-in page rather than the login screen again.
- On Windows, ensure Chrome is installed and accessible by the chromedp setup used by this utility.
- Tokens expire; re-authenticate when necessary and re-export updated values.
- If you’re automating with scripts, prefer exporting tokens at runtime rather than hard-coding in your code.
Related MCP Servers
trpc-agent-go
trpc-agent-go is a powerful Go framework for building intelligent agent systems using large language models (LLMs) and tools.
station
Station is our open-source runtime that lets teams deploy agents on their own infrastructure with full control.
tiger-cli
Tiger CLI is the command-line interface for Tiger Cloud. It includes an MCP server for helping coding agents write production-level Postgres code.
gopls
MCP server for golang projects development: Expand AI Code Agent ability boundary to have a semantic understanding and determinisic information for golang projects.
kubernetes
A Model Context Protocol (MCP) server for the Kubernetes API.
gcp-cost
💰 An MCP server that enables AI assistants to estimate Google Cloud costs, powered by Cloud Billing Catalog API and built with Genkit for Go