#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere
TypeScript dockerhacktoberfestjavapdfpdf-converterpdf-editorpdf-manipulationpdf-mergerpdf-ocrpdf-toolspdf-web-appspdfmergerself-hosted
fix(mcp): expose convert op in stirling_convert tool with tests (#8673)
Azadand06c6efbdfd6
diff --git a/app/proprietary/src/main/java/stirling/software/proprietary/mcp/catalog/McpToolCatalog.java b/app/proprietary/src/main/java/stirling/software/proprietary/mcp/catalog/McpToolCatalog.javaindex 2821c9181f..991455056c 100644--- a/app/proprietary/src/main/java/stirling/software/proprietary/mcp/catalog/McpToolCatalog.java+++ b/app/proprietary/src/main/java/stirling/software/proprietary/mcp/catalog/McpToolCatalog.java@@ -225,16 +225,24 @@ public class McpToolCatalog {return methods.contains(RequestMethod.POST) || methods.contains(RequestMethod.PUT);}- private static String extractOpId(String pattern, OperationCategory category) {+ static String extractOpId(String pattern, OperationCategory category) {if (category.urlPrefix() == null || !pattern.startsWith(category.urlPrefix())) {return null;}String tail = pattern.substring(category.urlPrefix().length());- if (tail.isBlank() || tail.contains("/") || tail.contains("{")) {+ if (tail.isBlank() || tail.contains("{")) {// Skip nested paths and path-variable templates.return null;}- return tail;++ if (category == OperationCategory.CONVERT) {+ String[] parts = tail.split("/");+ return parts.length == 2 && !parts[0].isEmpty() && !parts[1].isEmpty()+ ? parts[0] + "-to-" + parts[1]+ : null;+ }++ return tail.contains("/") ? null : tail;}private static String prettifyOpId(String id) {diff --git a/app/proprietary/src/test/java/stirling/software/proprietary/mcp/catalog/McpToolCatalogTest.java b/app/proprietary/src/test/java/stirling/software/proprietary/mcp/catalog/McpToolCatalogTest.javaindex 71341cf6ce..6d7e9a4c78 100644--- a/app/proprietary/src/test/java/stirling/software/proprietary/mcp/catalog/McpToolCatalogTest.java+++ b/app/proprietary/src/test/java/stirling/software/proprietary/mcp/catalog/McpToolCatalogTest.java@@ -1,8 +1,6 @@package stirling.software.proprietary.mcp.catalog;-import static org.junit.jupiter.api.Assertions.assertEquals;-import static org.junit.jupiter.api.Assertions.assertFalse;-import static org.junit.jupiter.api.Assertions.assertTrue;+import static org.junit.jupiter.api.Assertions.*;import static org.mockito.ArgumentMatchers.anyString;import static org.mockito.Mockito.mock;import static org.mockito.Mockito.when;@@ -151,6 +149,33 @@ class McpToolCatalogTest {assertTrue(idsOf(catalog).contains("compress-pdf"));}+ @Test+ void extractOpId_mapsConvertPathsToFromToIds() {+ assertEquals(+ "pdf-to-word",+ McpToolCatalog.extractOpId("/api/v1/convert/pdf/word", OperationCategory.CONVERT));+ assertEquals(+ "img-to-pdf",+ McpToolCatalog.extractOpId("/api/v1/convert/img/pdf", OperationCategory.CONVERT));++ assertNull(+ McpToolCatalog.extractOpId(+ "/api/v1/convert/pdf/text-editor/page/{jobId}/{pageNumber}",+ OperationCategory.CONVERT));+ assertNull(McpToolCatalog.extractOpId("/api/v1/convert//pdf", OperationCategory.CONVERT));++ assertNull(McpToolCatalog.extractOpId("/api/v1/convert/pdf/", OperationCategory.CONVERT));+ }++ @Test+ void extractOpId_singleSegmentCategoriesUnchanged() {+ assertEquals(+ "rotate-pdf",+ McpToolCatalog.extractOpId("/api/v1/general/rotate-pdf", OperationCategory.PAGES));+ assertNull(McpToolCatalog.extractOpId("/api/v1/misc/a/b", OperationCategory.MISC));+ assertNull(McpToolCatalog.extractOpId("/api/v1/misc/{id}", OperationCategory.MISC));+ }+private McpToolCatalog catalogWithEndpointsEnabled(ApplicationProperties props) {ApplicationContext ctx = mock(ApplicationContext.class);when(ctx.getBeansOfType(RequestMappingHandlerMapping.class)).thenReturn(Map.of());