Discourse MCP
Exposes Discourse forum capabilities, allowing AI agents to search content, read topics and posts, manage categories and tags, interact with chat channels, and create or manage posts, topics, users, and drafts.
Discourse MCP
A Model Context Protocol (MCP) stdio server that exposes Discourse forum capabilities as tools for AI agents.
Entry point:
src/index.ts→ compiled todist/index.js(binary name:discourse-mcp)SDK:
@modelcontextprotocol/sdkNode: >= 18
Quick start (release)
Run (read‑only, recommended to start)
npx -y @discourse/mcp@latestThen, in your MCP client, either:
Call the
discourse_select_sitetool with{ "site": "https://try.discourse.org" }to choose a site, orStart the server tethered to a site using
--site https://try.discourse.org(in which casediscourse_select_siteis hidden).Enable writes (opt‑in, safe‑guarded)
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"}]'Use in an MCP client (example: Claude Desktop) — via npx
{
"mcpServers": {
"discourse": {
"command": "npx",
"args": ["-y", "@discourse/mcp@latest"],
"env": {}
}
}
}Alternative: if you prefer a global binary after install, the package exposes
discourse-mcp.{ "mcpServers": { "discourse": { "command": "discourse-mcp", "args": [] } } }
Related MCP server: Discord Community MCP
Configuration
The server registers tools under the MCP server name @discourse/mcp. Choose a target Discourse site either by:
Using the
discourse_select_sitetool at runtime (validates via/about.json), orSupplying
--site <url>to tether the server to a single site at startup (validates via/about.jsonand hidesdiscourse_select_site).Auth
None by default.
Admin API Keys (require admin permissions):
--auth_pairs '[{"site":"https://example.com","api_key":"...","api_username":"system"}]'User API Keys (any user can generate):
--auth_pairs '[{"site":"https://example.com","user_api_key":"...","user_api_client_id":"..."}]'You can include multiple entries in
auth_pairs; the matching entry is used for the selected site. If bothuser_api_keyandapi_keyare provided for the same site,user_api_keytakes precedence.
Write safety
Writes are disabled by default.
The tools
discourse_create_post,discourse_create_topic,discourse_create_category, anddiscourse_create_userare only registered when all are true:--allow_writesAND not--read_onlyAND some auth is configured (either default flags or a matchingauth_pairsentry).
A ~1 req/sec rate limit is enforced for write actions.
Flags & defaults
--read_only(default: true)--allow_writes(default: false)--timeout_ms <number>(default: 15000)--concurrency <number>(default: 4)--log_level <silent|error|info|debug>(default: info)debug: Shows all HTTP requests, responses, and detailed error informationinfo: Shows retry attempts and general operational messageserror: Shows only errorssilent: No logging output
--tools_mode <auto|discourse_api_only|tool_exec_api>(default: auto)--site <url>: Tether MCP to a single site and hidediscourse_select_site.--default-search <prefix>: Unconditionally prefix every search query (e.g.,tag:ai order:latest).--max-read-length <number>: Maximum characters returned for post content (default 50000). Applies todiscourse_read_postand per-post content indiscourse_read_topic. The tools preferrawcontent by requestinginclude_raw=true.--transport <stdio|http>(default: stdio): Transport type. Usestdiofor standard input/output (default), orhttpfor Streamable HTTP transport (stateless mode with JSON responses).--port <number>(default: 3000): Port to listen on when using HTTP transport.--cache_dir <path>(reserved)--profile <path.json>(see below)
Profile file (keep secrets off the command line)
{
"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>" }
],
"read_only": false,
"allow_writes": 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
}Run with:
node dist/index.js --profile /absolute/path/to/profile.jsonFlags still override values from the profile.
Remote Tool Execution API (optional)
With
tools_mode=auto(default) ortool_exec_api, the server discovers remote tools via GET/ai/toolsafter you select a site (or immediately at startup if--siteis provided) and registers them dynamically. Set--tools_mode=discourse_api_onlyto disable remote tool discovery.
Networking & resilience
Retries on 429/5xx with backoff (3 attempts).
Lightweight in‑memory GET cache for selected endpoints.
Privacy
Secrets are redacted in logs. Errors are returned as human‑readable messages to MCP clients.
Tools
Built‑in tools (always present unless noted):
discourse_searchInput:
{ query: string; with_private?: boolean; max_results?: number (1–50, default 10) }Output: text summary plus a compact footer like:
{ "results": [{ "id": 123, "url": "https://…", "title": "…" }] }
discourse_read_topicInput:
{ topic_id: number; post_limit?: number (1–20, default 5) }
discourse_read_postInput:
{ post_id: number }
discourse_list_categoriesInput:
{}
discourse_list_tagsInput:
{}
discourse_get_userInput:
{ username: string }
discourse_filter_topicsInput:
{ filter: string; page?: number (default 1); per_page?: number (1–50) }Query language (succinct): key:value tokens separated by spaces; category/categories (comma = OR,
=category= without subcats,-prefix = exclude); tag/tags (comma = OR,+= AND) and tag_group; status:(open|closed|archived|listed|unlisted|public); personalin:(bookmarked|watching|tracking|muted|pinned); dates: created/activity/latest-post-(before|after) withYYYY-MM-DDor relative daysN; numeric: likes[-op]-(min|max), posts-(min|max), posters-(min|max), views-(min|max); order: activity|created|latest-post|likes|likes-op|posters|title|views|category with optional-asc; free text terms are matched.
discourse_list_chat_channelsInput:
{ filter?: string; limit?: number (1–100, default 25); offset?: number (default 0); status?: string }List all public chat channels visible to the current user. Returns channel information including title, description, and member counts.
discourse_list_user_chat_channelsInput:
{}List all chat channels for the currently authenticated user, including both public channels they're a member of and direct message channels. Includes unread tracking information.
discourse_get_chat_messagesInput:
{ channel_id: number; page_size?: number (1–500, default 50); target_message_id?: number; direction?: "past" | "future"; target_date?: string (ISO 8601); fetch_from_last_read?: boolean; include_target_message_id?: boolean }Get messages from a chat channel with flexible pagination and date-based filtering. Supports: (1) paginating with direction='past'/'future' from a target_message_id, (2) querying messages around a specific target_date, (3) getting messages around a target_message_id, or (4) fetching from last read position.
discourse_list_draftsInput:
{ offset?: number }List all drafts for the current user. Returns draft keys, sequences, and preview content.
discourse_get_draftInput:
{ draft_key: string; sequence?: number }Retrieve a specific draft by its key. Common keys:
"new_topic"for new topic drafts,"topic_<id>"for reply drafts.
discourse_save_draft(only when writes enabled; see Write safety)Input:
{ draft_key: string; reply: string; title?: string; category_id?: number; tags?: string[]; sequence?: number (default 0); action?: "createTopic" | "reply" | "edit" | "privateMessage" }Create a draft topic, create a draft reply, or update an existing draft. Use
draft_key="new_topic"for new topics,"topic_<id>"for replies. Returns the new sequence number for subsequent updates.
discourse_delete_draft(only when writes enabled; see Write safety)Input:
{ draft_key: string; sequence: number }Delete a draft by its key. Requires the current sequence number from list/get operations.
discourse_create_post(only when writes enabled; see Write safety)Input:
{ topic_id: number; raw: string (≤ 30k chars) }
discourse_create_topic(only when writes enabled; see Write safety)Input:
{ title: string; raw: string (≤ 30k chars); category_id?: number; tags?: string[] }
discourse_create_user(only when writes enabled; see Write safety)Input:
{ username: string (1-20 chars); email: string; name: string; password: string; active?: boolean; approved?: boolean }discourse_create_category(only when writes enabled; see Write safety)Input:
{ name: string; color?: hex; text_color?: hex; parent_category_id?: number; description?: string }
Notes:
Outputs are human‑readable first. Where applicable, a compact JSON is embedded in fenced code blocks to ease structured extraction by agents.
Development
Requirements: Node >= 18,
pnpm.Install / Build / Typecheck / Test
pnpm install
pnpm typecheck
pnpm build
pnpm testRun locally (with source maps)
pnpm build && pnpm devProject layout
Server & CLI:
src/index.tsHTTP client:
src/http/client.tsTool registry:
src/tools/registry.tsBuilt‑in tools:
src/tools/builtin/*Remote tools:
src/tools/remote/tool_exec_api.tsLogging/redaction:
src/util/logger.ts,src/util/redact.ts
Testing notes
Tests run with Node’s test runner against compiled artifacts (
dist/test/**/*.js). Ensurepnpm buildbeforepnpm testif invoking scripts individually.
Publishing (optional)
The package is published as
@discourse/mcpand exposes abinnameddiscourse-mcp. Prefernpx @discourse/mcp@latestfor frictionless usage.
Conventions
Focus on text‑oriented outputs; keep embedded JSON concise.
Be careful with write operations; keep them opt‑in and rate‑limited.
See AGENTS.md for additional guidance on using this server from agent frameworks.
Examples
Quick Start with User API Key (No Admin Required)
# 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=falseOther Examples
Read‑only session against
try.discourse.org:
npx -y @discourse/mcp@latest --log_level debug
# In client: call discourse_select_site with {"site":"https://try.discourse.org"}Tether to a single site:
npx -y @discourse/mcp@latest --site https://try.discourse.orgCreate a post with Admin API Key (writes enabled):
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"}]'Create a post with User API Key (writes enabled, no admin required):
npx -y @discourse/mcp@latest --allow_writes --read_only=false --auth_pairs '[{"site":"https://try.discourse.org","user_api_key":"'$DISCOURSE_USER_API_KEY'"}]'Create a category (writes enabled):
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" }Create a topic (writes enabled):
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"] }Run with HTTP transport (on port 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/mcpAuthentication
Admin API Keys vs User API Keys
This MCP server supports two types of Discourse API authentication:
Admin API Keys (
api_key+api_username)Require admin/moderator permissions to generate
Created via Admin Panel → API → New API Key
Can perform all operations including user/category creation
Use headers:
Api-KeyandApi-Username
User API Keys (
user_api_key+ optionaluser_api_client_id)Can be generated by any user (no admin required)
User-specific permissions and rate limits
Ideal for personal use and non-admin operations
Use headers:
User-Api-KeyandUser-Api-Client-IdAuto-expire after 180 days of inactivity (configurable per site)
Learn more: https://meta.discourse.org/t/user-api-keys-specification/48536
Obtaining a User API Key
Easy Method: Built-in Generator (Recommended)
This package includes a convenient command to generate User API Keys:
# 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 --helpThe command will:
Generate an RSA key pair
Display an authorization URL for you to visit
Prompt you to paste the encrypted payload after authorization
Decrypt and display your User API Key
Optionally save it to a profile file
Manual Method
User API Keys require an OAuth-like flow documented at https://meta.discourse.org/t/user-api-keys-specification/48536. Key steps:
Generate a public/private key pair
Request authorization via
/user-api-key/newwith your public key, application name, client ID, and requested scopesUser approves the request (after login if needed)
Discourse returns an encrypted payload with the User API Key
Decrypt using your private key and use the key in your configuration
You can also manually create User API Keys via the Discourse UI (if enabled by the site):
Visit your user preferences → Security → API
Or use third-party tools that implement the User API Key flow
FAQ
Why is
create_postmissing? You're in read‑only mode. Enable writes as described above.Can I disable remote tool discovery? Yes, run with
--tools_mode=discourse_api_only.Can I avoid exposing
discourse_select_site? Yes, start with--site <url>to tether to a single site.Time outs or rate limits? Increase
--timeout_ms, and note built‑in retry/backoff on 429/5xx.Should I use Admin API Keys or User API Keys? Use User API Keys for personal use (no admin required). Use Admin API Keys only when you need admin-level operations or are setting up a system-wide integration.
Getting "fetch failed" errors? Run with
--log_level debugto see detailed error information including:The exact URL being requested
HTTP status codes and response bodies
Network-level errors (DNS, SSL/TLS, connectivity issues)
Retry attempts and timing
Timeout diagnostics
Available Tools
15 toolsdiscourse_filter_topicsFilter TopicsARead-onlyIdempotent
Filter topics with a concise query language: use key:value tokens separated by spaces; category/categories for categories (comma = OR, '=category' = without subcats, '-' prefix = exclude), tag/tags (comma = OR, '+' = AND) and tag_group; status:(open|closed|archived|listed|unlisted|public) and personal in:(bookmarked|watching|tracking|muted|pinned); dates: created/activity/latest-post-(before|after) with YYYY-MM-DD or N (days); numeric: likes[-op]-(min|max), posts-(min|max), posters-(min|max), views-(min|max); order: activity|created|latest-post|likes|likes-op|posters|title|views|category with optional -asc; free text terms are matched full-text. Results are permission-aware.
Inputs: filter (required), page, per_page.
discourse_get_chat_messagesGet Chat MessagesARead-onlyIdempotent
Get messages from a chat channel with flexible pagination and date-based filtering. Supports: (1) paginating with direction='past'/'future' from a target_message_id, (2) querying messages around a specific target_date, (3) getting messages around a target_message_id, or (4) fetching from last read position.
Inputs: channel_id (required), page_size, target_message_id, direction, +3 more.
discourse_get_draftGet DraftARead-onlyIdempotent
Retrieve a specific draft by its key. Common keys: "new_topic" for new topic drafts, "topic_" for reply drafts.
Inputs: draft_key (required), sequence.
discourse_get_userGet UserARead-onlyIdempotent
Get information about a Discourse user by username. Returns name, trust level, join date, bio, and profile link.
Inputs: username (required).
discourse_list_categoriesList CategoriesARead-onlyIdempotent
List all categories visible to the current user. Returns category names and topic counts. Useful for discovering where to post or search.
Inputs: no named parameters.
discourse_list_chat_channelsList Chat ChannelsARead-onlyIdempotent
List all public chat channels visible to the current user. Returns channel information including title, description, and member counts. Supports filtering and pagination.
Inputs: filter, limit, offset, status.
discourse_list_draftsList DraftsARead-onlyIdempotent
List all drafts for the current user. Returns draft keys, sequences, and preview content. Use this to find existing drafts before updating them.
Inputs: offset.
discourse_list_tagsList TagsARead-onlyIdempotent
List all available tags on the Discourse site (if tagging is enabled). Returns tag names and usage counts. Use tags in search queries with #tagname.
Inputs: no named parameters.
discourse_list_user_chat_channelsList User's Chat ChannelsARead-onlyIdempotent
List all chat channels for the currently authenticated user, including both public channels they're a member of and direct message channels. Includes unread tracking information.
Inputs: no named parameters.
discourse_list_user_postsList User PostsARead-onlyIdempotent
Get a paginated list of posts and replies by a specific user, with the most recent first. Returns 30 posts per page. Includes topic title, post date, excerpt, and direct links.
Inputs: username (required), page.
discourse_read_postRead PostARead-onlyIdempotent
Read a specific post by its ID. Returns the post content, author, creation date, and link to the post.
Inputs: post_id (required).
discourse_read_topicRead TopicARead-onlyIdempotent
Read a Discourse topic including its metadata (title, category, tags) and posts. Supports pagination for long topics.
Inputs: topic_id (required), post_limit, start_post_number.
discourse_searchSearch DiscourseARead-onlyIdempotent
Search Discourse site content including topics, posts, and users. Use search operators like @username, #tag, category:name for filtered results.
Inputs: query (required), with_private, max_results.
discourse_select_siteSelect SiteARead-onlyIdempotent
Validate and select a Discourse site for subsequent tool calls. Verifies the site is reachable and retrieves its title. Must be called before using other tools when multiple sites are configured.
Inputs: site (required).
search_discourse_communitiesSearch Discourse CommunitiesARead-onlyIdempotent
Discover Discourse forum communities by topic or find similar communities. Use 'query' for semantic text search (e.g., 'note taking productivity') or 'similar_to' to find communities similar to a known one by URL or ID. Provide exactly one of 'query' or 'similar_to'. Returns communities with confidence scores and engagement metrics.
Inputs: query, similar_to, limit, min_users, +2 more.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 15 tools
Most tools have distinct purposes targeting specific resources like topics, posts, users, chats, or drafts, with clear boundaries. However, discourse_filter_topics and discourse_search have some functional overlap in querying content, which could cause minor confusion for agents about which to use for topic filtering versus general search.
Tool names follow a highly consistent snake_case pattern with a 'discourse_' prefix for most tools, using clear verb_noun combinations (e.g., discourse_list_categories, discourse_get_user). The single exception, search_discourse_communities, still maintains readability and a similar structure, not detracting from overall consistency.
With 15 tools, the server is well-scoped for a Discourse forum management system, covering key areas like content browsing, user management, chat, drafts, and site selection. Each tool serves a specific, non-redundant function, making the count appropriate for the domain without being overwhelming.
The toolset provides comprehensive coverage for reading, searching, and listing operations across topics, posts, users, chats, and drafts, with good support for filtering and pagination. A minor gap exists in write operations (e.g., creating or updating content like posts or topics), which agents might need to work around, but core workflows are well-supported.
Related MCP Connectors
Real-time forum discussions, subreddit threads, comments & tech community search API for agents.
A public forum where AI agents browse, search, join, reply, and follow conversations.
Search & read a zh-TW Taiwan community forum (PTT-style); AI agents can register to post & comment.
Related MCP Servers
AlicenseAqualityCmaintenanceEnables AI agents to interact with Discourse forums through search, reading topics/posts, managing categories and users. Supports secure authentication and optional write operations with rate limiting.1421,085 npm80MIT- FlicenseNot gradedqualityCmaintenanceEnables AI agents to search and recall Discord conversations, analyze community activity, participation, and growth, and optionally send messages when writes are enabled.1-
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to interact directly with NodeBB forums by searching, reading, posting, editing, and moderating content through standard MCP transports with scoped permissions.9 npm1BSD 2-Clause "Simplified"
- AlicenseNot gradedqualityBmaintenanceEnables AI agents to read public forum threads, start discussions, and post replies via HTTP and JSON, with optional authenticated write access.MIT