You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2026/08/12 02:36:59 UTC
(shardingsphere) branch master updated: Centralize MCP protocol version and sharding property guidance (#39413)
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 f7830b90737 Centralize MCP protocol version and sharding property guidance (#39413)
f7830b90737 is described below
commit f7830b90737090085f46a8824f303fa68e97cf36
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Wed Aug 12 10:36:53 2026 +0800
Centralize MCP protocol version and sharding property guidance (#39413)
* Implement MySQLPacketPayload.writeInt6()
Write six-byte fixed-length integers in little-endian order and add wire-format coverage for high-bit and maximum values.
* Centralize MCP protocol version and sharding property guidance
---
.../tool/service/ShardingInspectionService.java | 17 +++++++++--------
.../tool/service/ShardingInspectionServiceTest.java | 18 +++++++++++++-----
.../mcp/functionality/MCPClientTransportFactory.java | 4 ++--
.../transport/MCPInteractionProtocolSupport.java | 3 ++-
4 files changed, 26 insertions(+), 16 deletions(-)
diff --git a/mcp/features/sharding/src/main/java/org/apache/shardingsphere/mcp/feature/sharding/tool/service/ShardingInspectionService.java b/mcp/features/sharding/src/main/java/org/apache/shardingsphere/mcp/feature/sharding/tool/service/ShardingInspectionService.java
index 42a7c101e31..05508c775a1 100644
--- a/mcp/features/sharding/src/main/java/org/apache/shardingsphere/mcp/feature/sharding/tool/service/ShardingInspectionService.java
+++ b/mcp/features/sharding/src/main/java/org/apache/shardingsphere/mcp/feature/sharding/tool/service/ShardingInspectionService.java
@@ -18,8 +18,10 @@
package org.apache.shardingsphere.mcp.feature.sharding.tool.service;
import org.apache.shardingsphere.mcp.support.database.spi.MCPFeatureQueryFacade;
+import org.apache.shardingsphere.mcp.support.workflow.model.AlgorithmPropertyRequirement;
import org.apache.shardingsphere.mcp.support.workflow.service.WorkflowSQLUtils;
+import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
@@ -30,6 +32,8 @@ import java.util.Map;
*/
public final class ShardingInspectionService {
+ private final ShardingAlgorithmPropertyTemplateService algorithmPropertyTemplateService = new ShardingAlgorithmPropertyTemplateService();
+
/**
* Query DistSQL-visible sharding algorithm plugins.
*
@@ -295,14 +299,11 @@ public final class ShardingInspectionService {
}
private String resolveShardingAlgorithmGuidance(final String algorithmType) {
- String actualType = algorithmType.trim().toUpperCase(Locale.ENGLISH);
- if (actualType.contains("INLINE")) {
- return "Usually requires algorithm-expression.";
- }
- if ("MOD".equals(actualType)) {
- return "Usually requires sharding-count.";
- }
- return "Read the plugin documentation for required properties before planning.";
+ Collection<String> requiredProperties = algorithmPropertyTemplateService.findAlgorithmRequirements(algorithmType).stream()
+ .filter(AlgorithmPropertyRequirement::isRequired).map(AlgorithmPropertyRequirement::getPropertyKey).toList();
+ return requiredProperties.isEmpty()
+ ? "Read the plugin documentation for required properties before planning."
+ : String.format("Usually requires %s.", String.join(", ", requiredProperties));
}
private String resolveKeyGeneratorGuidance(final String algorithmType) {
diff --git a/mcp/features/sharding/src/test/java/org/apache/shardingsphere/mcp/feature/sharding/tool/service/ShardingInspectionServiceTest.java b/mcp/features/sharding/src/test/java/org/apache/shardingsphere/mcp/feature/sharding/tool/service/ShardingInspectionServiceTest.java
index e367e180605..c8234c30cf0 100644
--- a/mcp/features/sharding/src/test/java/org/apache/shardingsphere/mcp/feature/sharding/tool/service/ShardingInspectionServiceTest.java
+++ b/mcp/features/sharding/src/test/java/org/apache/shardingsphere/mcp/feature/sharding/tool/service/ShardingInspectionServiceTest.java
@@ -30,7 +30,6 @@ import java.util.Map;
import java.util.stream.Stream;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.eq;
@@ -48,12 +47,13 @@ class ShardingInspectionServiceTest {
verify(queryFacade).query(eq("logic_db"), eq(expectedSQL));
}
- @Test
- void assertQueryAlgorithmPlugins() {
+ @ParameterizedTest(name = "{0}")
+ @MethodSource("assertQueryAlgorithmPluginsArguments")
+ void assertQueryAlgorithmPlugins(final String name, final String algorithmType, final String expectedPropertyGuidance) {
MCPFeatureQueryFacade queryFacade = mock(MCPFeatureQueryFacade.class);
- when(queryFacade.queryWithAnyDatabase("SHOW SHARDING ALGORITHM PLUGINS")).thenReturn(List.of(Map.of("type", "INLINE")));
+ when(queryFacade.queryWithAnyDatabase("SHOW SHARDING ALGORITHM PLUGINS")).thenReturn(List.of(Map.of("type", algorithmType)));
List<Map<String, Object>> actual = new ShardingInspectionService().queryAlgorithmPlugins(queryFacade);
- assertThat(actual.getFirst().get("property_guidance").toString(), containsString("algorithm-expression"));
+ assertThat(actual.getFirst().get("property_guidance").toString(), is(expectedPropertyGuidance));
}
@Test
@@ -84,6 +84,14 @@ class ShardingInspectionServiceTest {
assertThat(actual, is(expected));
}
+ private static Stream<Arguments> assertQueryAlgorithmPluginsArguments() {
+ return Stream.of(
+ Arguments.of("inline", "INLINE", "Usually requires algorithm-expression."),
+ Arguments.of("mod", "MOD", "Usually requires sharding-count."),
+ Arguments.of("hash mod", "HASH_MOD", "Usually requires sharding-count."),
+ Arguments.of("unknown inline", "CUSTOM_INLINE", "Read the plugin documentation for required properties before planning."));
+ }
+
private static Stream<Arguments> assertDatabaseScopedQueryArguments() {
return Stream.of(
Arguments.of("algorithms", (QueryInvocation) (service, facade) -> service.queryAlgorithms(facade, "logic_db"),
diff --git a/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/functionality/MCPClientTransportFactory.java b/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/functionality/MCPClientTransportFactory.java
index 252b4dc8b39..f8405413fa4 100644
--- a/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/functionality/MCPClientTransportFactory.java
+++ b/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/functionality/MCPClientTransportFactory.java
@@ -26,9 +26,9 @@ import io.modelcontextprotocol.client.transport.ServerParameters;
import io.modelcontextprotocol.client.transport.StdioClientTransport;
import io.modelcontextprotocol.spec.McpClientTransport;
import io.modelcontextprotocol.spec.McpSchema;
-import io.modelcontextprotocol.spec.ProtocolVersions;
import org.apache.shardingsphere.mcp.bootstrap.MCPBootstrap;
import org.apache.shardingsphere.mcp.bootstrap.transport.MCPTransportJsonMapperFactory;
+import org.apache.shardingsphere.test.e2e.mcp.support.transport.MCPInteractionProtocolSupport;
import org.apache.shardingsphere.test.e2e.mcp.support.transport.client.MCPStdioLogbackConfiguration;
import java.io.IOException;
@@ -44,7 +44,7 @@ final class MCPClientTransportFactory {
private static final String STDIO_LOGBACK_CONFIG_FILE_NAME = "mcp-functionality-e2e-sdk-stdio-logback.xml";
- private static final List<String> SUPPORTED_PROTOCOL_VERSIONS = List.of(ProtocolVersions.MCP_2025_11_25);
+ private static final List<String> SUPPORTED_PROTOCOL_VERSIONS = List.of(MCPInteractionProtocolSupport.PROTOCOL_VERSION);
static McpSyncClient createElicitationClient(final McpClientTransport clientTransport, final List<McpSchema.ElicitRequest> elicitationRequests,
final BiFunction<List<McpSchema.ElicitRequest>, McpSchema.ElicitRequest, McpSchema.ElicitResult> elicitationHandler) {
diff --git a/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/support/transport/MCPInteractionProtocolSupport.java b/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/support/transport/MCPInteractionProtocolSupport.java
index aae1726eaae..4e9fe46a35e 100644
--- a/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/support/transport/MCPInteractionProtocolSupport.java
+++ b/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/support/transport/MCPInteractionProtocolSupport.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.test.e2e.mcp.support.transport;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
+import io.modelcontextprotocol.spec.ProtocolVersions;
import org.apache.shardingsphere.infra.util.json.JsonUtils;
import java.util.LinkedHashMap;
@@ -30,7 +31,7 @@ import java.util.Map;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class MCPInteractionProtocolSupport {
- public static final String PROTOCOL_VERSION = "2025-11-25";
+ public static final String PROTOCOL_VERSION = ProtocolVersions.MCP_2025_11_25;
/**
* Create initialize request parameters for the given client name.