diff --git a/openmetadata-mcp/src/main/java/org/openmetadata/mcp/usage/McpUsageRecorder.java b/openmetadata-mcp/src/main/java/org/openmetadata/mcp/usage/McpUsageRecorder.java index 884f9e2992e0..945febedafff 100644 --- a/openmetadata-mcp/src/main/java/org/openmetadata/mcp/usage/McpUsageRecorder.java +++ b/openmetadata-mcp/src/main/java/org/openmetadata/mcp/usage/McpUsageRecorder.java @@ -40,9 +40,7 @@ public final class McpUsageRecorder { private McpUsageRecorder() {} /** - * Records a tool invocation with the full Phase 3 payload. The legacy 3-arg overload below is - * kept so existing call sites and tests compile unchanged. New call sites should call this one - * directly with the latency timer reading + error category + client name they already have. + * Records a tool invocation with the full Phase 3 payload. * * @param toolName name of the tool that was invoked * @param userName principal name from the security context @@ -90,14 +88,6 @@ public static void record( } } - /** - * Backwards-compatible overload. New call sites should use the 6-arg variant so the row gets - * the full Phase 3 payload. - */ - public static void record(String toolName, String userName, boolean success) { - record(toolName, userName, success, null, null, null); - } - private static App resolveMcpApp() { AbstractNativeApplication app = ApplicationContext.getInstance().getAppIfExists(McpAppConstants.MCP_APP_NAME); diff --git a/openmetadata-mcp/src/test/java/org/openmetadata/mcp/usage/McpUsageRecorderTest.java b/openmetadata-mcp/src/test/java/org/openmetadata/mcp/usage/McpUsageRecorderTest.java index 9425e35cc320..86ffe86bd44d 100644 --- a/openmetadata-mcp/src/test/java/org/openmetadata/mcp/usage/McpUsageRecorderTest.java +++ b/openmetadata-mcp/src/test/java/org/openmetadata/mcp/usage/McpUsageRecorderTest.java @@ -73,7 +73,7 @@ void recordWritesUsageRowWhenAppRegistered() { stubMcpApp(appId, McpAppConstants.MCP_APP_NAME); long before = System.currentTimeMillis(); - McpUsageRecorder.record("search_metadata", "alice", true); + McpUsageRecorder.record("search_metadata", "alice", true, null, null, null); long after = System.currentTimeMillis(); ArgumentCaptor json = ArgumentCaptor.forClass(String.class); @@ -102,7 +102,7 @@ void recordWritesUsageRowWhenAppRegistered() { void serializedJsonContainsGeneratedColumnFieldNames() { stubMcpApp(UUID.randomUUID(), McpAppConstants.MCP_APP_NAME); - McpUsageRecorder.record("any_tool", "alice", true); + McpUsageRecorder.record("any_tool", "alice", true, null, null, null); ArgumentCaptor json = ArgumentCaptor.forClass(String.class); verify(dao).insert(json.capture(), eq("limits")); @@ -117,7 +117,7 @@ void serializedJsonContainsGeneratedColumnFieldNames() { void recordSkipsWhenMcpApplicationNotInitialized() { when(appContext.getAppIfExists(McpAppConstants.MCP_APP_NAME)).thenReturn(null); - McpUsageRecorder.record("any_tool", "alice", true); + McpUsageRecorder.record("any_tool", "alice", true, null, null, null); verify(dao, never()).insert(anyString(), anyString()); } @@ -127,7 +127,7 @@ void recordSwallowsDaoException() { stubMcpApp(UUID.randomUUID(), McpAppConstants.MCP_APP_NAME); doThrow(new RuntimeException("db down")).when(dao).insert(anyString(), eq("limits")); - McpUsageRecorder.record("create_entity", "alice", false); + McpUsageRecorder.record("create_entity", "alice", false, null, null, null); verify(dao, times(1)).insert(anyString(), eq("limits")); } @@ -136,7 +136,7 @@ void recordSwallowsDaoException() { void recordCapturesFailureFlag() { stubMcpApp(UUID.randomUUID(), McpAppConstants.MCP_APP_NAME); - McpUsageRecorder.record("patch_entity", "bob", false); + McpUsageRecorder.record("patch_entity", "bob", false, null, null, null); ArgumentCaptor json = ArgumentCaptor.forClass(String.class); verify(dao).insert(json.capture(), eq("limits")); @@ -159,20 +159,6 @@ void recordCapturesPhase3Metadata() { assertThat(decoded.getClientName()).isEqualTo("Claude Desktop"); } - @Test - void legacy3ArgOverloadOmitsPhase3Fields() { - stubMcpApp(UUID.randomUUID(), McpAppConstants.MCP_APP_NAME); - - McpUsageRecorder.record("search_metadata", "alice", true); - - ArgumentCaptor json = ArgumentCaptor.forClass(String.class); - verify(dao).insert(json.capture(), eq("limits")); - McpToolCallUsage decoded = JsonUtils.readValue(json.getValue(), McpToolCallUsage.class); - assertThat(decoded.getLatencyMs()).isNull(); - assertThat(decoded.getErrorCategory()).isNull(); - assertThat(decoded.getClientName()).isNull(); - } - private void stubMcpApp(UUID appId, String appName) { AbstractNativeApplication nativeApp = mock(AbstractNativeApplication.class); App app = new App().withId(appId).withName(appName);