MCPcopy Index your code
hub / github.com/ephraimduncan/opencode-cursor

github.com/ephraimduncan/opencode-cursor @v0.0.9

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.0.9 ↗ · + Follow
136 symbols 250 edges 9 files 21 documented · 15%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

opencode-cursor-oauth

OpenCode plugin that connects to Cursor's API, giving you access to Cursor models inside OpenCode with full tool-calling support.

Install in OpenCode

Add this to ~/.config/opencode/opencode.json:

{
  "$schema": "https://opencode.ai/config.json",
  "plugin": [
    "opencode-cursor-oauth"
  ],
  "provider": {
    "cursor": {
      "name": "Cursor"
    }
  }
}

The cursor provider stub is required because OpenCode drops providers that do not already exist in its bundled provider catalog.

OpenCode installs npm plugins automatically at startup, so users do not need to clone this repository.

Authenticate

opencode auth login --provider cursor

This opens Cursor OAuth in the browser. Tokens are stored in ~/.local/share/opencode/auth.json and refreshed automatically.

Use

Start OpenCode and select any Cursor model. The plugin starts a local OpenAI-compatible proxy on demand and routes requests through Cursor's gRPC API.

How it works

  1. OAuth — browser-based login to Cursor via PKCE.
  2. Model discovery — queries Cursor's gRPC API for all available models.
  3. Local proxy — translates POST /v1/chat/completions into Cursor's protobuf/HTTP/2 Connect protocol.
  4. Native tool routing — rejects Cursor's built-in filesystem/shell tools and exposes OpenCode's tool surface via Cursor MCP instead.

HTTP/2 transport runs through a Node child process (h2-bridge.mjs) because Bun's node:http2 support is not reliable against Cursor's API.

Architecture

OpenCode  -->  /v1/chat/completions  -->  Bun.serve (proxy)
                                              |
                                    Node child process (h2-bridge.mjs)
                                              |
                                     HTTP/2 Connect stream
                                              |
                                    api2.cursor.sh gRPC
                                      /agent.v1.AgentService/Run

Tool call flow

1. Cursor model receives OpenAI tools via RequestContext (as MCP tool defs)
2. Model tries native tools (readArgs, shellArgs, etc.)
3. Proxy rejects each with typed error (ReadRejected, ShellRejected, etc.)
4. Model falls back to MCP tool -> mcpArgs exec message
5. Proxy emits OpenAI tool_calls SSE chunk, pauses H2 stream
6. OpenCode executes tool, sends result in follow-up request
7. Proxy resumes H2 stream with mcpResult, streams continuation

Develop locally

bun install
bun run build
bun test/smoke.ts

Requirements

Extension points exported contracts — how you extend this code

ContentPart (Interface)
A single element in an OpenAI multi-part content array.
src/proxy.ts
TestModules (Interface)
(no doc)
test/smoke.ts
ModelCost (Interface)
(no doc)
src/index.ts
CursorModel (Interface)
(no doc)
src/models.ts
CursorAuthParams (Interface)
(no doc)
src/auth.ts
PendingExec (Interface)
A pending tool execution waiting for results from the caller.
src/proxy.ts
TestCursorBackend (Interface)
(no doc)
test/smoke.ts
CursorCredentials (Interface)
(no doc)
src/auth.ts

Core symbols most depended-on inside this repo

sendSSE
called by 15
src/proxy.ts
makeChunk
called by 13
src/proxy.ts
sendExecResult
called by 12
src/proxy.ts
fetch
called by 8
src/index.ts
textContent
called by 6
src/proxy.ts
assert
called by 5
test/smoke.ts
frameConnectMessage
called by 5
src/proxy.ts
assertArrayEqual
called by 4
test/smoke.ts

Shape

Function 98
Interface 21
Enum 17

Languages

TypeScript100%

Modules by API surface

src/proxy.ts65 symbols
test/smoke.ts24 symbols
src/proto/agent_pb.ts17 symbols
src/models.ts9 symbols
src/index.ts8 symbols
src/h2-bridge.mjs6 symbols
src/auth.ts6 symbols
src/pkce.ts1 symbols

For agents

$ claude mcp add opencode-cursor \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact