Skip to content

feat(mcp): add read-only mode for the built-in MCP server - #36579

Merged
Vishnuujain merged 6 commits into
open-metadata:mainfrom
aidanradford:feat/mcp-tool-allowlist
Nov 4, 2026
Merged

Vishnuujain merged 6 commits into
open-metadata:mainfrom
aidanradford:feat/mcp-tool-allowlist

Conversation

@aidanradford

@aidanradford aidanradford commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes:

Fixes #36577

Type of change:

  • Improvement

High-level design:

  • Adds readOnly to the MCP configuration (off by default), set from the MCP Server app settings. When on, only tools annotated readOnlyHint: true are listed or callable, for every user including admins (admins skip policy checks, so a deny policy can't cover them). Each user's own permissions still apply to the remaining tools.
  • Turning it on blocks write tools right away (403 at call time); they leave tools/list after a restart, and turning it off applies after a restart. describe_entity_type is hidden too, since it only prepares a create_entity call.
  • Replaces the earlier MCP_ALLOWED_TOOLS env allowlist: read-only is what this issue and Feature request : read-only mode for the built-in MCP server #33323 ask for, and every tool already carries readOnlyHint. See ADR:2026-11-04-mcp-read-only-mode-hides-write-tools.

Tests:

Use cases covered

  • Read-only mode withholds the write tools and describe_entity_type, and keeps the read tools.
  • A tool without readOnlyHint counts as a write tool.
  • Off or unset leaves every tool as before.
  • A registered write tool is refused once read-only is turned on, without a restart.

Unit tests

  • I added unit tests for the new/changed logic.
    Files updated: McpReadOnlyModeTest.java, useMcpConfiguration.test.tsx, McpApplicationConfiguration.test.tsx.
  • mvn -pl openmetadata-mcp -am package -Dtest='org/openmetadata/mcp/**/*Test' -Dsurefire.failIfNoSpecifiedTests=false passed: 859 tests, 0 failures. Jest: 22 passed.

Backend integration tests

  • Not applicable (no backend API changes).

Ingestion integration tests

  • Not applicable (no ingestion changes).

Playwright (UI) tests

  • Not added: the settings form is covered by the Jest tests above.

Manual testing performed

On a local server: with the toggle on, patch_entity returned 403 right after saving; after a restart tools/list went from 18 to 13 tools and create_entity returned Unknown tool; read tools kept working. Saving from the UI kept the other MCP settings.

UI screen recording:

Screenshot below. Screen recording to follow.

Read-only Mode toggle in the MCP Server settings

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR is linked to a GitHub issue via Fixes #<issue-number> above.
  • I have commented on my code, particularly in hard-to-understand areas — no new explanatory comments were needed.
  • For JSON Schema changes: mcpConfiguration.json gains readOnly; TypeScript types regenerated.
  • UI recording requirement: screenshot attached, recording to follow.
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.
  • Self-review: I reviewed the final diff against REVIEW.md (the pr-checklist skill runs it) and fixed every 🔴 finding, or answered it on the line below.
  • Decision check: if this PR decides something the next contributor could undo — a schema field, REST path or format another component or repo must agree with, a new default or limit, an ordering that must hold, or a rule stated only in this description — it adds a record under docs/decisions/ (see its README.md). This description is gone from git log after the squash-merge.
  • I have added tests around the new logic.

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR checks passed

The linked issue has a description and all required Shipping project fields set. Thanks!

@github-actions

Copy link
Copy Markdown
Contributor

Hi there 👋 Thanks for your contribution!

The OpenMetadata team will review the PR shortly! Once it has been labeled as safe to test, the CI workflows
will start executing and we'll be able to make sure everything is working as expected.

Let us know if you need any help!

@Vishnuujain
Vishnuujain requested a review from a team as a code owner November 3, 2026 21:45
@Vishnuujain
Vishnuujain requested a review from sweta1308 November 3, 2026 21:45
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Hi there 👋 Thanks for your contribution!

The OpenMetadata team will review the PR shortly! Once it has been labeled as safe to test, the CI workflows
will start executing and we'll be able to make sure everything is working as expected.

Let us know if you need any help!

@gitar-bot

gitar-bot Bot commented Nov 3, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 2 closed / 2 findings

🔴 High risk · The MCP read-only gate relies on tool annotations; a mutating tool marked read-only could still change metadata despite the setting.

Adds an optional MCP_ALLOWED_TOOLS server-side allowlist that restricts which MCP tools are advertised and callable, with an unset variable preserving existing behavior. Resolved the missing decision record for the allowlist semantics and added a warning for misspelled allowlist entries. No open issues remain.

✅ 2 closed
✅ Quality: MCP_ALLOWED_TOOLS semantics are a new operator contract with no record

📄 openmetadata-mcp/src/main/java/org/openmetadata/mcp/tools/DefaultToolContext.java:30 📄 openmetadata-mcp/src/main/java/org/openmetadata/mcp/tools/DefaultToolContext.java:43-57 📄 openmetadata-mcp/src/main/java/org/openmetadata/mcp/tools/DefaultToolContext.java:99-104 📄 openmetadata-mcp/README.md:32
This PR adds a configuration contract that operators and downstream deployments have to agree with. The MCP_ALLOWED_TOOLS env var takes comma-separated tool names; leaving it unset exposes every tool, while setting it to an empty or blank value disables all tools. A disallowed call gets a 403 with error category AUTH, and the allowlist is applied before RDF gating. The description says "An explicitly empty MCP_ALLOWED_TOOLS disables all MCP tools" and "Unlisted tools are hidden ... and direct calls to them are rejected". None of docs/decisions/ covers it (the existing mcp-* records only deal with OAuth and masking), and the README line leaves out the unset-versus-empty distinction. The repo squash-merges, so that rule would survive only in the PR body. A record would say something like: "The MCP server exposes and dispatches only the tools named in MCP_ALLOWED_TOOLS; if the variable is unset, every tool is allowed, and if it is set but empty, no tool is allowed. A disallowed call returns 403 / AUTH before dispatch, and RDF gating still applies on top."

✅ Edge Case: Misspelled allowlist entries silently hide tools with no warning

📄 openmetadata-mcp/src/main/java/org/openmetadata/mcp/tools/DefaultToolContext.java:47-56 📄 openmetadata-mcp/src/main/java/org/openmetadata/mcp/McpServer.java:118-121
The constructor accepts any name in MCP_ALLOWED_TOOLS and never checks it against the tool names in tools.json. If an operator mistypes a name (for example search_metdata), that tool silently disappears from tools/list, and calls to it return 403. Nothing is logged to say the entry matched no tool. The startup log does report the number of tools withheld by RDF gating, but it says nothing about tools withheld by the allowlist. The fix is to log a warning in getTools() for configured names that match no defined tool, and to log the effective allowlist once.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@Vishnuujain Vishnuujain changed the title feat(mcp): add optional server-side tool allowlist feat(mcp): add read-only mode for the built-in MCP server Nov 3, 2026
@Vishnuujain Vishnuujain added safe to test Add this label to run secure Github workflows on PRs To release Will cherry-pick this PR into the release branch labels Nov 3, 2026
@Vishnuujain

Copy link
Copy Markdown
Contributor

Thanks for this @aidanradford! I pushed a couple of commits that turn it into a readOnly switch in the MCP config instead of an env allowlist. It hides every tool not marked readOnlyHint, also applies to admins (policies can't stop them), and can be toggled from the MCP app settings page. Shout if you still need a per-tool list.

@sonarqubecloud

sonarqubecloud Bot commented Nov 3, 2026

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Jest test Coverage

UI tests summary

Lines Statements Branches Functions
Coverage: 81%
81.24% (137861/169679) 68.24% (49606/72691) 71.22% (27879/39141)

@sonarqubecloud

sonarqubecloud Bot commented Nov 3, 2026

Copy link
Copy Markdown

@Vishnuujain
Vishnuujain merged commit a2c47f4 into open-metadata:main Nov 4, 2026
127 of 151 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

safe to test Add this label to run secure Github workflows on PRs To release Will cherry-pick this PR into the release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow operators to restrict the built-in MCP server’s available tools

3 participants