A platform for community discussion. Free, open, simple.
DEV: Keep MCP required scopes with their implementations (#43736)
Natalie Tayc4ed156337c8
diff --git a/lib/discourse_mcp.rb b/lib/discourse_mcp.rbindex 7d2c1441db4..054124c36ff 100644--- a/lib/discourse_mcp.rb+++ b/lib/discourse_mcp.rb@@ -1,12 +1,23 @@# frozen_string_literal: truemodule DiscourseMcp+ module Scopes+ PROFILE_READ = "mcp:profile:read"+ PROFILE_WRITE = "mcp:profile:write"+ CONTENT_READ = "mcp:content:read"+ CONTENT_WRITE = "mcp:content:write"+ DRAFTS_READ = "mcp:drafts:read"+ DRAFTS_WRITE = "mcp:drafts:write"+ PRIVATE_MESSAGES_READ = "mcp:private-messages:read"+ PRIVATE_MESSAGES_WRITE = "mcp:private-messages:write"+ end+PROTOCOL_VERSION = "2026-07-28"LEGACY_PROTOCOL_VERSION = "2025-11-25"SUPPORTED_PROTOCOL_VERSIONS = [PROTOCOL_VERSION, LEGACY_PROTOCOL_VERSION].freezeJSONRPC_VERSION = "2.0"SERVER_NAME = "discourse"- INITIAL_SCOPE = "mcp:profile:read"+ INITIAL_SCOPE = Scopes::PROFILE_READclass Error < StandardErrorattr_reader :code, :data, :http_status, :headersdiff --git a/lib/discourse_mcp/core_primitives.rb b/lib/discourse_mcp/core_primitives.rbindex 3a13d8d37b9..df3c82369ca 100644--- a/lib/discourse_mcp/core_primitives.rb+++ b/lib/discourse_mcp/core_primitives.rb@@ -38,6 +38,25 @@ module DiscourseMcpidentifier,implementation:,output_schema: implementation::OUTPUT_SCHEMA,+ required_scopes: implementation::REQUIRED_SCOPES,+ **attributes,+ )+ end++ def register_resource_template(registry, identifier, implementation:, **attributes)+ registry.register_resource_template(+ identifier,+ implementation:,+ required_scopes: implementation::REQUIRED_SCOPES,+ **attributes,+ )+ end++ def register_prompt(registry, identifier, implementation:, **attributes)+ registry.register_prompt(+ identifier,+ implementation:,+ required_scopes: implementation::REQUIRED_SCOPES,**attributes,)end@@ -58,7 +77,6 @@ module DiscourseMcpdescription:"Returns the authenticated Discourse user, granted scopes, and MCP server URI.",implementation: Tools::CurrentUser,- required_scopes: [DiscourseMcp::INITIAL_SCOPE],annotations: READ_ONLY,)register_tool(@@ -85,7 +103,6 @@ module DiscourseMcp},required: %w[query],),- required_scopes: %w[mcp:content:read],annotations: READ_ONLY,)register_tool(@@ -126,7 +143,6 @@ module DiscourseMcp},},),- required_scopes: %w[mcp:content:read],annotations: READ_ONLY,)register_tool(@@ -155,7 +171,6 @@ module DiscourseMcp},required: %w[query],),- required_scopes: %w[mcp:content:read],annotations: READ_ONLY,)register_tool(@@ -212,7 +227,6 @@ module DiscourseMcp},required: %w[topic_id selection_mode],),- required_scopes: %w[mcp:content:read],annotations: READ_ONLY,)register_tool(@@ -243,7 +257,6 @@ module DiscourseMcp},required: %w[post_id],),- required_scopes: %w[mcp:content:read],annotations: READ_ONLY,)register_tool(@@ -258,7 +271,6 @@ module DiscourseMcpobject_schema({ before_post_id: { type: "integer", minimum: 1 }, replies_only: { type: "boolean" } },),- required_scopes: %w[mcp:content:read],annotations: READ_ONLY,)register_tool(@@ -287,7 +299,6 @@ module DiscourseMcp},required: %w[topic_id],),- required_scopes: %w[mcp:content:read],annotations: READ_ONLY,)register_tool(@@ -353,7 +364,6 @@ module DiscourseMcp},required: %w[period],),- required_scopes: %w[mcp:content:read],annotations: READ_ONLY,)register_tool(@@ -382,7 +392,6 @@ module DiscourseMcp},required: %w[topic_id],),- required_scopes: %w[mcp:content:read],annotations: READ_ONLY,)register_tool(@@ -393,7 +402,6 @@ module DiscourseMcpimplementation: Tools::GetPost,input_schema:object_schema({ post_id: { type: "integer", minimum: 1 } }, required: %w[post_id]),- required_scopes: %w[mcp:content:read],annotations: READ_ONLY,)register_tool(@@ -403,7 +411,6 @@ module DiscourseMcpdescription: "Lists recent topics visible to the authenticated user.",implementation: Tools::ListTopics,input_schema: object_schema({ limit: { type: "integer", minimum: 1, maximum: 50 } }),- required_scopes: %w[mcp:content:read],annotations: READ_ONLY,)register_tool(@@ -412,7 +419,6 @@ module DiscourseMcptitle: "List categories",description: "Lists the visible category hierarchy.",implementation: Tools::ListCategories,- required_scopes: %w[mcp:content:read],annotations: READ_ONLY,)register_tool(@@ -422,7 +428,6 @@ module DiscourseMcpdescription: "Lists visible tags ordered by usage.",implementation: Tools::ListTags,input_schema: object_schema({ limit: { type: "integer", minimum: 1, maximum: 200 } }),- required_scopes: %w[mcp:content:read],annotations: READ_ONLY,)register_tool(@@ -436,7 +441,6 @@ module DiscourseMcp{ username: { type: "string", minLength: 1, maxLength: 60 } },required: %w[username],),- required_scopes: %w[mcp:content:read],annotations: READ_ONLY,)register_tool(@@ -465,7 +469,6 @@ module DiscourseMcp},required: %w[username],),- required_scopes: %w[mcp:content:read],annotations: READ_ONLY,)register_tool(@@ -479,7 +482,6 @@ module DiscourseMcp{ username: { type: "string", minLength: 1, maxLength: 60 } },required: %w[username],),- required_scopes: %w[mcp:content:read],annotations: READ_ONLY,)register_tool(@@ -522,7 +524,6 @@ module DiscourseMcp},required: %w[username],),- required_scopes: %w[mcp:content:read],annotations: READ_ONLY,)register_tool(@@ -546,7 +547,6 @@ module DiscourseMcp},required: %w[draft_key],),- required_scopes: %w[mcp:drafts:read],annotations: READ_ONLY,)register_tool(@@ -556,7 +556,6 @@ module DiscourseMcpdescription: "Lists the authenticated user's bookmarks.",implementation: Tools::ListBookmarks,input_schema: object_schema({ limit: { type: "integer", minimum: 1, maximum: 100 } }),- required_scopes: %w[mcp:content:read],annotations: READ_ONLY,)register_tool(@@ -566,7 +565,6 @@ module DiscourseMcpdescription: "Lists the authenticated user's notifications.",implementation: Tools::ListNotifications,input_schema: object_schema({ limit: { type: "integer", minimum: 1, maximum: 100 } }),- required_scopes: %w[mcp:content:read],annotations: READ_ONLY,)register_tool(@@ -606,7 +604,6 @@ module DiscourseMcp},},),- required_scopes: %w[mcp:private-messages:read],annotations: READ_ONLY,)register_tool(@@ -635,7 +632,6 @@ module DiscourseMcp},required: %w[topic_id],),- required_scopes: %w[mcp:private-messages:read],annotations: READ_ONLY,)end@@ -678,7 +674,6 @@ module DiscourseMcp},required: %w[title raw],),- required_scopes: %w[mcp:content:write],annotations: WRITE,risk: :write,)@@ -712,7 +707,6 @@ module DiscourseMcp},required: %w[topic_id raw],),- required_scopes: %w[mcp:content:write],annotations: WRITE,risk: :write,)@@ -741,7 +735,6 @@ module DiscourseMcp},required: %w[post_id raw],),- required_scopes: %w[mcp:content:write],annotations: WRITE,risk: :write,)@@ -796,7 +789,6 @@ module DiscourseMcp},required: %w[topic_id],),- required_scopes: %w[mcp:content:write],annotations: WRITE,risk: :write,)@@ -857,7 +849,6 @@ module DiscourseMcp},required: %w[username],),- required_scopes: %w[mcp:profile:write],annotations: WRITE,risk: :write,)@@ -895,7 +886,6 @@ module DiscourseMcp},required: %w[upload_type],),- required_scopes: %w[mcp:content:write],annotations: EXTERNAL_SIDE_EFFECT,risk: :external_side_effect,)@@ -952,7 +942,6 @@ module DiscourseMcp},required: %w[title raw],),- required_scopes: %w[mcp:private-messages:write],annotations: EXTERNAL_SIDE_EFFECT,risk: :external_side_effect,)@@ -986,7 +975,6 @@ module DiscourseMcp},required: %w[topic_id raw],),- required_scopes: %w[mcp:private-messages:write],annotations: WRITE,risk: :write,)@@ -1034,7 +1022,6 @@ module DiscourseMcp},required: %w[topic_id],),- required_scopes: %w[mcp:private-messages:write],annotations: EXTERNAL_SIDE_EFFECT,risk: :external_side_effect,)@@ -1049,7 +1036,6 @@ module DiscourseMcp{ post_id: { type: "integer", minimum: 1 }, deleted: { type: "boolean" } },required: %w[post_id deleted],),- required_scopes: %w[mcp:content:write],annotations: DESTRUCTIVE,risk: :destructive,)@@ -1102,7 +1088,6 @@ module DiscourseMcp},required: %w[draft_key reply],),- required_scopes: %w[mcp:drafts:write],annotations: WRITE,risk: :write,)@@ -1127,7 +1112,6 @@ module DiscourseMcp},required: %w[draft_key sequence],),- required_scopes: %w[mcp:drafts:write],annotations: DESTRUCTIVE,risk: :destructive,)@@ -1162,7 +1146,6 @@ module DiscourseMcp{ properties: { clear: { enum: [false] } }, required: %w[description emoji] },],),- required_scopes: %w[mcp:content:write],annotations: WRITE,risk: :write,availability: -> { SiteSetting.enable_user_status },@@ -1170,7 +1153,8 @@ module DiscourseMcpenddef register_resources(registry)- registry.register_resource_template(+ register_resource_template(+ registry,"discourse.topic",title: "Discourse topic",description: "A topic visible to the authenticated user.",@@ -1180,10 +1164,10 @@ module DiscourseMcp{ uri: { type: "string", pattern: "\\Adiscourse://topic/[0-9]+\\z" } },required: %w[uri],),- required_scopes: %w[mcp:content:read],annotations: READ_ONLY,)- registry.register_resource_template(+ register_resource_template(+ registry,"discourse.post",title: "Discourse post",description: "A post visible to the authenticated user.",@@ -1193,13 +1177,13 @@ module DiscourseMcp{ uri: { type: "string", pattern: "\\Adiscourse://post/[0-9]+\\z" } },required: %w[uri],),- required_scopes: %w[mcp:content:read],annotations: READ_ONLY,)enddef register_prompts(registry)- registry.register_prompt(+ register_prompt(+ registry,"discourse.research_topic",title: "Research discussions",description: "Builds a prompt for researching visible Discourse discussions.",@@ -1209,10 +1193,10 @@ module DiscourseMcp{ question: { type: "string", minLength: 1, maxLength: 1000 } },required: %w[question],),- required_scopes: %w[mcp:content:read],annotations: READ_ONLY,)- registry.register_prompt(+ register_prompt(+ registry,"discourse.draft_reply",title: "Draft a reply",description: "Builds a prompt for drafting a grounded reply to a visible topic.",@@ -1231,7 +1215,6 @@ module DiscourseMcp},required: %w[topic_id],),- required_scopes: %w[mcp:content:read],annotations: READ_ONLY,)end@@ -1239,6 +1222,8 @@ module DiscourseMcpmodule Resourcesclass Topic+ REQUIRED_SCOPES = [Scopes::CONTENT_READ].freeze+def self.call(uri:, request_context:)id = uri.delete_prefix("discourse://topic/").to_itopic = ::Topic.find_by(id: id)@@ -1255,6 +1240,8 @@ module DiscourseMcpendclass Post+ REQUIRED_SCOPES = [Scopes::CONTENT_READ].freeze+def self.call(uri:, request_context:)id = uri.delete_prefix("discourse://post/").to_ipost = ::Post.secured(request_context.guardian).find_by(id: id)@@ -1269,6 +1256,8 @@ module DiscourseMcpmodule Promptsclass ResearchTopic+ REQUIRED_SCOPES = [Scopes::CONTENT_READ].freeze+def self.call(arguments:, request_context:){description: "Research visible Discourse discussions",@@ -1287,6 +1276,8 @@ module DiscourseMcpendclass DraftReply+ REQUIRED_SCOPES = [Scopes::CONTENT_READ].freeze+def self.call(arguments:, request_context:)topic = ::Topic.find_by(id: arguments.fetch("topic_id").to_i)if topic.blank? || !request_context.guardian.can_see?(topic)diff --git a/lib/discourse_mcp/tools/bookmarks.rb b/lib/discourse_mcp/tools/bookmarks.rbindex dd8dbf7ea86..fd349fdf396 100644--- a/lib/discourse_mcp/tools/bookmarks.rb+++ b/lib/discourse_mcp/tools/bookmarks.rb@@ -3,6 +3,7 @@module DiscourseMcpmodule Toolsclass ListBookmarks+ REQUIRED_SCOPES = [Scopes::CONTENT_READ].freezeOUTPUT_SCHEMA = OutputSchema.object(bookmarks: OutputSchema::OBJECT_ARRAY)def self.call(arguments:, request_context:)diff --git a/lib/discourse_mcp/tools/drafts.rb b/lib/discourse_mcp/tools/drafts.rbindex 1972ec091d3..f5feab79778 100644--- a/lib/discourse_mcp/tools/drafts.rb+++ b/lib/discourse_mcp/tools/drafts.rb@@ -3,6 +3,7 @@module DiscourseMcpmodule Toolsclass GetDraft+ REQUIRED_SCOPES = [Scopes::DRAFTS_READ].freezeOUTPUT_SCHEMA =OutputSchema.object(optional: %w[sequence data],@@ -58,6 +59,7 @@ module DiscourseMcpendclass SaveDraft+ REQUIRED_SCOPES = [Scopes::DRAFTS_WRITE].freezeOUTPUT_SCHEMA =OutputSchema.object(draft_key: OutputSchema::STRING,@@ -105,6 +107,7 @@ module DiscourseMcpendclass DeleteDraft+ REQUIRED_SCOPES = [Scopes::DRAFTS_WRITE].freezeOUTPUT_SCHEMA =OutputSchema.object(draft_key: OutputSchema::STRING, deleted: OutputSchema::BOOLEAN)diff --git a/lib/discourse_mcp/tools/notifications.rb b/lib/discourse_mcp/tools/notifications.rbindex 23003277317..b2a11de3ae9 100644--- a/lib/discourse_mcp/tools/notifications.rb+++ b/lib/discourse_mcp/tools/notifications.rb@@ -3,6 +3,7 @@module DiscourseMcpmodule Toolsclass ListNotifications+ REQUIRED_SCOPES = [Scopes::CONTENT_READ].freezeOUTPUT_SCHEMA = OutputSchema.object(notifications: OutputSchema::OBJECT_ARRAY)def self.call(arguments:, request_context:)@@ -14,7 +15,7 @@ module DiscourseMcp.includes(:topic).order(id: :desc).limit(limit)- if !request_context.has_scopes?("mcp:private-messages:read")+ if !request_context.has_scopes?(Scopes::PRIVATE_MESSAGES_READ)notifications =notifications.left_joins(:topic).where("topics.id IS NULL OR topics.archetype <> ?",diff --git a/lib/discourse_mcp/tools/private_messages.rb b/lib/discourse_mcp/tools/private_messages.rbindex f48c9681a57..273f2426231 100644--- a/lib/discourse_mcp/tools/private_messages.rb+++ b/lib/discourse_mcp/tools/private_messages.rb@@ -3,6 +3,7 @@module DiscourseMcpmodule Toolsclass ListPrivateMessages+ REQUIRED_SCOPES = [Scopes::PRIVATE_MESSAGES_READ].freezeMAILBOXES = %w[inbox sent archive unread new].freezeOUTPUT_SCHEMA =OutputSchema.object(@@ -140,6 +141,7 @@ module DiscourseMcpendclass ReadPrivateMessage+ REQUIRED_SCOPES = [Scopes::PRIVATE_MESSAGES_READ].freezeOUTPUT_SCHEMA =OutputSchema.object(topic_id: OutputSchema::INTEGER,@@ -212,6 +214,7 @@ module DiscourseMcpendclass CreatePrivateMessage+ REQUIRED_SCOPES = [Scopes::PRIVATE_MESSAGES_WRITE].freezeOUTPUT_SCHEMA =OutputSchema.object(id: OutputSchema::INTEGER,@@ -268,6 +271,7 @@ module DiscourseMcpendclass ReplyPrivateMessage+ REQUIRED_SCOPES = [Scopes::PRIVATE_MESSAGES_WRITE].freezeOUTPUT_SCHEMA =OutputSchema.object(id: OutputSchema::INTEGER,@@ -302,6 +306,7 @@ module DiscourseMcpendclass InviteToPrivateMessage+ REQUIRED_SCOPES = [Scopes::PRIVATE_MESSAGES_WRITE].freezeOUTPUT_SCHEMA =OutputSchema.object(optional: %w[group notifications_requested user participant_added outcome_confirmed],diff --git a/lib/discourse_mcp/tools/search.rb b/lib/discourse_mcp/tools/search.rbindex 61d69ac5ad9..dbf1daddc87 100644--- a/lib/discourse_mcp/tools/search.rb+++ b/lib/discourse_mcp/tools/search.rb@@ -3,6 +3,7 @@module DiscourseMcpmodule Toolsclass Search+ REQUIRED_SCOPES = [Scopes::CONTENT_READ].freezeOUTPUT_SCHEMA =OutputSchema.object(results: OutputSchema::OBJECT_ARRAY, meta: OutputSchema::OBJECT)@@ -13,7 +14,7 @@ module DiscourseMcp::Search.execute(query,guardian: request_context.guardian,- exclude_private_messages: !request_context.has_scopes?("mcp:private-messages:read"),+ exclude_private_messages: !request_context.has_scopes?(Scopes::PRIVATE_MESSAGES_READ),)topics = results.posts.filter_map(&:topic).uniq(&:id).first(limit + 1)has_more = topics.length > limit@@ -30,6 +31,7 @@ module DiscourseMcpclass FilterTopicsTOP_PERIODS = %w[daily weekly monthly quarterly yearly all].freeze+ REQUIRED_SCOPES = [Scopes::CONTENT_READ].freezeOUTPUT_SCHEMA =OutputSchema.object(results: OutputSchema::OBJECT_ARRAY, meta: OutputSchema::OBJECT)@@ -97,6 +99,7 @@ module DiscourseMcpendclass SearchPosts+ REQUIRED_SCOPES = [Scopes::CONTENT_READ].freezeOUTPUT_SCHEMA =OutputSchema.object(posts: OutputSchema::OBJECT_ARRAY,@@ -120,7 +123,7 @@ module DiscourseMcpsearch_type: :full_page,page:,blurb_length: 300,- exclude_private_messages: !request_context.has_scopes?("mcp:private-messages:read"),+ exclude_private_messages: !request_context.has_scopes?(Scopes::PRIVATE_MESSAGES_READ),)raise DiscourseMcp::ToolError, I18n.t("mcp.errors.invalid_search_query") if results.blank?diff --git a/lib/discourse_mcp/tools/topic_reads.rb b/lib/discourse_mcp/tools/topic_reads.rbindex 56fbe865e23..5b4d70683bb 100644--- a/lib/discourse_mcp/tools/topic_reads.rb+++ b/lib/discourse_mcp/tools/topic_reads.rb@@ -3,6 +3,7 @@module DiscourseMcpmodule Toolsclass ReadTopicPosts+ REQUIRED_SCOPES = [Scopes::CONTENT_READ].freezeSELECTION_KEYS = {"latest" => %w[limit replies_only],"earliest" => %w[limit replies_only],@@ -138,6 +139,7 @@ module DiscourseMcpendclass GetPostReplies+ REQUIRED_SCOPES = [Scopes::CONTENT_READ].freezeDIRECT_REPLIES_LIMIT = 20MODES = %w[reply_ids direct_replies reply_history].freezeOUTPUT_SCHEMA =@@ -254,6 +256,7 @@ module DiscourseMcpendclass ListLatestPosts+ REQUIRED_SCOPES = [Scopes::CONTENT_READ].freezeOUTPUT_SCHEMA =OutputSchema.object(posts: OutputSchema::OBJECT_ARRAY, meta: OutputSchema::OBJECT)@@ -298,6 +301,7 @@ module DiscourseMcpendclass GetTopicViewStats+ REQUIRED_SCOPES = [Scopes::CONTENT_READ].freezeOUTPUT_SCHEMA =OutputSchema.object(topic_id: OutputSchema::INTEGER,@@ -345,6 +349,7 @@ module DiscourseMcpendclass GetTopic+ REQUIRED_SCOPES = [Scopes::CONTENT_READ].freezeOUTPUT_SCHEMA =OutputSchema.object(id: OutputSchema::INTEGER,@@ -401,6 +406,7 @@ module DiscourseMcpendclass GetPost+ REQUIRED_SCOPES = [Scopes::CONTENT_READ].freezeOUTPUT_SCHEMA =OutputSchema.object(optional: %w[accepted_answer topic_accepted_answer],@@ -436,6 +442,7 @@ module DiscourseMcpendclass ListTopics+ REQUIRED_SCOPES = [Scopes::CONTENT_READ].freezeOUTPUT_SCHEMA = OutputSchema.object(topics: OutputSchema::OBJECT_ARRAY)def self.call(arguments:, request_context:)@@ -453,6 +460,7 @@ module DiscourseMcpendclass ListCategories+ REQUIRED_SCOPES = [Scopes::CONTENT_READ].freezeOUTPUT_SCHEMA = OutputSchema.object(categories: OutputSchema::OBJECT_ARRAY)def self.call(arguments:, request_context:)@@ -473,6 +481,7 @@ module DiscourseMcpendclass ListTags+ REQUIRED_SCOPES = [Scopes::CONTENT_READ].freezeOUTPUT_SCHEMA = OutputSchema.object(tags: OutputSchema::OBJECT_ARRAY)def self.call(arguments:, request_context:)diff --git a/lib/discourse_mcp/tools/topic_writes.rb b/lib/discourse_mcp/tools/topic_writes.rbindex 642df5c5e9d..dc455ffe358 100644--- a/lib/discourse_mcp/tools/topic_writes.rb+++ b/lib/discourse_mcp/tools/topic_writes.rb@@ -3,6 +3,7 @@module DiscourseMcpmodule Toolsclass CreateTopic+ REQUIRED_SCOPES = [Scopes::CONTENT_WRITE].freezeOUTPUT_SCHEMA =OutputSchema.object(id: OutputSchema::INTEGER,@@ -40,6 +41,7 @@ module DiscourseMcpendclass ReplyTopic+ REQUIRED_SCOPES = [Scopes::CONTENT_WRITE].freezeOUTPUT_SCHEMA =OutputSchema.object(id: OutputSchema::INTEGER,@@ -78,6 +80,7 @@ module DiscourseMcpendclass EditPost+ REQUIRED_SCOPES = [Scopes::CONTENT_WRITE].freezeOUTPUT_SCHEMA =OutputSchema.object(id: OutputSchema::INTEGER,@@ -112,6 +115,7 @@ module DiscourseMcpendclass UpdateTopic+ REQUIRED_SCOPES = [Scopes::CONTENT_WRITE].freezeMUTABLE_FIELDS = %w[title category_id tags featured_link].freezeOUTPUT_SCHEMA =OutputSchema.object(@@ -220,6 +224,7 @@ module DiscourseMcpendclass SetPostDeleted+ REQUIRED_SCOPES = [Scopes::CONTENT_WRITE].freezeOUTPUT_SCHEMA =OutputSchema.object(post_id: OutputSchema::INTEGER, deleted: OutputSchema::BOOLEAN)diff --git a/lib/discourse_mcp/tools/uploads.rb b/lib/discourse_mcp/tools/uploads.rbindex ca71d91734d..4cfbb742a11 100644--- a/lib/discourse_mcp/tools/uploads.rb+++ b/lib/discourse_mcp/tools/uploads.rb@@ -6,6 +6,7 @@ require "tempfile"module DiscourseMcpmodule Toolsclass UploadFile+ REQUIRED_SCOPES = [Scopes::CONTENT_WRITE].freezeUPLOAD_TYPES = %w[avatar profile_background card_background composer].freezeOUTPUT_SCHEMA =OutputSchema.object(diff --git a/lib/discourse_mcp/tools/users.rb b/lib/discourse_mcp/tools/users.rbindex 2a7efdbfc77..4022597aad3 100644--- a/lib/discourse_mcp/tools/users.rb+++ b/lib/discourse_mcp/tools/users.rb@@ -5,6 +5,7 @@ require "directory_items_query"module DiscourseMcpmodule Toolsclass CurrentUser+ REQUIRED_SCOPES = [DiscourseMcp::INITIAL_SCOPE].freezeOUTPUT_SCHEMA =OutputSchema.object(id: OutputSchema::INTEGER,@@ -33,6 +34,7 @@ module DiscourseMcpendclass ListDirectoryItems+ REQUIRED_SCOPES = [Scopes::CONTENT_READ].freezePAGE_SIZE = ::DirectoryItemsQuery::PAGE_SIZEPAGE_LIMIT = ::DirectoryItemsQuery::PAGE_LIMITOUTPUT_SCHEMA =@@ -118,6 +120,7 @@ module DiscourseMcpendclass GetUser+ REQUIRED_SCOPES = [Scopes::CONTENT_READ].freezeOUTPUT_SCHEMA =OutputSchema.object(id: OutputSchema::INTEGER,@@ -148,6 +151,7 @@ module DiscourseMcpendclass ListUserPosts+ REQUIRED_SCOPES = [Scopes::CONTENT_READ].freezeOUTPUT_SCHEMA =OutputSchema.object(posts: OutputSchema::OBJECT_ARRAY, meta: OutputSchema::OBJECT)@@ -178,6 +182,7 @@ module DiscourseMcpendclass GetUserSummary+ REQUIRED_SCOPES = [Scopes::CONTENT_READ].freezeMETRICS = %i[likes_givenlikes_received@@ -238,6 +243,7 @@ module DiscourseMcpendclass ListUserActions+ REQUIRED_SCOPES = [Scopes::CONTENT_READ].freezeACTION_TYPES = {"likes" => 1,"was_liked" => 2,@@ -286,7 +292,7 @@ module DiscourseMcpguardian:,ignore_private_messages:arguments["action_types"].blank? ||- !request_context.has_scopes?("mcp:private-messages:read"),+ !request_context.has_scopes?(Scopes::PRIVATE_MESSAGES_READ),acting_username: arguments["acting_username"],).to_ahas_more = actions.length > limit@@ -339,6 +345,7 @@ module DiscourseMcpendclass UpdateUser+ REQUIRED_SCOPES = [Scopes::PROFILE_WRITE].freezePROFILE_FIELDS = %w[namebio_raw@@ -431,6 +438,7 @@ module DiscourseMcpendclass SetUserStatus+ REQUIRED_SCOPES = [Scopes::CONTENT_WRITE].freezeOUTPUT_SCHEMA = OutputSchema.object(success: OutputSchema::BOOLEAN)def self.call(arguments:, request_context:)diff --git a/plugins/chat/lib/chat/mcp_tools.rb b/plugins/chat/lib/chat/mcp_tools.rbindex 3a5baaeefd6..91bdca64430 100644--- a/plugins/chat/lib/chat/mcp_tools.rb+++ b/plugins/chat/lib/chat/mcp_tools.rb@@ -3,6 +3,7 @@module Chatmodule McpToolsclass ListChannels+ REQUIRED_SCOPES = %w[chat:read].freezeOUTPUT_SCHEMA =DiscourseMcp::OutputSchema.object(channels: {@@ -35,6 +36,7 @@ module Chatendclass ListMessages+ REQUIRED_SCOPES = %w[chat:read].freezeOUTPUT_SCHEMA =DiscourseMcp::OutputSchema.object(channel_id: DiscourseMcp::OutputSchema::INTEGER,@@ -98,6 +100,7 @@ module Chatendclass CreateMessage+ REQUIRED_SCOPES = %w[chat:write].freezeOUTPUT_SCHEMA =DiscourseMcp::OutputSchema.object(id: DiscourseMcp::OutputSchema::INTEGER,diff --git a/plugins/chat/plugin.rb b/plugins/chat/plugin.rbindex 41b81c13898..5c70dec0ae0 100644--- a/plugins/chat/plugin.rb+++ b/plugins/chat/plugin.rb@@ -658,7 +658,7 @@ after_initialize do"Lists chat channels followed by the authenticated user, including direct-message channels.",implementation: Chat::McpTools::ListChannels,output_schema: Chat::McpTools::ListChannels::OUTPUT_SCHEMA,- required_scopes: %w[chat:read],+ required_scopes: Chat::McpTools::ListChannels::REQUIRED_SCOPES,annotations: {readOnlyHint: true,destructiveHint: false,@@ -700,7 +700,7 @@ after_initialize doadditionalProperties: false,},output_schema: Chat::McpTools::ListMessages::OUTPUT_SCHEMA,- required_scopes: %w[chat:read],+ required_scopes: Chat::McpTools::ListMessages::REQUIRED_SCOPES,annotations: {readOnlyHint: true,destructiveHint: false,@@ -734,7 +734,7 @@ after_initialize doadditionalProperties: false,},output_schema: Chat::McpTools::CreateMessage::OUTPUT_SCHEMA,- required_scopes: %w[chat:write],+ required_scopes: Chat::McpTools::CreateMessage::REQUIRED_SCOPES,annotations: {readOnlyHint: false,destructiveHint: false,diff --git a/plugins/discourse-events/lib/discourse_events/mcp_tools.rb b/plugins/discourse-events/lib/discourse_events/mcp_tools.rbindex 921df05df27..a4fbb03e9be 100644--- a/plugins/discourse-events/lib/discourse_events/mcp_tools.rb+++ b/plugins/discourse-events/lib/discourse_events/mcp_tools.rb@@ -3,6 +3,7 @@module DiscourseEventsmodule McpToolsclass ListEvents+ REQUIRED_SCOPES = %w[discourse-calendar:read].freezeOUTPUT_SCHEMA =DiscourseMcp::OutputSchema.object(events: {diff --git a/plugins/discourse-events/plugin.rb b/plugins/discourse-events/plugin.rbindex 7febc3f9e84..374b35ddbe7 100644--- a/plugins/discourse-events/plugin.rb+++ b/plugins/discourse-events/plugin.rb@@ -1098,7 +1098,7 @@ after_initialize doadditionalProperties: false,},output_schema: DiscourseEvents::McpTools::ListEvents::OUTPUT_SCHEMA,- required_scopes: %w[discourse-calendar:read],+ required_scopes: DiscourseEvents::McpTools::ListEvents::REQUIRED_SCOPES,annotations: {readOnlyHint: true,destructiveHint: false,diff --git a/plugins/discourse-reactions/lib/discourse_reactions/mcp_tools.rb b/plugins/discourse-reactions/lib/discourse_reactions/mcp_tools.rbindex 3ea2a7a6ea9..f4add8ed36b 100644--- a/plugins/discourse-reactions/lib/discourse_reactions/mcp_tools.rb+++ b/plugins/discourse-reactions/lib/discourse_reactions/mcp_tools.rb@@ -3,6 +3,7 @@module DiscourseReactionsmodule McpToolsclass SetReaction+ REQUIRED_SCOPES = %w[discourse-reactions:write].freezeOUTPUT_SCHEMA =DiscourseMcp::OutputSchema.object(post_id: DiscourseMcp::OutputSchema::INTEGER,diff --git a/plugins/discourse-reactions/plugin.rb b/plugins/discourse-reactions/plugin.rbindex 5d92a38ce4d..2b4452deb0e 100644--- a/plugins/discourse-reactions/plugin.rb+++ b/plugins/discourse-reactions/plugin.rb@@ -459,7 +459,7 @@ after_initialize doadditionalProperties: false,},output_schema: DiscourseReactions::McpTools::SetReaction::OUTPUT_SCHEMA,- required_scopes: %w[discourse-reactions:write],+ required_scopes: DiscourseReactions::McpTools::SetReaction::REQUIRED_SCOPES,annotations: {readOnlyHint: false,destructiveHint: false,diff --git a/plugins/discourse-solved/lib/discourse_solved/mcp_tools.rb b/plugins/discourse-solved/lib/discourse_solved/mcp_tools.rbindex fe32aa062d7..d5bd3232219 100644--- a/plugins/discourse-solved/lib/discourse_solved/mcp_tools.rb+++ b/plugins/discourse-solved/lib/discourse_solved/mcp_tools.rb@@ -3,6 +3,7 @@module DiscourseSolvedmodule McpToolsclass SetSolution+ REQUIRED_SCOPES = %w[discourse-solved:write].freezeOUTPUT_SCHEMA =DiscourseMcp::OutputSchema.object(post_id: DiscourseMcp::OutputSchema::INTEGER,diff --git a/plugins/discourse-solved/plugin.rb b/plugins/discourse-solved/plugin.rbindex 8810a5e6553..9ce832d20f9 100644--- a/plugins/discourse-solved/plugin.rb+++ b/plugins/discourse-solved/plugin.rb@@ -506,7 +506,7 @@ after_initialize doadditionalProperties: false,},output_schema: DiscourseSolved::McpTools::SetSolution::OUTPUT_SCHEMA,- required_scopes: %w[discourse-solved:write],+ required_scopes: DiscourseSolved::McpTools::SetSolution::REQUIRED_SCOPES,annotations: {readOnlyHint: false,destructiveHint: false,diff --git a/plugins/discourse-topic-voting/lib/discourse_topic_voting/mcp_tools.rb b/plugins/discourse-topic-voting/lib/discourse_topic_voting/mcp_tools.rbindex ded92ed3971..12eab6df5fa 100644--- a/plugins/discourse-topic-voting/lib/discourse_topic_voting/mcp_tools.rb+++ b/plugins/discourse-topic-voting/lib/discourse_topic_voting/mcp_tools.rb@@ -3,6 +3,7 @@module DiscourseTopicVotingmodule McpToolsclass SetVote+ REQUIRED_SCOPES = %w[discourse-topic-voting:write].freezeOUTPUT_SCHEMA =DiscourseMcp::OutputSchema.object(topic_id: DiscourseMcp::OutputSchema::INTEGER,diff --git a/plugins/discourse-topic-voting/plugin.rb b/plugins/discourse-topic-voting/plugin.rbindex 6b34883afab..04f770f885d 100755--- a/plugins/discourse-topic-voting/plugin.rb+++ b/plugins/discourse-topic-voting/plugin.rb@@ -276,7 +276,7 @@ after_initialize doadditionalProperties: false,},output_schema: DiscourseTopicVoting::McpTools::SetVote::OUTPUT_SCHEMA,- required_scopes: %w[discourse-topic-voting:write],+ required_scopes: DiscourseTopicVoting::McpTools::SetVote::REQUIRED_SCOPES,annotations: {readOnlyHint: false,destructiveHint: false,diff --git a/spec/lib/discourse_mcp/regular_user_tools_spec.rb b/spec/lib/discourse_mcp/regular_user_tools_spec.rbindex 26116ffafe1..41abfb6cdc6 100644--- a/spec/lib/discourse_mcp/regular_user_tools_spec.rb+++ b/spec/lib/discourse_mcp/regular_user_tools_spec.rb@@ -240,7 +240,9 @@ describe DiscourseMcp::Tools doFabricate(:topic, category: Fabricate(:private_category, group: Fabricate(:group)))hidden_notification = Fabricate(:notification, user:, topic: private_topic)context = request_context(user)- allow(context).to receive(:has_scopes?).with("mcp:private-messages:read").and_return(true)+ allow(context).to receive(:has_scopes?).with(+ DiscourseMcp::Scopes::PRIVATE_MESSAGES_READ,+ ).and_return(true)result =described_class.call(arguments: {}, request_context: context).fetch(:structuredContent)@@ -764,6 +766,16 @@ describe DiscourseMcp::CorePrimitives doexpect(tools_without_output_schema).to be_emptyend+ it "registers every primitive with the scopes declared by its implementation" do+ primitives_with_different_scopes =+ DiscourseMcp.registry.all.reject do |primitive|+ primitive.implementation.const_defined?(:REQUIRED_SCOPES, false) &&+ primitive.required_scopes == primitive.implementation::REQUIRED_SCOPES+ end++ expect(primitives_with_different_scopes.map(&:identifier)).to be_empty+ end+it "registers the compatible regular-user tool names" doexpected_names = %w[discourse_create_post