mcpField
D
discourse-mcp-extended

discourse-mcp-extended

ローカル
github.com/devzspyソーシャルメディア016 週間前に更新

discourse-mcp-extended について

discourse-mcp-extendedは、discourse/discourse-mcpを基にしたMCPサーバーで、Discourseフォーラム向けのツールとリソースにレビューキュー操作を追加しています。フォーラム情報の確認や保留中・フラグ付き項目の処理を行うAIエージェント向けで、書き込みは既定で無効です。

主な機能

  1. 01Discourseフォーラム情報の読み取り
  2. 02カテゴリ、タグ、グループのリソース提供
  3. 03レビューキュー項目の一覧表示
  4. 04レビュー項目の承認または却下
  5. 05サイト選択と認証設定
  6. 06書き込みツールの明示的な有効化

活用シーン

  1. 01フォーラムのトピックや投稿の検索
  2. 02カテゴリ、タグ、グループの確認
  3. 03保留中またはフラグ付きコンテンツの確認
  4. 04レビューキュー項目への対応

MCP 対応

MCPを通じて、Discourseのツールと読み取り専用リソースをAIエージェントに提供します。既定のstdioに加えてStreamable HTTPにも対応し、レビューなどの書き込みツールは書き込みを有効にした場合だけ登録されます。

設定

ローカルサーバーの設定はどのクライアントでも共通です。コピーしてクライアントの MCP 設定ファイルに貼り付けてください。

mcp.json · 共通設定
{
"mcpServers": {
"devzspy-discourse-mcp-extended": {
"command": "npx",
"args": [
"-y",
"@devzspy/discourse-mcp-extended"
]
}
}
}
起動コマンドnpx -y @devzspy/discourse-mcp-extended

ローカルサーバーにはマシン上の実行環境(Node.js 18 以上など)が必要です。設定ファイルの場所はクライアントごとに異なります。

パッケージ
npm@devzspy/discourse-mcp-extended0.1.0

ツール

13

掲載時のツール一覧 · 2 週間前に更新

パラメーター型必須説明
sitestringはい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 の設定が必要です(セキュリティ上、任意のファイルの読み取りを防止します)
    • 注:投稿に画像を埋め込むには 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
  • テストに関する注意事項

    • テストは、コンパイル済み成果物(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 種類のキーをサポートしています。

  1. 管理者 API キー(api_key + api_username)

    • 生成には管理者/モデレーター権限が必要です
    • 管理画面 → API → 新しい API キーから作成します
    • ユーザー/カテゴリの作成を含むすべての操作を実行できます
    • ヘッダーには Api-Key と Api-Username を使用します
  2. ユーザー 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

このコマンドは次の処理を行います。

  1. RSA キーペアを生成します
  2. アクセスする認証 URL を表示します
  3. 認証後、暗号化されたペイロードを貼り付けるよう促します
  4. ペイロードを復号して、ユーザー API キーを表示します
  5. 必要に応じて、プロファイルファイルに保存します
手動で行う方法

ユーザー API キーには、https://meta.discourse.org/t/user-api-keys-specification/48536 に記載されている OAuth に似たフローが必要です。主な手順は次のとおりです。

  1. 公開鍵と秘密鍵のペアを生成します
  2. 公開鍵、アプリケーション名、クライアント ID、要求するスコープを指定して /user-api-key/new 経由で認証を要求します
  3. ユーザーが要求を承認します(必要に応じてログイン後に承認します)
  4. Discourse がユーザー API キーを含む暗号化されたペイロードを返します
  5. 秘密鍵を使って復号し、設定でキーを使用します

サイトで有効になっている場合は、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、接続の問題)
    • 再試行の回数とタイミング
    • タイムアウトの診断情報

コメント

MCP は初めてですか?

プロトコルの概要から最初のサーバーの導入まで、よくある疑問にまとめて答えます。

AI アプリケーションが外部のツールやデータソースに統一的な方法で接続するためのオープンなプロトコルです。クライアントはモデルとの対話を担い、MCP サーバーはツール・リソース・プロンプトテンプレートを提供します。標準メッセージでやり取りするため、1 つのサーバーを複数のクライアントで再利用できます。