This chapter is for developers who want to extend ShardingSphere-MCP. For installation and usage, see the User Manual. For the protocol surface, see the Reference.
The MCP path is organized as api + support + features + core + bootstrap:
mcp/api: public MCP capability contracts, descriptor types, protocol responses, MCP protocol exceptions, and SPI entry points.mcp/support: database metadata, execution, capability, workflow contexts, models, facades, database/workflow SPIs, and reusable helpers.mcp/features/encrypt: Encrypt MCP feature.mcp/features/mask: Mask MCP feature.mcp/features/broadcast: Broadcast MCP feature.mcp/features/readwrite-splitting: Readwrite-Splitting MCP feature.mcp/features/shadow: Shadow MCP feature.mcp/features/sharding: Sharding MCP feature.mcp/core: handler discovery, registry, request context, session, metadata discovery, and runtime context.mcp/bootstrap: MCP Java SDK based bootstrap, HTTP/STDIO transport, configuration loading, and lifecycle management.mcp/registry: isolated distribution metadata validation tooling; it does not depend on MCP runtime modules.distribution/mcp: standalone packaging, startup scripts, configuration, and Dockerfile.test/e2e/mcp: end-to-end contract validation.The production dependency direction is api <- support <- core <- bootstrap and api <- support <- feature.
Feature modules do not depend on core, bootstrap, registry, or one another. mcp/bootstrap only publishes the aggregated protocol surface and does not hard-code concrete feature business logic.
Public server capability contracts are organized under org.apache.shardingsphere.mcp.api.capability.<capability>, while the ServiceLoader entry interface is
org.apache.shardingsphere.mcp.api.MCPHandlerProvider. Request contexts, sessions, transports, payloads, and exceptions are cross-capability or base-protocol contracts and stay outside capability packages.
Recommended path for a new feature:
mcp/features/<feature>.mcp/api.mcp/support when database metadata, SQL execution, or workflow support is needed.mcp/core or mcp/bootstrap; runtime implementations are not feature extension contracts.MCPHandlerProvider.getToolHandlers() and getResourceHandlers().MCPWorkflowDefinitionProvider on the same provider.org.apache.shardingsphere.mcp.api.MCPHandlerProvider under src/main/resources/META-INF/services/.META-INF/shardingsphere-mcp/mcp-descriptors.If the feature should be shipped as an official default capability:
mcp/features/pom.xml.distribution/mcp/pom.xml.If the feature is optional, place the built jar under the distribution plugins/ directory.
Features that plan, preview, apply, and validate rule changes should use the Data Encryption MCP feature’s rule workflow as the template. The template implementation should satisfy:
mcp/features/<feature>; mcp/support and mcp/core should only host generic workflow, execution, redaction, descriptor, and runtime contracts.approved_steps.When adding a public tool:
MCPToolHandler<T extends MCPRequestContext>.handle(...) returns only a successful MCPSuccessPayload. For controlled failures such as invalid arguments, missing resources, query failure, timeout, or unsupported operations, throw the corresponding ShardingSphereMCPException subclass and let runtime convert it to an MCP tool error result. Unexpected runtime failures are sanitized as JSON-RPC internal errors.When adding a public resource:
MCPResourceHandler<T extends MCPRequestContext>.handle(...) returns only a successful MCPSuccessPayload. Do not build error payloads in handlers; throw the corresponding ShardingSphereMCPException subclass and let runtime convert it to an MCP resource read error. Unexpected runtime failures are sanitized as JSON-RPC internal errors.When runtime code needs the descriptor for a handler, resolve it from MCPDescriptorCatalogIndex by canonical tool name or resource URI template.
Do not duplicate descriptor fields inside handlers.
MCPRequestContext when a handler only needs the session identity or active transport. It exposes exactly getSessionIdentity() and getActiveTransport().MCPFeatureRequestContext when a handler or completion provider needs database metadata, execution, or workflow capabilities.MCPSessionIdentity contains the opaque session ID together with optional trusted subject, source, and attributes; read the ID through getSessionIdentity().getSessionId(). Attribution describes where a session came from and is not an authentication or authorization result.
MCPFeatureRuntimeRequestContext is the runtime-owned, per-request implementation. Handlers and completion providers depend only on context interfaces, not on the core implementation class.
Completion requests use a per-session 60-second fixed-window rate limit. The default is 600 requests per minute and can be changed with the
shardingsphere.mcp.maxCompletionRequestsPerMinute Java system property.
shardingsphere://features/<feature>/... namespace.Descriptors should explain how models should use the protocol surface, not merely repeat tool names or URIs.
Maintain:
Tool annotations are only client hints. They do not replace runtime validation, SQL safety checks, user approval, or server-side authorization.
