This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch feat/mcp-sdk-1.0.0
in repository
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mcp-server.git
The following commit(s) were added to refs/heads/feat/mcp-sdk-1.0.0 by this
push:
new 5c1e237 fix: use references to services instead of static access to
McpJsonDefaults
5c1e237 is described below
commit 5c1e237f2f6e70efd15ddf0c3c2399c86a8a90aa
Author: Robert Munteanu <[email protected]>
AuthorDate: Thu Mar 12 14:58:53 2026 +0100
fix: use references to services instead of static access to McpJsonDefaults
This makes the McpServlet more resilient to service startup order.
---
.../java/org/apache/sling/mcp/server/impl/McpServlet.java | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/src/main/java/org/apache/sling/mcp/server/impl/McpServlet.java
b/src/main/java/org/apache/sling/mcp/server/impl/McpServlet.java
index 8aa953d..668d583 100644
--- a/src/main/java/org/apache/sling/mcp/server/impl/McpServlet.java
+++ b/src/main/java/org/apache/sling/mcp/server/impl/McpServlet.java
@@ -28,7 +28,8 @@ import java.util.List;
import java.util.Map;
import io.modelcontextprotocol.common.McpTransportContext;
-import io.modelcontextprotocol.json.McpJsonDefaults;
+import io.modelcontextprotocol.json.McpJsonMapperSupplier;
+import io.modelcontextprotocol.json.schema.JsonSchemaValidatorSupplier;
import io.modelcontextprotocol.server.McpServer;
import io.modelcontextprotocol.server.McpStatelessRequestHandler;
import
io.modelcontextprotocol.server.McpStatelessServerFeatures.SyncPromptSpecification;
@@ -95,12 +96,14 @@ public class McpServlet extends SlingAllMethodsServlet {
public McpServlet(
BundleContext ctx,
Config config,
+ @Reference McpJsonMapperSupplier jsonMapperSupplier,
+ @Reference JsonSchemaValidatorSupplier jsonSchemaValidatorSupplier,
@Reference(cardinality = MULTIPLE, policyOption = GREEDY)
List<McpServerContribution> contributions)
throws IllegalAccessException, NoSuchMethodException {
transportProvider = HttpServletStatelessServerTransport.builder()
.messageEndpoint(ENDPOINT)
- .jsonMapper(McpJsonDefaults.getMapper())
+ .jsonMapper(jsonMapperSupplier.get())
.contextExtractor(request -> McpTransportContext.create(Map.of(
"resourceResolver",
((BridgedJakartaHttpServletRequest) request)
@@ -138,8 +141,8 @@ public class McpServlet extends SlingAllMethodsServlet {
syncServer = McpServer.sync(transportProvider)
.serverInfo(config.serverTitle(), serverVersion)
- .jsonMapper(McpJsonDefaults.getMapper())
- .jsonSchemaValidator(McpJsonDefaults.getSchemaValidator())
+ .jsonMapper(jsonMapperSupplier.get())
+ .jsonSchemaValidator(jsonSchemaValidatorSupplier.get())
.instructions(config.instructions())
.completions(completions)
.capabilities(ServerCapabilities.builder()