This is an automated email from the ASF dual-hosted git repository.

terrymanu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 3ea3c1bdece Rename MCPMarkdownResourceLoader.load() (#38830)
3ea3c1bdece is described below

commit 3ea3c1bdecebe7a640c5ce5f74831521a6cd9b7e
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Jun 8 18:05:56 2026 +0800

    Rename MCPMarkdownResourceLoader.load() (#38830)
---
 .../transport/server/MCPSyncServerFactory.java     |  6 +-----
 .../descriptor/MCPPromptTemplateLoader.java        |  2 +-
 .../markdown/MCPMarkdownResourceLoader.java        | 24 ++++++++--------------
 .../markdown/MCPMarkdownResourceLoaderTest.java    | 20 +++++++++---------
 .../production/ProductionMySQLRuntimeE2ETest.java  | 13 ++++++------
 5 files changed, 27 insertions(+), 38 deletions(-)

diff --git 
a/mcp/bootstrap/src/main/java/org/apache/shardingsphere/mcp/bootstrap/transport/server/MCPSyncServerFactory.java
 
b/mcp/bootstrap/src/main/java/org/apache/shardingsphere/mcp/bootstrap/transport/server/MCPSyncServerFactory.java
index e87b20dc3c7..9eb9ff9aa71 100644
--- 
a/mcp/bootstrap/src/main/java/org/apache/shardingsphere/mcp/bootstrap/transport/server/MCPSyncServerFactory.java
+++ 
b/mcp/bootstrap/src/main/java/org/apache/shardingsphere/mcp/bootstrap/transport/server/MCPSyncServerFactory.java
@@ -79,7 +79,7 @@ public final class MCPSyncServerFactory {
     private McpSyncServer create(final McpServer.SyncSpecification<?> 
specification) {
         return specification.jsonMapper(jsonMapper)
                 .serverInfo(MCPTransportConstants.SERVER_NAME, 
Optional.ofNullable(MCPSyncServerFactory.class.getPackage().getImplementationVersion()).orElse("development"))
-                .instructions(loadServerInstructions())
+                
.instructions(MCPMarkdownResourceLoader.load(MCPTransportConstants.SERVER_INSTRUCTIONS_RESOURCE,
 "server instruction"))
                 .capabilities(ServerCapabilities.builder().resources(false, 
false).tools(false).prompts(false).completions().build())
                 
.resources(resourceSpecificationFactory.createResourceSpecifications())
                 
.resourceTemplates(resourceSpecificationFactory.createResourceTemplateSpecifications())
@@ -88,8 +88,4 @@ public final class MCPSyncServerFactory {
                 
.completions(completionSpecificationFactory.createCompletionSpecifications())
                 .build();
     }
-    
-    private String loadServerInstructions() {
-        return 
MCPMarkdownResourceLoader.loadRequired(MCPTransportConstants.SERVER_INSTRUCTIONS_RESOURCE,
 "server instruction");
-    }
 }
diff --git 
a/mcp/support/src/main/java/org/apache/shardingsphere/mcp/support/descriptor/MCPPromptTemplateLoader.java
 
b/mcp/support/src/main/java/org/apache/shardingsphere/mcp/support/descriptor/MCPPromptTemplateLoader.java
index b95784fc2d4..dca78bde559 100644
--- 
a/mcp/support/src/main/java/org/apache/shardingsphere/mcp/support/descriptor/MCPPromptTemplateLoader.java
+++ 
b/mcp/support/src/main/java/org/apache/shardingsphere/mcp/support/descriptor/MCPPromptTemplateLoader.java
@@ -44,7 +44,7 @@ public final class MCPPromptTemplateLoader {
      * @throws IllegalStateException when the template cannot be loaded
      */
     public static String load(final String templateResource) {
-        return MCPMarkdownResourceLoader.loadRequired(templateResource, 
"prompt template");
+        return MCPMarkdownResourceLoader.load(templateResource, "prompt 
template");
     }
     
     /**
diff --git 
a/mcp/support/src/main/java/org/apache/shardingsphere/mcp/support/markdown/MCPMarkdownResourceLoader.java
 
b/mcp/support/src/main/java/org/apache/shardingsphere/mcp/support/markdown/MCPMarkdownResourceLoader.java
index 591ea8a36e1..ab4f6e854c9 100644
--- 
a/mcp/support/src/main/java/org/apache/shardingsphere/mcp/support/markdown/MCPMarkdownResourceLoader.java
+++ 
b/mcp/support/src/main/java/org/apache/shardingsphere/mcp/support/markdown/MCPMarkdownResourceLoader.java
@@ -19,10 +19,12 @@ package org.apache.shardingsphere.mcp.support.markdown;
 
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.infra.exception.ShardingSpherePreconditions;
 
 import java.io.IOException;
 import java.io.InputStream;
 import java.nio.charset.StandardCharsets;
+import java.util.Optional;
 
 /**
  * MCP Markdown resource loader.
@@ -39,31 +41,23 @@ public final class MCPMarkdownResourceLoader {
     private static final String APACHE_LICENSE_MARKER = "Apache License, 
Version 2.0";
     
     /**
-     * Load required Markdown resource from classpath.
+     * Load resource from classpath.
      *
      * @param resourceName resource name
      * @param resourceDescription resource description
      * @return Markdown content without source-control header
      * @throws IllegalStateException when the resource cannot be loaded or is 
blank
      */
-    public static String loadRequired(final String resourceName, final String 
resourceDescription) {
-        String result = stripSourceHeader(readResource(resourceName, 
resourceDescription, getResourceClassLoader())).strip();
-        if (result.isBlank()) {
-            throw new IllegalStateException(String.format("MCP %s resource 
`%s` is blank.", resourceDescription, resourceName));
-        }
+    public static String load(final String resourceName, final String 
resourceDescription) {
+        ClassLoader resourceClassLoader = 
Optional.ofNullable(Thread.currentThread().getContextClassLoader()).orElse(MCPMarkdownResourceLoader.class.getClassLoader());
+        String result = stripSourceHeader(load(resourceName, 
resourceDescription, resourceClassLoader)).strip();
+        ShardingSpherePreconditions.checkNotEmpty(result, () -> new 
IllegalStateException(String.format("MCP %s resource `%s` is blank.", 
resourceDescription, resourceName)));
         return result;
     }
     
-    private static ClassLoader getResourceClassLoader() {
-        ClassLoader result = Thread.currentThread().getContextClassLoader();
-        return null == result ? 
MCPMarkdownResourceLoader.class.getClassLoader() : result;
-    }
-    
-    private static String readResource(final String resourceName, final String 
resourceDescription, final ClassLoader classLoader) {
+    private static String load(final String resourceName, final String 
resourceDescription, final ClassLoader classLoader) {
         try (InputStream inputStream = 
classLoader.getResourceAsStream(resourceName)) {
-            if (null == inputStream) {
-                throw new IllegalStateException(String.format("MCP %s resource 
`%s` is not found.", resourceDescription, resourceName));
-            }
+            ShardingSpherePreconditions.checkNotNull(inputStream, () -> new 
IllegalStateException(String.format("MCP %s resource `%s` is not found.", 
resourceDescription, resourceName)));
             return new String(inputStream.readAllBytes(), 
StandardCharsets.UTF_8);
         } catch (final IOException ex) {
             throw new IllegalStateException(String.format("Failed to load MCP 
%s resource `%s`.", resourceDescription, resourceName), ex);
diff --git 
a/mcp/support/src/test/java/org/apache/shardingsphere/mcp/support/markdown/MCPMarkdownResourceLoaderTest.java
 
b/mcp/support/src/test/java/org/apache/shardingsphere/mcp/support/markdown/MCPMarkdownResourceLoaderTest.java
index 82fb11726e8..0b5a6442941 100644
--- 
a/mcp/support/src/test/java/org/apache/shardingsphere/mcp/support/markdown/MCPMarkdownResourceLoaderTest.java
+++ 
b/mcp/support/src/test/java/org/apache/shardingsphere/mcp/support/markdown/MCPMarkdownResourceLoaderTest.java
@@ -38,29 +38,29 @@ class MCPMarkdownResourceLoaderTest {
     private static final String MISSING_RESOURCE = 
"META-INF/shardingsphere-mcp/prompts/fixture-missing.md";
     
     @Test
-    void assertLoadRequired() {
-        assertThat(MCPMarkdownResourceLoader.loadRequired(TEMPLATE_RESOURCE, 
"fixture markdown"), is("Fixture template for {{database}}."));
+    void assertLoad() {
+        assertThat(MCPMarkdownResourceLoader.load(TEMPLATE_RESOURCE, "fixture 
markdown"), is("Fixture template for {{database}}."));
     }
     
     @Test
-    void assertLoadRequiredUsesFallbackClassLoader() {
+    void assertLoadUsesFallbackClassLoader() {
         assertThat(loadWithContextClassLoader(null, TEMPLATE_RESOURCE), 
is("Fixture template for {{database}}."));
     }
     
     @Test
-    void assertLoadRequiredPreservesAuthoredLeadingComment() {
+    void assertLoadPreservesAuthoredLeadingComment() {
         assertThat(loadWithContextClassLoader(new 
FixtureResourceClassLoader("fixture-authored-comment.md", "<!-- authored 
comment -->\nVisible content."), "fixture-authored-comment.md"),
                 is("<!-- authored comment -->\nVisible content."));
     }
     
     @Test
-    void assertLoadRequiredRejectsMissingResource() {
-        IllegalStateException actual = 
assertThrows(IllegalStateException.class, () -> 
MCPMarkdownResourceLoader.loadRequired(MISSING_RESOURCE, "fixture markdown"));
+    void assertLoadRejectsMissingResource() {
+        IllegalStateException actual = 
assertThrows(IllegalStateException.class, () -> 
MCPMarkdownResourceLoader.load(MISSING_RESOURCE, "fixture markdown"));
         assertThat(actual.getMessage(), is("MCP fixture markdown resource 
`META-INF/shardingsphere-mcp/prompts/fixture-missing.md` is not found."));
     }
     
     @Test
-    void assertLoadRequiredRejectsUnreadableResource() {
+    void assertLoadRejectsUnreadableResource() {
         IllegalStateException actual = 
assertThrows(IllegalStateException.class,
                 () -> loadWithContextClassLoader(new 
FixtureResourceClassLoader("fixture-unreadable.md"), "fixture-unreadable.md"));
         assertThat(actual.getMessage(), is("Failed to load MCP fixture 
markdown resource `fixture-unreadable.md`."));
@@ -68,8 +68,8 @@ class MCPMarkdownResourceLoaderTest {
     }
     
     @Test
-    void assertLoadRequiredRejectsBlankResource() {
-        IllegalStateException actual = 
assertThrows(IllegalStateException.class, () -> 
MCPMarkdownResourceLoader.loadRequired(BLANK_RESOURCE, "fixture markdown"));
+    void assertLoadRejectsBlankResource() {
+        IllegalStateException actual = 
assertThrows(IllegalStateException.class, () -> 
MCPMarkdownResourceLoader.load(BLANK_RESOURCE, "fixture markdown"));
         assertThat(actual.getMessage(), is("MCP fixture markdown resource 
`META-INF/shardingsphere-mcp/prompts/fixture-blank.md` is blank."));
     }
     
@@ -78,7 +78,7 @@ class MCPMarkdownResourceLoaderTest {
         ClassLoader originalClassLoader = 
currentThread.getContextClassLoader();
         try {
             currentThread.setContextClassLoader(classLoader);
-            return MCPMarkdownResourceLoader.loadRequired(resourceName, 
"fixture markdown");
+            return MCPMarkdownResourceLoader.load(resourceName, "fixture 
markdown");
         } finally {
             currentThread.setContextClassLoader(originalClassLoader);
         }
diff --git 
a/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/runtime/production/ProductionMySQLRuntimeE2ETest.java
 
b/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/runtime/production/ProductionMySQLRuntimeE2ETest.java
index 233b57f8a2d..165bcf7f0e0 100644
--- 
a/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/runtime/production/ProductionMySQLRuntimeE2ETest.java
+++ 
b/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/runtime/production/ProductionMySQLRuntimeE2ETest.java
@@ -17,10 +17,6 @@
 
 package org.apache.shardingsphere.test.e2e.mcp.runtime.production;
 
-import static org.hamcrest.Matchers.containsInAnyOrder;
-import static org.hamcrest.Matchers.hasItems;
-import static org.hamcrest.Matchers.is;
-
 import org.apache.shardingsphere.mcp.bootstrap.transport.MCPTransportConstants;
 import 
org.apache.shardingsphere.mcp.support.markdown.MCPMarkdownResourceLoader;
 import org.apache.shardingsphere.test.e2e.mcp.support.runtime.RuntimeTransport;
@@ -35,6 +31,9 @@ import java.util.List;
 import java.util.Map;
 
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.Matchers.hasItems;
+import static org.hamcrest.Matchers.is;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
@@ -138,7 +137,7 @@ class ProductionMySQLRuntimeE2ETest extends 
AbstractProductionMySQLRuntimeE2ETes
         try (MCPInteractionClient interactionClient = 
createOpenedInteractionClient()) {
             Map<String, Object> actualResult = 
getMap(interactionClient.getInitializePayload().get("result"));
             String actualInstructions = 
String.valueOf(actualResult.get("instructions"));
-            assertThat(actualInstructions, 
is(MCPMarkdownResourceLoader.loadRequired(MCPTransportConstants.SERVER_INSTRUCTIONS_RESOURCE,
 "server instruction")));
+            assertThat(actualInstructions, 
is(MCPMarkdownResourceLoader.load(MCPTransportConstants.SERVER_INSTRUCTIONS_RESOURCE,
 "server instruction")));
             assertThat(actualInstructions.lines().findFirst().orElse(""), 
is("Apache ShardingSphere MCP."));
         }
     }
@@ -181,7 +180,7 @@ class ProductionMySQLRuntimeE2ETest extends 
AbstractProductionMySQLRuntimeE2ETes
             List<Map<String, Object>> items = 
getPayloadItems(interactionClient.readResource(
                     
String.format("shardingsphere://databases/%s/schemas/%s/tables/orders", 
LOGICAL_DATABASE_NAME, LOGICAL_DATABASE_NAME)));
             assertThat(items.size(), is(1));
-            Map<String, Object> actualItem = items.get(0);
+            Map<String, Object> actualItem = items.getFirst();
             assertThat(String.valueOf(actualItem.get("table")), is("orders"));
             assertThat(getNestedNames(actualItem, "columns", "column"), 
is(List.of("amount", "order_id", "status")));
             assertThat(getNestedNames(actualItem, "indexes", "index"), 
containsInAnyOrder("PRIMARY", "idx_orders_status"));
@@ -207,7 +206,7 @@ class ProductionMySQLRuntimeE2ETest extends 
AbstractProductionMySQLRuntimeE2ETes
             List<Map<String, Object>> items = 
getPayloadItems(interactionClient.readResource(
                     
String.format("shardingsphere://databases/%s/schemas/%s/views", 
LOGICAL_DATABASE_NAME, LOGICAL_DATABASE_NAME)));
             assertThat(items.size(), is(1));
-            assertThat(String.valueOf(items.get(0).get("view")), 
is("active_orders"));
+            assertThat(String.valueOf(items.getFirst().get("view")), 
is("active_orders"));
         }
     }
     

Reply via email to