Get the FREE Ultimate OpenClaw Setup Guide →

lc

leetcode mcp server written in golang

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
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:

  1. Install dependencies (example):
go get -u github.com/chromedp/chromedp
  1. Run the authentication utility:
# From the project directory
go run auth.go
  1. 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.

  2. 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

Sponsor this space

Reach thousands of developers