discourse-mcp-extended について
discourse-mcp-extendedは、discourse/discourse-mcpを基にしたMCPサーバーで、Discourseフォーラム向けのツールとリソースにレビューキュー操作を追加しています。フォーラム情報の確認や保留中・フラグ付き項目の処理を行うAIエージェント向けで、書き込みは既定で無効です。
主な機能
- 01Discourseフォーラム情報の読み取り
- 02カテゴリ、タグ、グループのリソース提供
- 03レビューキュー項目の一覧表示
- 04レビュー項目の承認または却下
- 05サイト選択と認証設定
- 06書き込みツールの明示的な有効化
活用シーン
- 01フォーラムのトピックや投稿の検索
- 02カテゴリ、タグ、グループの確認
- 03保留中またはフラグ付きコンテンツの確認
- 04レビューキュー項目への対応
MCP 対応
MCPを通じて、Discourseのツールと読み取り専用リソースをAIエージェントに提供します。既定のstdioに加えてStreamable HTTPにも対応し、レビューなどの書き込みツールは書き込みを有効にした場合だけ登録されます。
設定
ローカルサーバーの設定はどのクライアントでも共通です。コピーしてクライアントの MCP 設定ファイルに貼り付けてください。
ツール
13掲載時のツール一覧 · 2 週間前に更新
| パラメーター | 型 | 必須 | 説明 |
|---|---|---|---|
| site | string | はい | Discourse サイトのベース URL |
詳細
Discourse MCP(拡張フォーク)
これは discourse/discourse-mcp のフォークです。Discourse のレビューキュー(
/review)を扱うツールを追加し、保留中またはフラグ付きの項目の一覧表示、承認、却下を行えます。それ以外は上流版から変更ありません。詳しくは、以下のこのフォークで追加された内容をご覧ください。
AI エージェント向けに、Discourse フォーラムの機能をツールとリソースとして公開する、Model Context Protocol(MCP)の stdio サーバーです。
- エントリーポイント:
src/index.ts→dist/index.jsにコンパイルされます(バイナリ名:discourse-mcp) - SDK:
@modelcontextprotocol/sdk - Node:>= 24
- バージョン:0.2.4(0.2.x には 0.1.x との互換性を損なう変更があります。出力は JSON のみとなり、リストツールはリソースに置き換えられています)
このフォークで追加された内容
discourse_list_reviewables— レビューキュー内の項目(/review?sort_order=scoreに表示されるもの)を一覧表示します。例:承認待ちの新規投稿やキューに入った投稿、フラグ付きの投稿です。サイトの管理者またはモデレーターの API キー、あるいはユーザー API キーが必要です。discourse_perform_reviewable_action— レビューキュー内の項目を承認、却下、またはその他の方法で処理します(他の書き込みツールと同様、書き込みが有効な場合にのみ登録されます)。
入力と出力の詳細は、以下のツールのセクションをご覧ください。このビルドは npm で公開されていないため、npx @discourse/mcp@latest ではなく、このリポジトリをビルドしてローカルで実行してください(pnpm install && pnpm build を実行し、MCP クライアントから dist/index.js を指定します)。
クイックスタート(リリース版)
- 実行(読み取り専用、まずはこちらを推奨)
npx -y @discourse/mcp@latest
次に、MCP クライアントで以下のいずれかを行います。
-
discourse_select_siteツールに{ "site": "https://try.discourse.org" }を渡してサイトを選択する、または -
--site https://try.discourse.orgを指定して、特定のサイトに接続した状態でサーバーを起動する(この場合、discourse_select_siteは非表示になります)。 -
書き込みを有効にする(オプトイン、安全対策あり)
npx -y @discourse/mcp@latest --allow_writes --read_only=false --auth_pairs '[{"site":"https://try.discourse.org","api_key":"'$DISCOURSE_API_KEY'","api_username":"system"}]'
- MCP クライアントで使用する(例:Claude Desktop) — npx 経由
{
"mcpServers": {
"discourse": {
"command": "npx",
"args": ["-y", "@discourse/mcp@latest"],
"env": {}
}
}
}
代替方法:インストール後にグローバルバイナリを使いたい場合は、パッケージが
discourse-mcpを提供します。{ "mcpServers": { "discourse": { "command": "discourse-mcp", "args": [] } } }
設定
サーバーは、MCP サーバー名 @discourse/mcp でツールを登録します。次のいずれかの方法で接続先の Discourse サイトを選択します。
-
実行時に
discourse_select_siteツールを使用する(/about.jsonで検証されます)、または -
起動時に
--site <url>を指定して、サーバーを単一のサイトに接続する(/about.jsonで検証され、discourse_select_siteは非表示になります)。 -
認証
- デフォルトではなしです。
- 管理者 API キー(管理者権限が必要):
--auth_pairs '[{"site":"https://example.com","api_key":"...","api_username":"system"}]' - ユーザー API キー(どのユーザーでも生成可能):
--auth_pairs '[{"site":"https://example.com","user_api_key":"...","user_api_client_id":"..."}]' - HTTP Basic 認証(リバースプロキシの背後にあるサイト向け):任意の
auth_pairsエントリにhttp_basic_userとhttp_basic_passを追加します。これは、リバースプロキシレベルで HTTP Basic 認証によって保護された Discourse サイトで便利です。 auth_pairsには複数のエントリを指定できます。選択したサイトに一致するエントリが使用されます。同じサイトにuser_api_keyとapi_keyの両方が指定されている場合は、user_api_keyが優先されます。
-
書き込みの安全性
- 書き込みはデフォルトで無効です。
- 書き込みツール(
discourse_create_post、discourse_create_topic、discourse_create_category、discourse_update_topic、discourse_create_user、discourse_update_user、discourse_upload_file、discourse_save_draft、discourse_delete_draft、discourse_perform_reviewable_action)は、--allow_writesが指定され、かつ--read_onlyが指定されていない場合にのみ登録されます。 - 書き込みツールを使用するには、選択したサイトに一致する
auth_pairsエントリが必要です。一致するエントリがない場合はエラーが返されます。 - 書き込み操作には、約 1 件/秒のレート制限が適用されます。
-
フラグとデフォルト値
--read_only(既定値:true)--allow_writes(既定値:false)--timeout_ms <number>(既定値:15000)--concurrency <number>(既定値:4)--log_level <silent|error|info|debug>(既定値:info)debug:すべての HTTP リクエスト、レスポンス、詳細なエラー情報を表示しますinfo:再試行の状況と一般的な操作メッセージを表示しますerror:エラーのみを表示しますsilent:ログを出力しません
--show_emails(既定値:false)。ユーザーツールにメールアドレスを含めます。管理者アクセスが必要です--tools_mode <auto|discourse_api_only|tool_exec_api>(既定値:auto)--site <url>:MCP を単一のサイトに固定し、discourse_select_siteを非表示にします。--default-search <prefix>:すべての検索クエリに必ず接頭辞を付けます(例:tag:ai order:latest)。--max-read-length <number>:投稿コンテンツで返される最大文字数(既定値は 50000)。discourse_read_postとdiscourse_read_topicの投稿ごとのコンテンツに適用されます。ツールはinclude_raw=trueを指定してrawコンテンツを優先的に取得します。--allowed_upload_paths <paths>:ローカルファイルのアップロードが許可されるディレクトリを、カンマ区切りのリストまたは JSON 配列で指定します。discourse_upload_fileでローカルファイルのアップロードを有効にするには必須です。例:--allowed_upload_paths "/home/user/images,/tmp/uploads"または--allowed_upload_paths '["/home/user/images"]'--transport <stdio|http>(既定値:stdio):トランスポートの種類です。標準入出力(既定値)にはstdio、JSON レスポンスを返すステートレスモードの Streamable HTTP トランスポートにはhttpを使用します。--port <number>(既定値:3000):HTTP トランスポート使用時にリッスンするポートです。--cache_dir <path>(予約済み)--profile <path.json>(以下を参照)
-
プロファイルファイル(シークレットをコマンドラインに記述しないでください)
{
"auth_pairs": [
{
"site": "https://try.discourse.org",
"api_key": "<redacted>",
"api_username": "system"
},
{
"site": "https://example.com",
"user_api_key": "<user_api_key>",
"user_api_client_id": "<client_id>"
},
{
"site": "https://protected.example.com",
"api_key": "<redacted>",
"api_username": "system",
"http_basic_user": "username",
"http_basic_pass": "password"
}
],
"read_only": false,
"allow_writes": true,
"show_emails": true,
"log_level": "info",
"tools_mode": "auto",
"site": "https://try.discourse.org",
"default_search": "tag:ai order:latest",
"max_read_length": 50000,
"transport": "stdio",
"port": 3000,
"allowed_upload_paths": ["/home/user/images", "/tmp/uploads"]
}
次のコマンドで実行します:
node dist/index.js --profile /absolute/path/to/profile.json
フラグを指定すると、プロファイルの値より優先されます。
-
リモートツール実行 API(任意)
tools_mode=auto(既定値)またはtool_exec_apiの場合、サーバーはサイトを選択した後(または--siteが指定されている場合は起動直後)に GET/ai/toolsでリモートツールを検出し、動的に登録します。リモートツールの検出を無効にするには、--tools_mode=discourse_api_onlyを設定します。
-
ネットワークと耐障害性
- 429/5xx に対して、バックオフを伴う再試行を行います(3 回)。
- 選択したエンドポイントの GET リクエストを軽量なインメモリキャッシュに保存します。
-
プライバシー
- ログ内のシークレットは伏せ字になります。エラーは MCP クライアントに読みやすいメッセージで返されます。
MCP リソース
リソースは、URI を使って静的/準静的な読み取り専用データを提供します。一覧表示の操作には、ツールの代わりにこれらを使用してください。
-
discourse://site/categories
- 階層と権限を含むすべてのカテゴリを一覧表示します
- 出力:
{ categories: [{id, name, slug, pid, read_restricted, topic_count, post_count, perms}], meta: {total} } permsは{gid, perm}の配列です。perm の値は、1=フル、2=投稿作成、3=読み取り専用です- 注:
permsが設定されるのは、管理者/モデレーターの認証がある場合のみです。管理者認証がない場合は、read_restrictedのブール値のみが利用できます。
-
discourse://site/tags
- 使用数を含むすべてのタグを一覧表示します
- 出力:
{ tags: [{id, name, count}], meta: {total} }
-
discourse://site/groups
- 可視性、操作レベル、アクセス設定を含むすべてのグループを一覧表示します
- 出力:
{ groups: [{id, name, automatic, user_count, vis, members_vis, mention, msg, public_admission, public_exit, allow_membership_requests}], meta: {total} } - レベル(0~4):0=公開、1=ログインユーザー、2=メンバー、3=スタッフ、4=オーナー
- ユースケース:カテゴリ権限の
gid値からグループ名を特定し、移行時にグループ設定を再現します
-
discourse://chat/channels
- すべての公開チャットチャンネルを一覧表示します
- 出力:
{ channels: [{id, title, slug, status, members_count, description}], meta: {total} }
-
discourse://user/chat-channels
- 未読数/メンション数を含む、ユーザーのチャットチャンネル(公開チャンネル+DM)を一覧表示します
- 出力:
{ public_channels: [...], dm_channels: [...], meta: {total} } - 認証が必要です
-
discourse://user/drafts
- ユーザーの下書きを一覧表示します
- 出力:
{ drafts: [{draft_key, sequence, title, category_id, created_at, reply_preview}], meta: {total} } - 認証が必要です
ツール
組み込みツール(特記がない限り常に利用可能です)。すべてのツールは厳密な JSON(Markdown なし)を返します。
discourse_search- 入力:
{ query: string; max_results?: number (1–50, default 10) } - 出力:
{ results: [{id, slug, title}], meta: {total, has_more} }
- 入力:
discourse_read_topic- 入力:
{ topic_id: number; post_limit?: number (1–50, default 5); start_post_number?: number } - 出力:
{ id, title, slug, category_id, tags, posts_count, posts: [{id, post_number, username, created_at, raw}], meta }
- 入力:
discourse_read_post- 入力:
{ post_id: number } - 出力:
{ id, topic_id, topic_slug, post_number, username, created_at, raw, truncated }
- 入力:
discourse_get_user- 入力:
{ username: string } - 出力:
{ id, username, name, trust_level, created_at, bio, admin, moderator }
- 入力:
discourse_list_user_posts- 入力:
{ username: string; page?: number (0-based); limit?: number (1–50, default 30) } - 出力:
{ posts: [{id, topic_id, post_number, slug, title, created_at, excerpt, category_id}], meta: {page, limit, has_more} }
- 入力:
discourse_filter_topics- 入力:
{ filter: string; page?: number; per_page?: number (1–50) } - 出力:
{ results: [{id, slug, title}], meta: {page, limit, has_more} } - クエリ言語(簡潔な形式):スペース区切りの key:value トークン。category/categories(カンマ=OR、
=category=サブカテゴリを含めない、-プレフィックス=除外)、tag/tags(カンマ=OR、+=AND)および tag_group、status:(open|closed|archived|listed|unlisted|public)、個人用のin:(bookmarked|watching|tracking|muted|pinned)、日付:created/activity/latest-post-(before|after) はYYYY-MM-DDまたは相対日数N、数値:likes[-op]-(min|max)、posts-(min|max)、posters-(min|max)、views-(min|max)、並べ替え:activity|created|latest-post|likes|likes-op|posters|title|views|category(任意で-ascを指定)。自由入力の検索語も照合されます。
- 入力:
discourse_get_chat_messages- 入力:
{ channel_id: number; page_size?: number (1–50, default 50); target_message_id?: number; direction?: "past" | "future"; target_date?: string (ISO 8601) } - 出力:
{ channel_id, messages: [{id, username, created_at, message, edited, thread_id, in_reply_to_id}], meta }
- 入力:
discourse_get_draft- 入力:
{ draft_key: string; sequence?: number } - 出力:
{ draft_key, sequence, found, data: {title, reply, category_id, tags, action} }
- 入力:
discourse_list_reviewables(管理者/モデレーターの API キーが必要です)- 入力:
{ status?: "pending"|"approved"|"rejected"|"ignored"|"deleted"|"reviewed"|"all"; type?: string; priority?: "low"|"medium"|"high"; sort_order?: "score"|"score_asc"|"created_at"|"created_at_asc"; category_id?: number; topic_id?: number; page?: number } - 出力:
{ reviewables: [{id, type, status, score, created_at, topic_id, category_id, post_id, target_user_id, created_by, target_created_by, title, excerpt, version, actions}], meta: {page, limit, total, has_more} } - レビュ―キューの項目(
/review?sort_order=scoreに表示されるもの)を一覧表示します。承認待ちの新規/キュー登録済み投稿と、フラグが付けられた投稿が含まれます。actionsは、その項目で有効なアクション ID の一覧です(例:approve_post、reject_post、agree_and_hide、disagree、delete)。discourse_perform_reviewable_actionに渡してください。1 ページあたり 10 項目(Discourse の固定ページサイズ)です。
- 入力:
discourse_perform_reviewable_action(書き込みが有効な場合のみ。Write safety を参照)- 入力:
{ reviewable_id: number; action_id: string; version: number; reject_reason?: string; revise_feedback?: string } - 出力:
{ success, reviewable_id, action_id, version, created_post_id, created_post_topic_id, reviewable_updates } - レビューキュー項目を承認、却下、またはその他の方法で処理します。まず
discourse_list_reviewablesを使い、対象項目のreviewable_id、現在のversion、および有効なaction_idの値を取得してください。
- 入力:
discourse_save_draft(書き込みが有効な場合のみ。Write safety を参照)- 入力:
{ draft_key: string; reply: string; title?: string; category_id?: number; tags?: string[]; sequence?: number (default 0); action?: "createTopic" | "reply" | "edit" | "privateMessage" } - 出力:
{ draft_key, sequence, saved }
- 入力:
discourse_delete_draft(書き込みが有効な場合のみ。Write safety を参照)- 入力:
{ draft_key: string; sequence: number } - 出力:
{ draft_key, deleted }
- 入力:
discourse_create_post(書き込みが有効な場合のみ。Write safety を参照)- 入力:
{ topic_id: number; raw: string (<= 30k chars); author_username?: string } - 出力:
{ id, topic_id, post_number }
- 入力:
discourse_create_topic(書き込みが有効な場合のみ。Write safety を参照)- 入力:
{ title: string; raw: string (<= 30k chars); category_id?: number; tags?: string[]; author_username?: string } - 出力:
{ id, topic_id, slug, title }
- 入力:
discourse_update_topic(書き込みが有効な場合のみ。Write safety を参照)- 入力:
{ topic_id: number; title?: string; category_id?: number; tags?: string[]; featured_link?: string; original_title?: string; original_tags?: string[] } - 出力:
{ success, topic_id, updated_fields, topic: {id, title, slug, category_id, tags, featured_link} }
- 入力:
discourse_list_users(管理者 API キーが必要です)- 入力:
{ query?: "active"|"new"|"staff"|"suspended"|"silenced"|"pending"|"staged"; filter?: string; order?: "created"|"last_emailed"|"seen"|"username"|"trust_level"|"days_visited"|"posts"; asc?: boolean; page?: number } - 出力:
{ users: [{id, username, name, email, avatar_template, trust_level, created_at, last_seen_at, admin, moderator, suspended, silenced}], meta: {page, has_more} } - 注:1 ページあたり約 100 人のユーザーを返します(Discourse の固定ページサイズ)。
avatar_templateには{size}プレースホルダーが含まれます。アバター URL を取得するには、ピクセルサイズ(例:120)に置き換えてください。
- 入力:
discourse_create_user(書き込みが有効な場合のみ。Write safety を参照)- 入力:
{ username: string (1-20 chars); email: string; name: string; password: string; active?: boolean; approved?: boolean; upload_id?: number } - 出力:
{ success, username, name, email, active, avatar_updated, message, avatar_error? } - 注:
upload_idを指定したものの、アバターの更新に失敗した場合は、avatar_errorにエラーメッセージが含まれます。
- 入力:
discourse_update_user(書き込みが有効な場合のみ。Write safety を参照)- 入力:
{ username: string; name?: string; bio_raw?: string; location?: string; website?: string; title?: string; date_of_birth?: string; locale?: string; profile_background_upload_url?: string; card_background_upload_url?: string; upload_id?: number } - 出力:
{ success, username, updated_fields, avatar_updated, user: {...}, avatar_error? } - 注:
upload_idを指定したものの、アバターの更新に失敗した場合は、avatar_errorにエラーメッセージが含まれます。
- 入力:
discourse_upload_file(書き込みが有効な場合のみ。Write safety を参照)- 入力:
{ upload_type: "avatar"|"profile_background"|"card_background"|"composer"; image_data?: string (base64); url?: string; filename?: string; user_id?: number } - 出力:
{ id, url, short_url, short_path, original_filename, extension, width, height, filesize, human_filesize } - 制約:
- 次のうち、必ず 1 つだけ指定してください:
image_data(filenameが必要)、リモート HTTP(S) URL、または絶対ローカルファイルパス - avatar/profile_background/card_background のアップロードでは
user_idが必要です - ローカルファイルのアップロードには
--allowed_upload_pathsの設定が必要です(セキュリティ上、任意のファイルの読み取りを防止します)
- 次のうち、必ず 1 つだけ指定してください:
- 注:投稿に画像を埋め込むには
short_url(例:upload://abc123.png)を使用してください。
- 入力:
discourse_create_category(書き込みが有効な場合のみ。Write safety を参照)- 入力:
{ name: string; color?: hex; text_color?: hex; emoji?: string; icon?: string; parent_category_id?: number; description?: string } - 出力:
{ id, slug, name }
- 入力:
discourse_select_site(--siteが指定されている場合は非表示)- 入力:
{ site: string } - 出力:
{ site, title }
- 入力:
開発
-
要件:Node >= 24、
pnpm。 -
インストール/ビルド/型チェック/テスト
pnpm install
pnpm typecheck
pnpm build
pnpm test
- ローカルで実行(ソースマップを使用)
pnpm build && pnpm dev
-
プロジェクト構成
- サーバーと CLI:
src/index.ts - HTTP クライアント:
src/http/client.ts - ツールレジストリ:
src/tools/registry.ts - リソースレジストリ:
src/resources/registry.ts - 組み込みツール:
src/tools/builtin/* - リモートツール:
src/tools/remote/tool_exec_api.ts - JSON ヘルパー:
src/util/json_response.ts - ロギング/秘匿化:
src/util/logger.ts、src/util/redact.ts
- サーバーと CLI:
-
テストに関する注意事項
- テストは、コンパイル済み成果物(
dist/test/**/*.js)に対して Node のテストランナーで実行されます。スクリプトを個別に実行する場合は、pnpm testの前にpnpm buildを実行してください。
- テストは、コンパイル済み成果物(
-
公開(任意)
- このパッケージは
@discourse/mcpとして公開され、discourse-mcpというbinを提供します。手軽に利用するには、npx @discourse/mcp@latestを推奨します。
- このパッケージは
-
規約
- エージェントが確実にプログラムから解析できるよう、すべての出力は JSON のみです。
- 書き込み操作は慎重に行い、オプトイン方式にしてレート制限を設けてください。
エージェントフレームワークからこのサーバーを使用する際の追加ガイダンスについては、AGENTS.md を参照してください。
使用例
ユーザー API キーを使ったクイックスタート(管理者権限不要)
# Step 1: Generate a User API Key
npx @discourse/mcp@latest generate-user-api-key \
--site https://discourse.example.com \
--save-to profile.json
# Step 2: Visit the authorization URL shown, approve the request, and paste the payload
# Step 3: Run the MCP server with your new key
npx @discourse/mcp@latest --profile profile.json --allow_writes --read_only=false
その他の使用例
try.discourse.orgに対する読み取り専用セッション:
npx -y @discourse/mcp@latest --log_level debug
# In client: call discourse_select_site with {"site":"https://try.discourse.org"}
- 単一のサイトに接続する:
npx -y @discourse/mcp@latest --site https://try.discourse.org
- 管理者 API キーを使って投稿を作成する(書き込みを有効化):
npx -y @discourse/mcp@latest --allow_writes --read_only=false --auth_pairs '[{"site":"https://try.discourse.org","api_key":"'$DISCOURSE_API_KEY'","api_username":"system"}]'
- ユーザー API キーを使って投稿を作成する(書き込みを有効化、管理者権限不要):
npx -y @discourse/mcp@latest --allow_writes --read_only=false --auth_pairs '[{"site":"https://try.discourse.org","user_api_key":"'$DISCOURSE_USER_API_KEY'"}]'
- カテゴリを作成する(書き込みを有効化):
npx -y @discourse/mcp@latest --allow_writes --read_only=false --auth_pairs '[{"site":"https://try.discourse.org","api_key":"'$DISCOURSE_API_KEY'","api_username":"system"}]'
# In your MCP client, call discourse_create_category with for example:
# { "name": "AI Research", "color": "0088CC", "text_color": "FFFFFF", "description": "Discussions about AI research" }
- トピックを作成する(書き込みを有効化):
npx -y @discourse/mcp@latest --allow_writes --read_only=false --auth_pairs '[{"site":"https://try.discourse.org","api_key":"'$DISCOURSE_API_KEY'","api_username":"system"}]'
# In your MCP client, call discourse_create_topic, for example:
# { "title": "Agentic workflows", "raw": "Let's discuss agent workflows.", "category_id": 1, "tags": ["ai","agents"] }
- HTTP トランスポートを使って実行する(ポート 3000):
npx -y @discourse/mcp@latest --transport http --port 3000 --site https://try.discourse.org
# Server will start on http://localhost:3000
# Health check: http://localhost:3000/health
# MCP endpoint: http://localhost:3000/mcp
- HTTP Basic 認証の背後にあるサイトに接続する:
npx -y @discourse/mcp@latest --auth_pairs '[{"site":"https://protected.example.com","api_key":"'$DISCOURSE_API_KEY'","api_username":"system","http_basic_user":"username","http_basic_pass":"password"}]' --site https://protected.example.com
認証
管理者 API キーとユーザー API キー
この MCP サーバーは、Discourse API 認証に 2 種類のキーをサポートしています。
-
管理者 API キー(
api_key+api_username)- 生成には管理者/モデレーター権限が必要です
- 管理画面 → API → 新しい API キーから作成します
- ユーザー/カテゴリの作成を含むすべての操作を実行できます
- ヘッダーには
Api-KeyとApi-Usernameを使用します
-
ユーザー API キー(
user_api_key+ 任意のuser_api_client_id)- 管理者権限がなくても、すべてのユーザーが生成できます
- ユーザーごとの権限とレート制限が適用されます
- 個人利用や管理者権限を必要としない操作に最適です
- ヘッダーには
User-Api-KeyとUser-Api-Client-Idを使用します - 180 日間操作がないと自動的に期限切れになります(サイトごとに設定可能)
- 詳細はこちら:https://meta.discourse.org/t/user-api-keys-specification/48536
ユーザー API キーの取得
簡単な方法:組み込みジェネレーター(推奨)
このパッケージには、ユーザー API キーを生成する便利なコマンドが含まれています。
# Interactive mode - follow the prompts
npx @discourse/mcp@latest generate-user-api-key --site https://discourse.example.com
# Save directly to a profile file
npx @discourse/mcp@latest generate-user-api-key --site https://discourse.example.com --save-to profile.json
# Specify custom scopes
npx @discourse/mcp@latest generate-user-api-key --site https://discourse.example.com --scopes "read,write,notifications"
# Get help
npx @discourse/mcp@latest generate-user-api-key --help
このコマンドは次の処理を行います。
- RSA キーペアを生成します
- アクセスする認証 URL を表示します
- 認証後、暗号化されたペイロードを貼り付けるよう促します
- ペイロードを復号して、ユーザー API キーを表示します
- 必要に応じて、プロファイルファイルに保存します
手動で行う方法
ユーザー API キーには、https://meta.discourse.org/t/user-api-keys-specification/48536 に記載されている OAuth に似たフローが必要です。主な手順は次のとおりです。
- 公開鍵と秘密鍵のペアを生成します
- 公開鍵、アプリケーション名、クライアント ID、要求するスコープを指定して
/user-api-key/new経由で認証を要求します - ユーザーが要求を承認します(必要に応じてログイン後に承認します)
- Discourse がユーザー API キーを含む暗号化されたペイロードを返します
- 秘密鍵を使って復号し、設定でキーを使用します
サイトで有効になっている場合は、Discourse の UI からユーザー API キーを手動で作成することもできます。
- ユーザー設定 → セキュリティ → API にアクセスします
- または、ユーザー API キーのフローを実装したサードパーティ製ツールを使用します
FAQ
create_postが見つからないのはなぜですか? 読み取り専用モードになっています。前述の説明に従って書き込みを有効にしてください。- リモートツールの検出を無効にできますか? はい、
--tools_mode=discourse_api_onlyを指定して実行してください。 discourse_select_siteを公開せずに済みますか? はい、--site <url>を指定して起動すると、単一のサイトに固定できます。- タイムアウトやレート制限が発生します。
--timeout_msを増やしてください。また、429/5xx では組み込みの再試行/バックオフが行われることに注意してください。 - Admin API Keys と User API Keys のどちらを使うべきですか? 個人利用には User API Keys を使用してください(管理者権限は不要です)。管理者レベルの操作が必要な場合、またはシステム全体に適用されるインテグレーションを設定する場合に限り、Admin API Keys を使用してください。
- 「fetch failed」エラーが発生します。
--log_level debugを指定して実行すると、次の情報を含む詳細なエラー情報を確認できます。- リクエスト先の正確な URL
- HTTP ステータスコードとレスポンス本文
- ネットワークレベルのエラー(DNS、SSL/TLS、接続の問題)
- 再試行の回数とタイミング
- タイムアウトの診断情報
コメント
AI アプリケーションが外部のツールやデータソースに統一的な方法で接続するためのオープンなプロトコルです。クライアントはモデルとの対話を担い、MCP サーバーはツール・リソース・プロンプトテンプレートを提供します。標準メッセージでやり取りするため、1 つのサーバーを複数のクライアントで再利用できます。