Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# MCP read-only mode hides every tool not annotated readOnlyHint, for every caller including admins

- **Status:** Accepted
- **Revisions:** v1 2026-11-04 (initial)
- **Revisions:** v1 2026-11-04 (initial) · v2 2026-11-05 (single tools can be disabled)
- **Deciders:** Vishnu Jain
- **Guard:** `McpReadOnlyModeTest`
- **Related:** #36577, #33323, #36579
Expand Down Expand Up @@ -32,3 +32,9 @@ A new write tool must carry `readOnlyHint: false` (or no annotation) to stay hid
tool `readOnlyHint: true` exposes it in read-only mode. A per-tool allowlist was considered and left
out: nobody asked to hide individual read tools, and a name list goes stale on upgrade. Updating
`tools/list` without a restart would mean re-registering tools on a config change on every server.

## Amendment

**v2 2026-11-05.** Admins asked to turn off single tools (#37161), so the per-tool list left out above now
exists as a denylist of tool names, applied the same two ways. See
ADR:2026-11-05-mcp-admins-can-disable-single-tools. Read-only mode is unchanged.
32 changes: 32 additions & 0 deletions docs/decisions/2026-11-05-mcp-admins-can-disable-single-tools.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# MCP admins can disable single tools by name, for every caller including admins

- **Status:** Accepted
- **Revisions:** v1 2026-11-05 (initial)
- **Deciders:** Vishnu Jain
- **Guard:** `McpReadOnlyModeTest`
- **Related:** #37161, ADR:2026-11-04-mcp-read-only-mode-hides-write-tools

## Context

Read-only mode hides every write tool at once. Admins also asked to turn off single tools, read or
write, whatever the user's permissions, and to do it from the MCP Server settings.

## Decision

- `disabledTools` in `mcpConfiguration`: a set of tool names, default empty. It is a denylist, so a
tool added on upgrade is on until an admin disables it.
- It is applied exactly like read-only mode, in the same two places in `McpServer`: left out of
`tools/list` at startup, and refused with a 403 on every call. A disabled tool is refused right
away; the list changes, and enabling it again applies, after a restart. When both apply, the
read-only message wins.
- A name that matches no registered tool is ignored with a startup warning, not rejected on save:
it may belong to another distribution or to a tool renamed on upgrade.
- The settings form offers the tools the server registered, served by `GET /system/mcp/tools`
(admin only), not a list in the form schema: distributions add their own tools, and a hardcoded
list goes stale.

## Consequences

Renaming a tool silently re-enables it on servers that disabled the old name, so a rename should say
so in the release notes. There is no allowlist: a deployment that wants only a few tools disables the
rest and revisits the list on upgrade.
1 change: 1 addition & 0 deletions openmetadata-mcp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ This module implements a complete OAuth 2.0 Authorization Code Flow with PKCE fo
- **Thread-Safe Concurrent Processing** - ThreadLocal storage for request isolation
- **Audit Logging** - OAuth operations logged via SLF4J (oauth_audit_log table available for future use)
- **Read-only Mode** - Turn on Read-only Mode in the MCP Server app settings to expose only tools annotated `readOnlyHint`, for every user including admins. Writes are blocked at once; the tool list changes, and turning it off applies, after a restart. Through the API, send the full configuration: `PUT /api/v1/system/mcp/config` replaces every field.
- **Disabled Tools** - Pick tools under Disabled Tools in the MCP Server app settings to turn them off for every user including admins. Calls are refused at once; the tool list changes, and enabling a tool again applies, after a restart. `GET /api/v1/system/mcp/tools` lists the tool names the server registered.

### Database-Driven Configuration
- **Runtime Configuration** - Update MCP settings without server restart via REST API
Expand Down
63 changes: 52 additions & 11 deletions openmetadata-mcp/src/main/java/org/openmetadata/mcp/McpServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
import io.modelcontextprotocol.spec.McpError;
import io.modelcontextprotocol.spec.McpSchema;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.jetty.ee10.servlet.ServletHolder;
import org.openmetadata.mcp.prompts.DefaultPromptsContext;
Expand All @@ -30,6 +32,7 @@
import org.openmetadata.service.apps.ApplicationContext;
import org.openmetadata.service.apps.McpServerProvider;
import org.openmetadata.service.apps.bundles.mcp.McpAppConstants;
import org.openmetadata.service.apps.bundles.mcp.McpToolRegistry;
import org.openmetadata.service.limits.Limits;
import org.openmetadata.service.rdf.RdfRepository;
import org.openmetadata.service.security.Authorizer;
Expand Down Expand Up @@ -83,8 +86,10 @@ public void initializeMcpServer(
this.limits = limits;
this.environment = environment;
MutableServletContextHandler contextHandler = environment.getApplicationContext();
List<McpSchema.Tool> registered = getTools();
McpToolRegistry.setToolNames(registered.stream().map(McpSchema.Tool::name).toList());
List<McpSchema.Tool> tools =
exposedTools(getTools(), SecurityConfigurationManager.getCurrentMcpConfig());
exposedTools(registered, SecurityConfigurationManager.getCurrentMcpConfig());
List<McpSchema.Prompt> prompts = getPrompts();
addStatelessTransport(contextHandler, tools, prompts);
}
Expand Down Expand Up @@ -147,7 +152,8 @@ private static boolean rdfEnabled() {
* after a subclass has added its own tools in {@link #getTools()}, so those are covered too.
* Tools are registered once at startup, so {@link #executeTool} checks again on every call:
* turning the mode on blocks writes before the restart that drops them from tools/list. See
* ADR:2026-11-04-mcp-read-only-mode-hides-write-tools.
* ADR:2026-11-04-mcp-read-only-mode-hides-write-tools. Disabled tools follow the same two steps,
* see ADR:2026-11-05-mcp-admins-can-disable-single-tools.
*/
static List<McpSchema.Tool> exposedTools(List<McpSchema.Tool> tools, MCPConfiguration config) {
List<McpSchema.Tool> exposed = tools;
Expand All @@ -157,13 +163,41 @@ static List<McpSchema.Tool> exposedTools(List<McpSchema.Tool> tools, MCPConfigur
"[MCP] Read-only mode; withholding {} write tool(s) from tools/list",
tools.size() - exposed.size());
}
return exposed;
return withoutDisabledTools(exposed, tools, config);
}

private static List<McpSchema.Tool> withoutDisabledTools(
List<McpSchema.Tool> exposed, List<McpSchema.Tool> registered, MCPConfiguration config) {
Set<String> disabled = disabledTools(config);
warnAboutUnknownTools(registered, disabled);
List<McpSchema.Tool> enabled =
exposed.stream().filter(tool -> !disabled.contains(tool.name())).toList();
if (enabled.size() < exposed.size()) {
LOG.info(
"[MCP] Withholding {} disabled tool(s) from tools/list", exposed.size() - enabled.size());
}
return enabled;
}

// Not an error: the name may be a tool of another distribution or one renamed on upgrade.
private static void warnAboutUnknownTools(List<McpSchema.Tool> registered, Set<String> disabled) {
Set<String> names = registered.stream().map(McpSchema.Tool::name).collect(Collectors.toSet());
List<String> unknown = disabled.stream().filter(name -> !names.contains(name)).toList();
if (!unknown.isEmpty()) {
LOG.warn("[MCP] Ignoring disabled tool name(s) that match no registered tool: {}", unknown);
}
}

private static boolean isReadOnlyMode(MCPConfiguration config) {
return config != null && Boolean.TRUE.equals(config.getReadOnly());
}

private static Set<String> disabledTools(MCPConfiguration config) {
return config == null || config.getDisabledTools() == null
? Set.of()
: config.getDisabledTools();
}

// The MCP spec defaults readOnlyHint to false, so a tool without it counts as a write tool.
// describe_entity_type only reads, but it exists to prepare a create_entity call.
private static boolean isAvailableInReadOnlyMode(McpSchema.Tool tool) {
Expand All @@ -172,9 +206,15 @@ private static boolean isAvailableInReadOnlyMode(McpSchema.Tool tool) {
return readOnlyHint && !WRITE_HELPER_TOOLS.contains(tool.name());
}

private static boolean isRefusedInReadOnlyMode(McpSchema.Tool tool) {
return isReadOnlyMode(SecurityConfigurationManager.getCurrentMcpConfig())
&& !isAvailableInReadOnlyMode(tool);
private static Optional<String> refusalReason(McpSchema.Tool tool, MCPConfiguration config) {
Optional<String> reason = Optional.empty();
if (isReadOnlyMode(config) && !isAvailableInReadOnlyMode(tool)) {
reason =
Optional.of("The MCP server is in read-only mode, so " + tool.name() + " is unavailable");
} else if (disabledTools(config).contains(tool.name())) {
reason = Optional.of(tool.name() + " is disabled on this MCP server");
}
return reason;
}

protected List<McpSchema.Prompt> getPrompts() {
Expand Down Expand Up @@ -362,11 +402,12 @@ private McpSchema.CallToolResult executeTool(
try {
ImpersonationContext.setImpersonatedBy(getMcpBotName());
outcome =
isRefusedInReadOnlyMode(tool)
? DefaultToolContext.forbidden(
"The MCP server is in read-only mode, so " + tool.name() + " is unavailable")
: toolContext.callToolWithMetadata(
authorizer, limits, tool.name(), securityContext, req);
refusalReason(tool, SecurityConfigurationManager.getCurrentMcpConfig())
.map(DefaultToolContext::forbidden)
.orElseGet(
() ->
toolContext.callToolWithMetadata(
authorizer, limits, tool.name(), securityContext, req));
return outcome.result();
} finally {
recordUsage(tool.name(), userName, clientName, outcome);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,30 @@ void aReadToolStillRunsInReadOnlyMode() {
assertSame(SUCCESS, callInReadOnlyMode(succeedingToolContext(), "search_metadata"));
}

@Test
void aDisabledToolIsWithheldAndAnUnknownNameIsIgnored() {
List<McpSchema.Tool> tools = new McpServer().getTools();
MCPConfiguration config =
new MCPConfiguration().withDisabledTools(Set.of("semantic_search", "no_such_tool"));

List<String> exposed = names(McpServer.exposedTools(tools, config));

assertFalse(exposed.contains("semantic_search"));
assertEquals(tools.size() - 1, exposed.size());
}

@Test
void aRegisteredDisabledToolIsRefusedOnEveryCall() {
DefaultToolContext toolContext = succeedingToolContext();
MCPConfiguration config = new MCPConfiguration().withDisabledTools(Set.of("search_metadata"));

McpSchema.CallToolResult result = call(toolContext, "search_metadata", config);

assertTrue(result.isError(), "a disabled tool must not run");
assertEquals(403, ((Map<?, ?>) result.structuredContent()).get("statusCode"));
verify(toolContext, never()).callToolWithMetadata(any(), any(), any(), any(), any());
}

private static DefaultToolContext succeedingToolContext() {
DefaultToolContext toolContext = mock(DefaultToolContext.class);
when(toolContext.callToolWithMetadata(any(), any(), any(), any(), any()))
Expand All @@ -110,6 +134,11 @@ private static DefaultToolContext succeedingToolContext() {

private static McpSchema.CallToolResult callInReadOnlyMode(
DefaultToolContext toolContext, String toolName) {
return call(toolContext, toolName, READ_ONLY);
}

private static McpSchema.CallToolResult call(
DefaultToolContext toolContext, String toolName, MCPConfiguration mcpConfig) {
McpServer server = new McpServer(toolContext, new DefaultPromptsContext());
server.jwtFilter = jwtFilterFor("alice");
McpSchema.CallToolRequest request =
Expand All @@ -118,7 +147,7 @@ private static McpSchema.CallToolResult callInReadOnlyMode(
try (MockedStatic<SecurityConfigurationManager> config =
mockStatic(SecurityConfigurationManager.class);
MockedStatic<McpUsageRecorder> usage = mockStatic(McpUsageRecorder.class)) {
config.when(SecurityConfigurationManager::getCurrentMcpConfig).thenReturn(READ_ONLY);
config.when(SecurityConfigurationManager::getCurrentMcpConfig).thenReturn(mcpConfig);
return server.getTool(toolNamed(toolName)).callHandler().apply(callerContext(), request);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2026 Collate
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.openmetadata.service.apps.bundles.mcp;

import java.util.List;

/**
* Names of the tools the MCP server registered at startup, before read-only mode or disabled tools
* are applied, so the settings form can offer every tool. It lives here because the MCP module
* depends on this one, not the other way round. See ADR:2026-11-05-mcp-admins-can-disable-single-tools.
*/
public final class McpToolRegistry {

private static volatile List<String> toolNames = List.of();

private McpToolRegistry() {}

public static void setToolNames(List<String> names) {
toolNames = List.copyOf(names);
}

public static List<String> getToolNames() {
return toolNames;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.media.Schema;
Expand Down Expand Up @@ -99,6 +100,7 @@
import org.openmetadata.schema.utils.ResultList;
import org.openmetadata.service.Entity;
import org.openmetadata.service.OpenMetadataApplicationConfig;
import org.openmetadata.service.apps.bundles.mcp.McpToolRegistry;
import org.openmetadata.service.cache.CacheBundle;
import org.openmetadata.service.cache.CacheConfig;
import org.openmetadata.service.cache.CacheMetrics;
Expand Down Expand Up @@ -1596,6 +1598,30 @@ public Response getMCPConfiguration(@Context SecurityContext securityContext) {
return Response.status(Response.Status.NOT_FOUND).entity("MCP configuration not found").build();
}

@GET
@Path("/mcp/tools")
@Operation(
operationId = "listMCPTools",
summary = "List the MCP server's tools",
description =
"Names of the tools this MCP server registered at startup, including tools a "
+ "distribution adds and before read-only mode or disabled tools are applied. "
+ "The settings form offers these as the tools an admin can disable.",
responses = {
@ApiResponse(
responseCode = "200",
description = "Tool names",
content =
@Content(
mediaType = "application/json",
array = @ArraySchema(schema = @Schema(type = "string")))),
@ApiResponse(responseCode = "403", description = "Forbidden")
})
public List<String> listMCPTools(@Context SecurityContext securityContext) {
authorizer.authorizeAdmin(securityContext);
return McpToolRegistry.getToolNames();
}

@PUT
@Path("/mcp/config")
@Operation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@
"description": "Expose only the MCP tools that do not change metadata (annotated readOnlyHint), for every user including admins. Turning it on blocks write tools right away; they leave tools/list after a restart, and turning it off applies after a restart.",
"type": "boolean",
"default": false
},
"disabledTools": {
"description": "Names of MCP tools to turn off for every user, admins included. A disabled tool is refused on every call right away and leaves tools/list after a restart; enabling it again applies after a restart. A name that matches no tool is ignored.",
"type": "array",
"items": {
"type": "string"
},
"uniqueItems": true,
"default": []
}
},
"additionalProperties": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,11 @@ $$section

Expose only the MCP tools that do not change metadata, such as search, lineage and entity details. Tools that create or edit metadata are blocked for every MCP client and every user, admins included. Each user's own permissions still apply to the remaining tools. Turning it on blocks those tools right away; they leave the tool list after the server restarts, and turning it off takes effect after a restart.

$$

$$section
### Disabled Tools $(id="disabledTools")

MCP tools to turn off for every MCP client and every user, admins included, whatever their permissions. Use it to hide single tools, read or write; Read-only Mode still applies to the rest. A disabled tool is blocked right away; it leaves the tool list after the server restarts, and enabling it again takes effect after a restart.

$$
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ jest.mock('react-i18next', () => ({

jest.mock('../../../../rest/mcpConfigAPI', () => ({
getMcpConfig: jest.fn(),
getMcpTools: jest.fn().mockResolvedValue(['search_metadata']),
updateMcpConfig: jest.fn(),
}));

Expand Down Expand Up @@ -263,7 +264,13 @@ describe('McpApplicationConfiguration', () => {
it.each([
[
'every field the form shows',
['/baseUrl', '/allowedOrigins', '/maxResponseChars', '/readOnly'],
[
'/baseUrl',
'/allowedOrigins',
'/maxResponseChars',
'/readOnly',
'/disabledTools',
],
],
['the whole setting', ['/']],
])(
Expand Down Expand Up @@ -328,6 +335,7 @@ describe('McpApplication form schema', () => {
'allowedOrigins',
'maxResponseChars',
'readOnly',
'disabledTools',
];
// Shape of a real stored mcpConfiguration row, including the fields no code reads.
const storedConfig = {
Expand All @@ -339,6 +347,7 @@ describe('McpApplication form schema', () => {
allowedOrigins: ['http://localhost:3000', 'https://app.example.com'],
maxResponseChars: 100000,
readOnly: true,
disabledTools: ['create_test_case'],
connectTimeout: 30000,
originHeaderUri: 'http://localhost',
mcpServerVersion: '1.0.0',
Expand Down
Loading
Loading