Skip to main content
Glama
pmsorhaindo

reddit-mcp

by pmsorhaindo

reddit-mcp

Cursor / Grok Bot 向けconnect-card OAuth用の、読み取り専用の Reddit Data API MCP コネクタです。 Cloudflare Worker として動作し、MCP Streamable HTTP を実装します。呼び出し元の Authorization: Bearer トークンは、https://oauth.reddit.comそのままパススルー されます。

リポジトリ: https://github.com/pmsorhaindo/reddit-mcp

アーキテクチャ

Cursor / Grok Bot
   │  OAuth (connect-card) against Reddit authorize/token
   │  then MCP JSON-RPC with Bearer access token
   ▼
Cloudflare Worker (this repo)
   │  POST /mcp  → tools/list, tools/call
   │  GET  /.well-known/oauth-*  → discovery pointing at Reddit
   ▼
https://oauth.reddit.com  (User-Agent from env, Bearer passthrough)

ルート

目的

GET / または /health

Livenessチェックとエンドポイント一覧

POST /mcp

MCP Streamable HTTP(JSON-RPC: initializetools/listtools/call

GET /.well-known/oauth-authorization-server

OAuth AS メタデータ(Redditのauthorize/token)

GET /.well-known/oauth-protected-resource

このMCP URLに対する保護リソースのメタデータ

GET /callback

開発用ランディングページのみ — コード交換は行いません

なぜ最小限のJSON-RPCなのか(完全なMCP SDKではないのか)

@modelcontextprotocol/sdk は従来、Nodeのトランスポートを対象にしていました。このWorkerは、Durable Objectsやセッションストアを使わずに、Cursor/Grokがツール呼び出しのために必要とする Workersネイティブで依存が少ない Streamable HTTP JSON-RPC サーフェス(initialize / tools/list / tools/call)を実装します。これは Bearerパススルー に適合します。WorkerはRedditのリフレッシュトークンを一切保持しないためです。

ツール

ツール

Reddit API

スコープ

get_me

GET /api/v1/me

identity

list_subscriptions

GET /subreddits/mine/subscriber

mysubreddits

get_user_history

GET /user/{user}/{overview|submitted|comments}

historyread

get_subreddit_feed

GET /r/{sub}/{hot|new|top|rising|controversial}

read

search_reddit

GET /search または /r/{sub}/search

read

すべてのツールは コンパクトなJSON(テキストフィールドは切り詰められます)を返します。limit のデフォルトは 25 で、上限は 100 です。

レート制限

  • Redditへの外部呼び出しは、Workerのisolateごとに直列化されます(promiseチェーン)。

  • レスポンスの X-Ratelimit-Remaining / X-Ratelimit-Reset は、次の呼び出しの前に尊重されます。

  • HTTP 429 / 503 では、Retry-After または指数バックオフによる制限付きリトライが実行されます。

シークレットの取り扱い

本当のシークレットをコミットしないでください。

  • 強力な .gitignore が、.env.dev.vars.wrangler/node_modules/dist/credentials*.json.mcp-auth/ を対象にしています。

  • コミットされるのはサンプルの環境変数ファイルのみです: .dev.vars.example.env.example

  • wrangler.toml には、インラインのシークレットはありません

  • エラーやconsoleログに、Authorization ヘッダー、トークン、シークレット用環境変数の値が含まれることはありません。

  • ツールのエラーペイロードはステータスとメッセージのみです — クレデンシャルを漏らす可能性のある上流のレスポンスボディは含まれません。

Related MCP server: reddit-mcp

Redditアプリのセットアップ

  1. https://www.reddit.com/prefs/apps でRedditアプリを作成します(クライアントに応じて web app または installed app を選択してください)。

  2. リダイレクトURIを追加します:

    • http://localhost:8787/callback — ローカルのwrangler / 手動テスト用

    • https://www.cursor.com/agents/mcp/oauth/callback — Cursor connect-card用

  3. スコープをリクエストします(Redditのauthorize URLではカンマ区切り):

    • identity,read,mysubreddits,history

  4. client_id / client_secret は、OAuthクライアント(Cursor / お使いのシークレットマネージャー)側で控えてください。このリポジトリや wrangler.toml には入れないでください

OAuthディスカバリの前提

  • /.well-known/oauth-authorization-server は以下を公開します:

    • authorization_endpoint: https://www.reddit.com/api/v1/authorize

    • token_endpoint: https://www.reddit.com/api/v1/access_token

  • このWorkerは、認可コードの交換を行わず、リフレッシュトークンも保存しません

  • Cursor / Grok は、クライアントで設定したRedditアプリの認証情報を使ってRedditとのOAuthを完了し、MCPリクエストに Authorization: Bearer <access_token> を付けて送信します。

  • メタデータ内の issuer はこのWorkerのオリジンです。MCPクライアントがMCPベースURLからドキュメントを発見できるようにするためです。authorize/tokenの実行は引き続きReddit側で行われます。

  • Redditのスコープは、authorize URLでは従来どおりカンマ区切りです。クライアントはスコープをそれに合わせて連結する必要があります。

Cloudflareへのデプロイ

前提条件: Node 22+、Cloudflareアカウント、Wranglerへのログイン(npx wrangler login)。

git clone https://github.com/pmsorhaindo/reddit-mcp.git
cd reddit-mcp
npm install

# Local secrets (gitignored)
cp .dev.vars.example .dev.vars
# edit USER_AGENT — must identify you per Reddit API rules

npm run typecheck
npm run dev          # http://127.0.0.1:8787

# Production secret (not committed)
npx wrangler secret put USER_AGENT
npm run deploy

USER_AGENT の例の形状(プレースホルダのみ):

cloudflare-worker:reddit-mcp:0.1.0 (by /u/YOUR_REDDIT_USERNAME)

デプロイ後、workers.devまたはカスタムドメインのURLを確認してください。例: https://reddit-mcp.<account>.workers.dev

MCPサーバーの追加(Cursor / Grok)

AddMcpServer(または同等のconnect-card)を設定する際は次のようにします:

フィールド

URL

https://<your-worker>/mcp

認証

OAuth(connect-card)

スコープ

identity read mysubreddits history

クライアントは、お使いのRedditアプリのclient id / secret と上記のCursorリダイレクトURIを使用します。認証後、MCPツールの呼び出しには、RedditのアクセストークンをBearerヘッダーとして含める必要があります。このWorkerがそれをアップストリームに転送します。

スモークテスト

$BASE$TOKEN はローカルで置き換えてください — トークンはコミットしないでください

BASE=http://127.0.0.1:8787
TOKEN=reddit_access_token_here

# Health
curl -sS "$BASE/health"

# OAuth metadata
curl -sS "$BASE/.well-known/oauth-authorization-server"
curl -sS "$BASE/.well-known/oauth-protected-resource"

# MCP initialize
curl -sS -X POST "$BASE/mcp" \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-03-26","capabilities":{},"clientInfo":{"name":"smoke","version":"0"}}}'

# tools/list
curl -sS -X POST "$BASE/mcp" \
  -H 'Content-Type: application/json' \
  -d '{"jsonrpc":"2.0","id":2,"method":"tools/list"}'

# tools/call get_me (requires valid Bearer)
curl -sS -X POST "$BASE/mcp" \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $TOKEN" \
  -d '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"get_me","arguments":{}}}'

期待される結果: JSON-RPCの結果が返ること。get_me はコンパクトなプロフィールフィールドを返します。Bearerがない場合は、JSON-RPCエラーとして Unauthorized が返り、ヘッダーは漏れません。

スクリプト

スクリプト

コマンド

npm run dev

wrangler dev

npm run deploy

wrangler deploy

npm run typecheck

tsc --noEmit

対象外

  • 書き込み、投票、メッセージ、Moderation、Ads API

  • Worker上でのRedditリフレッシュトークンやクライアントシークレットの保存

  • /callback でのOAuthコード交換の実行

  • 完全なMCPのresources/prompts/sampling/elicitationセッション

  • マルチテナントのトークン保管庫 / Durable ObjectSessionストア

  • クロスアイソレートのグローバルレート制限連携の保証(制限はisolateごととRedditヘッダーによる)

ライセンス

ライセンスファイルを追加しない限り、Private / 未公開となります。

Maintenance

ActivityMaintained
ResponsivenessSyncing

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

  • A
    license
    B
    quality
    D
    maintenance
    An MCP server that provides both read-only and authenticated access to Reddit content and interactions without requiring a developer API key. It enables users to browse posts, search subreddits, and perform write actions like commenting and voting by leveraging browser session cookies.
    8
    1
    The Unlicense
  • F
    license
    Not graded
    quality
    D
    maintenance
    A read-only Model Context Protocol server that enables browsing subreddits, searching within subreddits, retrieving comment trees, and looking up user activity on Reddit via natural language.
  • A
    license
    Not graded
    quality
    D
    maintenance
    A read-only MCP server that connects to the Reddit Data API to search posts, browse subreddits, read comments, view user profiles, and check trending content through the Model Context Protocol.
    12
    1
    MIT
  • A
    license
    Not graded
    quality
    C
    maintenance
    Read-only MCP server for public Reddit content using TypeScript. Enables listing posts, fetching post details and comments, and searching Reddit.
    32
    2
    MIT

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/pmsorhaindo/reddit-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server