Skip to content

OAuth flow for your CLI or Node.js app

Lightweight, cross-runtime, with native MCP SDK integration for AI agents

OAuth Callback Demo

Quick Start

typescript
import { getAuthCode } from "oauth-callback";

// Just pass your OAuth URL - that's it!
const result = await getAuthCode(
  "https://github.com/login/oauth/authorize?client_id=xxx",
);

console.log("Auth code:", result.code);
typescript
import { browserAuth, inMemoryStore } from "oauth-callback/mcp";
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";

// OAuth provider for Notion MCP server
// See: https://developers.notion.com/docs/get-started-with-mcp
const authProvider = browserAuth({
  store: inMemoryStore(), // Ephemeral tokens (lost on restart)
});

// Connect to Notion's MCP server with OAuth
const transport = new StreamableHTTPClientTransport(
  new URL("https://mcp.notion.com/mcp"),
  { authProvider },
);

const client = new Client(
  { name: "my-app", version: "1.0.0" },
  { capabilities: {} },
);

await client.connect(transport);
// Now you can use Notion's MCP tools!
bash
# Using Bun (recommended)
bun add oauth-callback

# Using npm
npm install oauth-callback

# Using pnpm
pnpm add oauth-callback
npm versionnpm downloadsMIT License

Released under the MIT License.