diff --git a/docs/decisions/2026-11-04-mcp-read-only-mode-hides-write-tools.md b/docs/decisions/2026-11-04-mcp-read-only-mode-hides-write-tools.md index b304bbb1e024..8b1387a7eca8 100644 --- a/docs/decisions/2026-11-04-mcp-read-only-mode-hides-write-tools.md +++ b/docs/decisions/2026-11-04-mcp-read-only-mode-hides-write-tools.md @@ -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 @@ -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. diff --git a/docs/decisions/2026-11-05-mcp-admins-can-disable-single-tools.md b/docs/decisions/2026-11-05-mcp-admins-can-disable-single-tools.md new file mode 100644 index 000000000000..ad5a54b42ff5 --- /dev/null +++ b/docs/decisions/2026-11-05-mcp-admins-can-disable-single-tools.md @@ -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. diff --git a/openmetadata-mcp/README.md b/openmetadata-mcp/README.md index 92c0f30a8889..8b5cd0b8a1d0 100644 --- a/openmetadata-mcp/README.md +++ b/openmetadata-mcp/README.md @@ -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 diff --git a/openmetadata-mcp/src/main/java/org/openmetadata/mcp/McpServer.java b/openmetadata-mcp/src/main/java/org/openmetadata/mcp/McpServer.java index b27c329634fa..efe21fab4162 100644 --- a/openmetadata-mcp/src/main/java/org/openmetadata/mcp/McpServer.java +++ b/openmetadata-mcp/src/main/java/org/openmetadata/mcp/McpServer.java @@ -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; @@ -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; @@ -83,8 +86,10 @@ public void initializeMcpServer( this.limits = limits; this.environment = environment; MutableServletContextHandler contextHandler = environment.getApplicationContext(); + List registered = getTools(); + McpToolRegistry.setToolNames(registered.stream().map(McpSchema.Tool::name).toList()); List tools = - exposedTools(getTools(), SecurityConfigurationManager.getCurrentMcpConfig()); + exposedTools(registered, SecurityConfigurationManager.getCurrentMcpConfig()); List prompts = getPrompts(); addStatelessTransport(contextHandler, tools, prompts); } @@ -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 exposedTools(List tools, MCPConfiguration config) { List exposed = tools; @@ -157,13 +163,41 @@ static List exposedTools(List 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 withoutDisabledTools( + List exposed, List registered, MCPConfiguration config) { + Set disabled = disabledTools(config); + warnAboutUnknownTools(registered, disabled); + List 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 registered, Set disabled) { + Set names = registered.stream().map(McpSchema.Tool::name).collect(Collectors.toSet()); + List 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 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) { @@ -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 refusalReason(McpSchema.Tool tool, MCPConfiguration config) { + Optional 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 getPrompts() { @@ -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); diff --git a/openmetadata-mcp/src/test/java/org/openmetadata/mcp/McpReadOnlyModeTest.java b/openmetadata-mcp/src/test/java/org/openmetadata/mcp/McpReadOnlyModeTest.java index be87e1ac040b..ea2b0daf1634 100644 --- a/openmetadata-mcp/src/test/java/org/openmetadata/mcp/McpReadOnlyModeTest.java +++ b/openmetadata-mcp/src/test/java/org/openmetadata/mcp/McpReadOnlyModeTest.java @@ -101,6 +101,30 @@ void aReadToolStillRunsInReadOnlyMode() { assertSame(SUCCESS, callInReadOnlyMode(succeedingToolContext(), "search_metadata")); } + @Test + void aDisabledToolIsWithheldAndAnUnknownNameIsIgnored() { + List tools = new McpServer().getTools(); + MCPConfiguration config = + new MCPConfiguration().withDisabledTools(Set.of("semantic_search", "no_such_tool")); + + List 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())) @@ -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 = @@ -118,7 +147,7 @@ private static McpSchema.CallToolResult callInReadOnlyMode( try (MockedStatic config = mockStatic(SecurityConfigurationManager.class); MockedStatic 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); } } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/apps/bundles/mcp/McpToolRegistry.java b/openmetadata-service/src/main/java/org/openmetadata/service/apps/bundles/mcp/McpToolRegistry.java new file mode 100644 index 000000000000..c203698370df --- /dev/null +++ b/openmetadata-service/src/main/java/org/openmetadata/service/apps/bundles/mcp/McpToolRegistry.java @@ -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 toolNames = List.of(); + + private McpToolRegistry() {} + + public static void setToolNames(List names) { + toolNames = List.copyOf(names); + } + + public static List getToolNames() { + return toolNames; + } +} diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/resources/system/SystemResource.java b/openmetadata-service/src/main/java/org/openmetadata/service/resources/system/SystemResource.java index 525efdbad976..4db3d17d3eef 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/resources/system/SystemResource.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/resources/system/SystemResource.java @@ -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; @@ -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; @@ -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 listMCPTools(@Context SecurityContext securityContext) { + authorizer.authorizeAdmin(securityContext); + return McpToolRegistry.getToolNames(); + } + @PUT @Path("/mcp/config") @Operation( diff --git a/openmetadata-spec/src/main/resources/json/schema/configuration/mcpConfiguration.json b/openmetadata-spec/src/main/resources/json/schema/configuration/mcpConfiguration.json index 7a6daadc18d3..84972bfe355d 100644 --- a/openmetadata-spec/src/main/resources/json/schema/configuration/mcpConfiguration.json +++ b/openmetadata-spec/src/main/resources/json/schema/configuration/mcpConfiguration.json @@ -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 diff --git a/openmetadata-ui/src/main/resources/ui/public/locales/en-US/Applications/McpApplication.md b/openmetadata-ui/src/main/resources/ui/public/locales/en-US/Applications/McpApplication.md index 8947c71bf379..5d16add502f5 100644 --- a/openmetadata-ui/src/main/resources/ui/public/locales/en-US/Applications/McpApplication.md +++ b/openmetadata-ui/src/main/resources/ui/public/locales/en-US/Applications/McpApplication.md @@ -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. + $$ \ No newline at end of file diff --git a/openmetadata-ui/src/main/resources/ui/src/components/Settings/Applications/McpApplicationConfiguration/McpApplicationConfiguration.test.tsx b/openmetadata-ui/src/main/resources/ui/src/components/Settings/Applications/McpApplicationConfiguration/McpApplicationConfiguration.test.tsx index 2ebaa5a17f6b..9e8dc233861f 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/Settings/Applications/McpApplicationConfiguration/McpApplicationConfiguration.test.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/Settings/Applications/McpApplicationConfiguration/McpApplicationConfiguration.test.tsx @@ -45,6 +45,7 @@ jest.mock('react-i18next', () => ({ jest.mock('../../../../rest/mcpConfigAPI', () => ({ getMcpConfig: jest.fn(), + getMcpTools: jest.fn().mockResolvedValue(['search_metadata']), updateMcpConfig: jest.fn(), })); @@ -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', ['/']], ])( @@ -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 = { @@ -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', diff --git a/openmetadata-ui/src/main/resources/ui/src/components/Settings/Applications/McpApplicationConfiguration/McpApplicationConfiguration.tsx b/openmetadata-ui/src/main/resources/ui/src/components/Settings/Applications/McpApplicationConfiguration/McpApplicationConfiguration.tsx index 95cda820b6e9..02ac5656077d 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/Settings/Applications/McpApplicationConfiguration/McpApplicationConfiguration.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/Settings/Applications/McpApplicationConfiguration/McpApplicationConfiguration.tsx @@ -38,6 +38,7 @@ const McpApplicationConfiguration = ({ const [activeField, setActiveField] = useState(''); const { formConfig, + formSchema, formUiSchema, isEveryFieldManaged, isFetching, @@ -46,7 +47,7 @@ const McpApplicationConfiguration = ({ fetchMcpConfig, refetchSources, saveMcpConfig, - } = useMcpConfiguration(); + } = useMcpConfiguration(jsonSchema); const handleFieldFocus = useCallback((fieldName: string) => { if (isEmpty(fieldName)) { @@ -78,7 +79,7 @@ const McpApplicationConfiguration = ({ isLoading={isSaving} okText={t('label.save')} readonly={isEveryFieldManaged} - schema={jsonSchema} + schema={formSchema} uiSchema={formUiSchema} onFocus={handleFieldFocus} onSubmit={({ formData }: IChangeEvent) => diff --git a/openmetadata-ui/src/main/resources/ui/src/components/Settings/Applications/McpApplicationConfiguration/useMcpConfiguration.test.tsx b/openmetadata-ui/src/main/resources/ui/src/components/Settings/Applications/McpApplicationConfiguration/useMcpConfiguration.test.tsx index 7350a6c7a0f5..1ba420bdf3b5 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/Settings/Applications/McpApplicationConfiguration/useMcpConfiguration.test.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/Settings/Applications/McpApplicationConfiguration/useMcpConfiguration.test.tsx @@ -10,6 +10,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { RJSFSchema } from '@rjsf/utils'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { act, renderHook, waitFor } from '@testing-library/react'; import { AxiosError } from 'axios'; @@ -19,7 +20,12 @@ import { SettingSource, SettingType, } from '../../../../generated/system/settingsSourceResponse'; -import { getMcpConfig, updateMcpConfig } from '../../../../rest/mcpConfigAPI'; +import { + getMcpConfig, + getMcpTools, + updateMcpConfig, +} from '../../../../rest/mcpConfigAPI'; +import mcpSchema from '../../../../utils/ApplicationSchemas/McpApplication.json'; import { getSettingsSource } from '../../../../rest/settingConfigAPI'; import { showErrorToast, showSuccessToast } from '../../../../utils/ToastUtils'; import { useMcpConfiguration } from './useMcpConfiguration'; @@ -30,6 +36,7 @@ jest.mock('react-i18next', () => ({ jest.mock('../../../../rest/mcpConfigAPI', () => ({ getMcpConfig: jest.fn(), + getMcpTools: jest.fn(), updateMcpConfig: jest.fn(), })); @@ -44,6 +51,7 @@ jest.mock('../../../../utils/ToastUtils', () => ({ })); const mockGetMcpConfig = getMcpConfig as jest.Mock; +const mockGetMcpTools = getMcpTools as jest.Mock; const mockUpdateMcpConfig = updateMcpConfig as jest.Mock; const mockGetSettingsSource = getSettingsSource as jest.Mock; @@ -70,13 +78,16 @@ const renderUseMcpConfiguration = () => { {children} ); - return renderHook(() => useMcpConfiguration(), { wrapper }); + return renderHook(() => useMcpConfiguration(mcpSchema as RJSFSchema), { + wrapper, + }); }; describe('useMcpConfiguration', () => { beforeEach(() => { jest.clearAllMocks(); mockGetMcpConfig.mockResolvedValue(storedConfig); + mockGetMcpTools.mockResolvedValue(['search_metadata', 'nlq_search']); mockGetSettingsSource.mockResolvedValue({ settings: [] }); mockUpdateMcpConfig.mockImplementation(async (payload) => payload); }); @@ -187,6 +198,7 @@ describe('useMcpConfiguration', () => { '/allowedOrigins', '/maxResponseChars', '/readOnly', + '/disabledTools', ]), ], }); @@ -195,4 +207,36 @@ describe('useMcpConfiguration', () => { await waitFor(() => expect(result.current.isEveryFieldManaged).toBe(true)); }); + + it("offers the server's tools, plus saved names it no longer has, as the tools to disable", async () => { + mockGetMcpConfig.mockResolvedValue({ + ...storedConfig, + disabledTools: ['sparql_query'], + }); + + const { result } = renderUseMcpConfiguration(); + + await waitFor(() => + expect( + (result.current.formSchema.properties?.disabledTools as RJSFSchema) + .items + ).toEqual({ + type: 'string', + enum: ['search_metadata', 'nlq_search', 'sparql_query'], + }) + ); + }); + + it('falls back to typing tool names when the tool list fails to load', async () => { + const error = { response: { status: 500 } } as AxiosError; + mockGetMcpTools.mockRejectedValue(error); + + const { result } = renderUseMcpConfiguration(); + + await waitFor(() => expect(showErrorToast).toHaveBeenCalledWith(error)); + + expect( + result.current.formSchema.properties?.disabledTools + ).not.toHaveProperty('uiFieldType'); + }); }); diff --git a/openmetadata-ui/src/main/resources/ui/src/components/Settings/Applications/McpApplicationConfiguration/useMcpConfiguration.ts b/openmetadata-ui/src/main/resources/ui/src/components/Settings/Applications/McpApplicationConfiguration/useMcpConfiguration.ts index a3f73d835408..62ff8b01fca4 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/Settings/Applications/McpApplicationConfiguration/useMcpConfiguration.ts +++ b/openmetadata-ui/src/main/resources/ui/src/components/Settings/Applications/McpApplicationConfiguration/useMcpConfiguration.ts @@ -11,15 +11,20 @@ * limitations under the License. */ +import { RJSFSchema } from '@rjsf/utils'; import { AxiosError } from 'axios'; -import { pick } from 'lodash'; +import { isEmpty, omit, pick, uniq } from 'lodash'; import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { ClientErrors } from '../../../../enums/Axios.enum'; import { MCPConfiguration } from '../../../../generated/configuration/mcpConfiguration'; import { SettingType } from '../../../../generated/settings/settings'; import { useSettingsSource } from '../../../../hooks/platform/useSettingsSource'; -import { getMcpConfig, updateMcpConfig } from '../../../../rest/mcpConfigAPI'; +import { + getMcpConfig, + getMcpTools, + updateMcpConfig, +} from '../../../../rest/mcpConfigAPI'; import { applyManagedPathsToUiSchema, findSettingSource, @@ -35,26 +40,54 @@ import applicationsClassBase from '../AppDetails/ApplicationsClassBase'; * wrong base URL breaks the OAuth metadata behind a load balancer. The response cap depends on * which MCP clients connect, so it is set here too. Everything else in the stored * `mcpConfiguration` (timeouts, plus fields no code reads) stays out of the form but is merged - * back on save, because the PUT replaces the whole setting. Read-only mode is an admin choice, so - * it is edited here as well. + * back on save, because the PUT replaces the whole setting. Read-only mode and disabled tools are + * admin choices, so they are edited here as well. */ const EDITABLE_MCP_CONFIG_FIELDS: (keyof MCPConfiguration)[] = [ 'baseUrl', 'allowedOrigins', 'maxResponseChars', 'readOnly', + 'disabledTools', ]; const MCP_SETTING_TYPES = [SettingType.MCPConfiguration]; +/** + * Which tools exist depends on the server: Collate adds its own and RDF tools are left out when RDF + * is off, so the options are fetched, like the reindex entity list. Saved names stay options, or one + * the server no longer registers would fail validation and block every save. With no list (it + * failed, or the server registered none) the picker would offer only "All", which saves nothing, so + * the field falls back to typing names, like Allowed Origins. + */ +export const withMcpToolNames = ( + schema: RJSFSchema, + toolNames: string[] | undefined, + savedNames: string[] = [] +): RJSFSchema => { + if (!toolNames) { + return schema; + } + const field = schema.properties?.disabledTools as RJSFSchema; + const disabledTools: RJSFSchema = isEmpty(toolNames) + ? omit(field, ['uiFieldType', 'expandAllValue']) + : { + ...field, + items: { type: 'string', enum: uniq([...toolNames, ...savedNames]) }, + }; + + return { ...schema, properties: { ...schema.properties, disabledTools } }; +}; + /** * The MCP app entity holds no configuration of its own. Everything the MCP server actually reads * lives in the `mcpConfiguration` system setting, so the form talks to `/system/mcp/config` * directly rather than going through the app entity's `appConfiguration`. */ -export const useMcpConfiguration = () => { +export const useMcpConfiguration = (jsonSchema: RJSFSchema) => { const { t } = useTranslation(); const [formConfig, setFormConfig] = useState({}); + const [toolNames, setToolNames] = useState(); const [isFetching, setIsFetching] = useState(true); const [isSaving, setIsSaving] = useState(false); // Fields outside the form are not rendered but must survive a save, since the PUT replaces the @@ -106,9 +139,24 @@ export const useMcpConfiguration = () => { } }, [applyConfig]); + const fetchMcpTools = useCallback(async () => { + try { + setToolNames(await getMcpTools()); + } catch (error) { + setToolNames([]); + showErrorToast(error as AxiosError); + } + }, []); + useEffect(() => { void fetchMcpConfig(); - }, [fetchMcpConfig]); + void fetchMcpTools(); + }, [fetchMcpConfig, fetchMcpTools]); + + const formSchema = useMemo( + () => withMcpToolNames(jsonSchema, toolNames, formConfig.disabledTools), + [jsonSchema, toolNames, formConfig.disabledTools] + ); const saveMcpConfig = useCallback( // Callers pass form data already run through `formatFormDataForSubmit`. @@ -136,6 +184,7 @@ export const useMcpConfiguration = () => { return { formConfig, + formSchema, formUiSchema, isEveryFieldManaged, isFetching, diff --git a/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/tabs/applications/McpConfigForm.test.tsx b/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/tabs/applications/McpConfigForm.test.tsx index 96252f863ab9..a0c4f85e6102 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/tabs/applications/McpConfigForm.test.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/tabs/applications/McpConfigForm.test.tsx @@ -27,6 +27,7 @@ jest.mock('react-i18next', () => ({ jest.mock('../../../../../../rest/mcpConfigAPI', () => ({ getMcpConfig: jest.fn(), + getMcpTools: jest.fn().mockResolvedValue(['search_metadata']), updateMcpConfig: jest.fn(), })); diff --git a/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/tabs/applications/McpConfigForm.tsx b/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/tabs/applications/McpConfigForm.tsx index 923012085028..70248389b568 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/tabs/applications/McpConfigForm.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/tabs/applications/McpConfigForm.tsx @@ -29,6 +29,7 @@ const McpConfigForm: FC = ({ const { t } = useTranslation(); const { formConfig, + formSchema, formUiSchema, isEveryFieldManaged, isFetching, @@ -37,7 +38,7 @@ const McpConfigForm: FC = ({ fetchMcpConfig, refetchSources, saveMcpConfig, - } = useMcpConfiguration(); + } = useMcpConfiguration(jsonSchema); if (isFetching) { return ; @@ -54,7 +55,7 @@ const McpConfigForm: FC = ({ appData={{ ...appData, appConfiguration: formConfig }} isReadOnly={isEveryFieldManaged} isSaving={isSaving} - jsonSchema={jsonSchema} + jsonSchema={formSchema} showHint={showHint} submitLabel={t('label.save')} uiSchema={formUiSchema} diff --git a/openmetadata-ui/src/main/resources/ui/src/generated/configuration/mcpConfiguration.ts b/openmetadata-ui/src/main/resources/ui/src/generated/configuration/mcpConfiguration.ts index dea9156d6055..84fe6f348efe 100644 --- a/openmetadata-ui/src/main/resources/ui/src/generated/configuration/mcpConfiguration.ts +++ b/openmetadata-ui/src/main/resources/ui/src/generated/configuration/mcpConfiguration.ts @@ -30,6 +30,12 @@ export interface MCPConfiguration { * 30000ms (30 seconds) */ connectTimeout?: number; + /** + * 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. + */ + disabledTools?: string[]; /** * Enable or disable the MCP server */ diff --git a/openmetadata-ui/src/main/resources/ui/src/generated/settings/settings.ts b/openmetadata-ui/src/main/resources/ui/src/generated/settings/settings.ts index b8be7ecbbfe6..cc55eef9f30f 100644 --- a/openmetadata-ui/src/main/resources/ui/src/generated/settings/settings.ts +++ b/openmetadata-ui/src/main/resources/ui/src/generated/settings/settings.ts @@ -683,6 +683,12 @@ export interface PipelineServiceClientConfiguration { * 30000ms (30 seconds) */ connectTimeout?: number; + /** + * 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. + */ + disabledTools?: string[]; /** * Largest MCP tool response, in characters. Tools return fewer items to stay under it, so * it bounds how much of the MCP client's context one call can use. A saved change applies diff --git a/openmetadata-ui/src/main/resources/ui/src/jsons/applicationSchemas/McpApplication.json b/openmetadata-ui/src/main/resources/ui/src/jsons/applicationSchemas/McpApplication.json index baa03f27fbf2..461cdeded9e5 100644 --- a/openmetadata-ui/src/main/resources/ui/src/jsons/applicationSchemas/McpApplication.json +++ b/openmetadata-ui/src/main/resources/ui/src/jsons/applicationSchemas/McpApplication.json @@ -36,6 +36,18 @@ "description": "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.", "type": "boolean", "default": false + }, + "disabledTools": { + "title": "Disabled Tools", + "description": "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.", + "type": "array", + "items": { + "type": "string" + }, + "uniqueItems": true, + "uiFieldType": "treeSelect", + "expandAllValue": true, + "default": [] } }, "required": [ diff --git a/openmetadata-ui/src/main/resources/ui/src/rest/mcpConfigAPI.ts b/openmetadata-ui/src/main/resources/ui/src/rest/mcpConfigAPI.ts index 8caebef92417..84c075e40a7d 100644 --- a/openmetadata-ui/src/main/resources/ui/src/rest/mcpConfigAPI.ts +++ b/openmetadata-ui/src/main/resources/ui/src/rest/mcpConfigAPI.ts @@ -28,6 +28,12 @@ export const getMcpConfig = async () => { return response.data; }; +export const getMcpTools = async () => { + const response = await axiosClient.get('/system/mcp/tools'); + + return response.data; +}; + export const updateMcpConfig = async (payload: MCPConfiguration) => { const response = await axiosClient.put( '/system/mcp/config', diff --git a/openmetadata-ui/src/main/resources/ui/src/utils/ApplicationSchemas/McpApplication.json b/openmetadata-ui/src/main/resources/ui/src/utils/ApplicationSchemas/McpApplication.json index c054570ea16c..de566c085898 100644 --- a/openmetadata-ui/src/main/resources/ui/src/utils/ApplicationSchemas/McpApplication.json +++ b/openmetadata-ui/src/main/resources/ui/src/utils/ApplicationSchemas/McpApplication.json @@ -38,6 +38,18 @@ "description": "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.", "type": "boolean", "default": false + }, + "disabledTools": { + "title": "Disabled Tools", + "description": "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.", + "type": "array", + "items": { + "type": "string" + }, + "uniqueItems": true, + "uiFieldType": "treeSelect", + "expandAllValue": true, + "default": [] } }, "required": ["allowedOrigins"],