Skip to main content
Glama
Asynchronous-0x4C

Reddit Research MCP

README.md
# Reddit Research MCP

Reddit を **読むだけ** の MCP サーバー。
「自分が自然に役に立てる会話」を探して整理するところまでを担当し、
投稿は必ず人間が Reddit の UI で行う。

このサーバーは Reddit へ **書き込まない**。投稿・コメント・編集・削除・投票・DM 送信・
フォローの経路をコードとして持たない。ブラウザ自動操作も HTML スクレイピングもしない。
**方針ではなく、実装とテストで固定してある。**

なぜそう作ったかは [`docs/DESIGN.md`](docs/DESIGN.md)。

> **状態: v0.1。実際の Reddit へは 1 リクエストも送っていない。**
> MCP ツール 13 本・OAuth・rate limiter・SQLite・スコアリング・digest まで実装済み。
> テストはすべて**モックの Reddit** に対して通っている。
>
> 実接続していないのは、Reddit の API 利用に**事前の承認が要る**ため(下記)。

---

## 規約について(先に読む)

**このリポジトリは「Reddit の規約上、この使い方が許されている」とは主張しない。**

2026-09-08 時点で、Reddit の [Responsible Builder Policy](https://support.reddithelp.com/hc/en-us/articles/42728983564564-Responsible-Builder-Policy)
は次のように定めている:

> *"Approval is required: You must request access and get explicit approval before accessing
> any Reddit data through our API"* / *"This policy applies to everyone"*

`/prefs/apps` からの自己申請では通らない。チケットでの申請が必要である。
**商用目的での利用には、さらに別の書面での permission が要る。**

- [Developer Terms](https://redditinc.com/policies/developer-terms)
- [Data API Terms](https://redditinc.com/policies/data-api-terms)

**承認を得るまで、実際の Reddit へ接続しないこと。**
テストはモックに対して回るので、待つあいだも開発はできる。

---

## 何をするか

1. 自分の活動を読む(貢献と自己宣伝の比率を出すため)
2. 決められたサブレディットだけを検索し、答えられそうな質問を拾う
3. サブレディットの規約を読む。**判定できなければ `unknown` のままにする**
4. 「製品に触れずに有益な回答が成立するか」を最大の重みにして並べる
5. 1 日分の候補として、方針と材料を返す

**返すのは方針と材料まで。そのまま貼れるコメント本文は返さない。**

## 動かす

```bash
python -m venv .venv
.venv/Scripts/activate       # Windows。POSIX なら .venv/bin/activate
pip install -e ".[dev]"
pytest
```

Python 3.14 / `mcp` 2.2 / httpx / pydantic v2 / 標準の `sqlite3` / `keyring`。

`config.yaml` が無い状態でもテストは通る。
`tests/conftest.py` が `tests/fixtures/data/` の作り物へ切り替えるため。

### 自分の設定を作る

```bash
cp config.example.yaml config.yaml
cp data/product.example.yaml data/product.yaml
cp .env.example .env            # REDDIT_CLIENT_ID などを埋める
```

`data/subreddits.yaml` と `data/expertise.yaml` は同梱していない(下記)。
形は `tests/fixtures/data/` を参考にすること。

### Reddit の認可(承認を得たあと)

```bash
python -m reddit_research_mcp.auth --status
python -m reddit_research_mcp.auth
```

installed app として登録し、redirect URI は `http://localhost:8765/callback`。
refresh token は OS の資格情報ストア(`keyring`)へ入る。**`.env` には置かない。**

### MCP サーバーとして起動

```bash
python -m reddit_research_mcp.server
```

Reddit の認証が無くても、`policy_status` と `product_*` は応答する。

## 同梱していないもの

運用に使うデータは含まれない。**個人の一次情報だからである。**

| 含まれない | 何か |
|---|---|
| `data/subreddits.yaml` | どこで貢献してよいか(role 付きのサブレディット表) |
| `data/expertise.yaml` | 本人が一次情報として持っている知識 |
| `data/product.yaml` | 製品の事実(既定では返らない) |
| `data/templates/` | 実機で確認する手順 |
| `config.yaml` / `.env` | 運用の設定と資格情報 |

雛形と、テスト用の作り物(`tests/fixtures/data/`)は入っている。

## 中身の地図

```
src/reddit_research_mcp/
├── server.py            MCP ツール 13 本。ここに業務ロジックを書かない
├── policy.py            安全境界の純関数。Reddit に触らない。門はすべてここ
├── logs.py              秘密情報を伏せるロガー
├── auth.py              初回の認可 CLI
├── config/              設定とデータの読み込み。不変条件はここで落とす
├── reddit/              API アクセス層。書き込み系をここに置かない
│   ├── client.py        GET だけを出す。唯一の出口は get() / get_dict()
│   ├── oauth.py         POST を出す唯一の場所(トークン交換のみ)
│   └── rate_limiter.py  全リクエストがここを通る
├── services/            データを判断の材料に変える
├── product/             ローカル知識。mode が never なら製品情報を返さない
└── storage/             SQLite と retention cleanup
```

**候補を出す経路は必ず `policy.evaluate()` を通る。**
サービス側で独自の判定を足さない。

## テスト

```bash
pytest                        # 全部
pytest tests/unit/test_safety.py   # 安全境界だけ
ruff check src tests
mypy
```

`tests/unit/test_safety.py` は、書き込み経路・ブラウザ自動操作・
秘密情報の漏れ・レート制限の回避を、ソースを読んで機械的に検出する。
**ここを緩める変更は、まずテストが落ちる。**

運用データを検査する `tests/unit/test_data_files.py` は、
対象のファイルが無ければ skip される(緩めているのではなく、対象が無い)。

## ライセンス

MIT。[`LICENSE`](LICENSE) を参照。

TDQS

A3.9/5.0

Scored across 13 tools

Disambiguation3/5

Most tools are clearly distinct, but reddit_find_opportunities overlaps heavily with reddit_daily_digest since the digest already includes ranked opportunities, and reddit_whoami duplicates the promotion-mode information also exposed by policy_status. The long descriptions help, but an agent could plausibly select the wrong tool for the same task.

Naming Consistency4/5

There is a strong reddit_/product_ prefix pattern and most tools use get_ or a clear action verb, so the set is predictable. A few names break the pattern: reddit_daily_digest, reddit_whoami, and policy_status are noun-style rather than verb_noun, which creates minor inconsistency.

Tool Count4/5

13 tools is within the well-scoped range and each major responsibility has a dedicated tool. The count feels slightly heavier than necessary because reddit_find_opportunities could arguably be folded into reddit_daily_digest, but the overall size is reasonable for read-only Reddit research.

Completeness5/5

The surface covers the core research workflow thoroughly: authentication status, user activity, replies, thread reading, post search, subreddit rules, opportunity ranking, daily digest, product expertise, and verification guidance. Since the server is intentionally read-only, the missing write operations are a deliberate boundary rather than a gap.

Maintenance

ActivityMaintained
ResponsivenessNo issues