# Add plugin data to native MCP topics

**URL:** <https://meta.discourse.org/t/add-plugin-data-to-native-mcp-topics/418891>\
**Category:** Developer Guides\
**Created:** [December 2, 2026, 3:19pm UTC](https://meta.discourse.org/t/add-plugin-data-to-native-mcp-topics/418891 "2026-12-02T15:19:41Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)\
**Post date:** [December 2, 2026, 3:19pm UTC](https://meta.discourse.org/t/add-plugin-data-to-native-mcp-topics/418891/1 "2026-12-02T15:19:41Z")

</div>

The `mcp_topic_plugin_data` modifier adds plugin-owned data to `discourse_read_topic`  
and `discourse_filter_topics`. It runs once for each returned topic batch.

The modifier receives three arguments:

- `data`: a hash keyed by integer topic ID. Each value is a hash keyed by plugin name.
- `topics`: the array of topics that the native tool has authorized for this request.
- `request_context`: the current `DiscourseMcp::RequestContext`. It provides the  
current `guardian` and delegated scope checks through `has_scopes?` and `ensure_scopes!`.

Return the complete `data` hash. Preserve data from other plugins. Use the plugin  
name as a namespace. Do not change the topics or return data for other topic IDs.  
Values must be JSON-serializable. Integer hash keys become strings in the response.  
The data appears in both text content and structured content. An invalid modifier  
return value or an exception fails the tool call.

```ruby
after_initialize do
  register_modifier(:mcp_topic_plugin_data) do |data, topics, request_context|
    next data unless SiteSetting.example_enabled

    topics.each do |topic|
      next unless request_context.guardian.can_edit?(topic)

      data[topic.id] = data.fetch(topic.id, {}).merge(
        "example" => { editable: true },
      )
    end
    data
  end
end

```

A topic’s visibility does not grant access to all plugin data. Check the current  
user’s permissions and any required delegated scopes for each field. Do not return  
secrets or email addresses. Check reply visibility before returning data about a  
reply. Private-message access also requires the dedicated MCP scope.

Load related records for the whole batch, not once per topic. Omit a namespace when  
there is no data that the user can see. Native tools omit `plugin_data` when the  
entire topic entry is empty.

* * *

This document is version controlled - suggest changes [on github](https://github.com/discourse/discourse/blob/main/docs/developer-guides/docs/04-plugins/08-mcp-topic-data.md).

---

_[View the full topic](https://meta.discourse.org/t/add-plugin-data-to-native-mcp-topics/418891)._
