Skip to content

Commit 7f2012e

Browse files
committed
Restore DI-based MCP protocol ObjectMapper with FAIL_ON_UNKNOWN_PROPERTIES
Re-introduce the @McpProtocolObjectMapper qualifier annotation and Guice binding (from the first commit of this PR) instead of inline new ObjectMapper() instances. This centralizes configuration in McpServerModule and makes the mapper injectable/testable. The binding now includes FAIL_ON_UNKNOWN_PROPERTIES=false to handle forward-compatible fields from newer MCP clients. Workaround for modelcontextprotocol/java-sdk#766 Remove once the SDK adds @JsonIgnoreProperties(ignoreUnknown=true) to its capability records. Co-Authored-By: Claude Opus 4.6 <[EMAIL_ADDRESS_REDACTED]>
1 parent f7b20d5 commit 7f2012e

6 files changed

Lines changed: 60 additions & 7 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (C) 2020 Graylog, Inc.
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the Server Side Public License, version 1,
6+
* as published by MongoDB, Inc.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* Server Side Public License for more details.
12+
*
13+
* You should have received a copy of the Server Side Public License
14+
* along with this program. If not, see
15+
* <http://www.mongodb.com/licensing/server-side-public-license>.
16+
*/
17+
package org.graylog.mcp.server;
18+
19+
import com.google.inject.BindingAnnotation;
20+
21+
import java.lang.annotation.Retention;
22+
import java.lang.annotation.Target;
23+
24+
import static java.lang.annotation.ElementType.FIELD;
25+
import static java.lang.annotation.ElementType.METHOD;
26+
import static java.lang.annotation.ElementType.PARAMETER;
27+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
28+
29+
/**
30+
* Qualifier annotation for the ObjectMapper used to deserialize MCP protocol messages.
31+
* This mapper is a plain ObjectMapper configured with FAIL_ON_UNKNOWN_PROPERTIES=false,
32+
* unlike the global Graylog ObjectMapper which adds SnakeCaseStrategy and custom modules
33+
* that interfere with the MCP SDK's own Jackson annotations.
34+
*
35+
* Workaround for <a href="https://github.com/modelcontextprotocol/java-sdk/issues/766">java-sdk#766</a>.
36+
* Remove once the SDK adds @JsonIgnoreProperties(ignoreUnknown=true) to its capability records.
37+
*/
38+
@BindingAnnotation
39+
@Target({FIELD, PARAMETER, METHOD})
40+
@Retention(RUNTIME)
41+
public @interface McpProtocolObjectMapper {
42+
}

‎graylog2-server/src/main/java/org/graylog/mcp/server/McpRestResource.java‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717
package org.graylog.mcp.server;
1818

19-
import com.fasterxml.jackson.databind.DeserializationFeature;
2019
import com.fasterxml.jackson.databind.JsonNode;
2120
import com.fasterxml.jackson.databind.ObjectMapper;
2221
import io.modelcontextprotocol.spec.McpError;
@@ -65,8 +64,7 @@ public class McpRestResource extends RestResource {
6564
private static final String HEADER_MCP_SESSION_ID = "Mcp-Session-Id";
6665
private static final String HEADER_MCP_PROTOCOL_VERSION = "MCP-Protocol-Version";
6766

68-
private final ObjectMapper protocolObjectMapper = new ObjectMapper()
69-
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
67+
private final ObjectMapper protocolObjectMapper;
7068

7169
private final McpService mcpService;
7270

@@ -75,9 +73,10 @@ public class McpRestResource extends RestResource {
7573
private final ClusterConfigService clusterConfig;
7674

7775
@Inject
78-
public McpRestResource(final ClusterConfigService clusterConfig, final McpService mcpService, final SecurityContext securityContext) {
76+
public McpRestResource(final ClusterConfigService clusterConfig, final McpService mcpService, @McpProtocolObjectMapper final ObjectMapper protocolObjectMapper, final SecurityContext securityContext) {
7977
this.clusterConfig = clusterConfig;
8078
this.mcpService = mcpService;
79+
this.protocolObjectMapper = protocolObjectMapper;
8180
this.securityContext = securityContext;
8281
}
8382

‎graylog2-server/src/main/java/org/graylog/mcp/server/McpServerModule.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*/
1717
package org.graylog.mcp.server;
1818

19+
import com.fasterxml.jackson.databind.DeserializationFeature;
20+
import com.fasterxml.jackson.databind.ObjectMapper;
1921
import org.graylog.mcp.resources.DashboardResourceProvider;
2022
import org.graylog.mcp.resources.EventDefinitionResourceProvider;
2123
import org.graylog.mcp.resources.StreamResourceProvider;
@@ -36,6 +38,12 @@
3638
public class McpServerModule extends PluginModule {
3739
@Override
3840
protected void configure() {
41+
// Workaround for https://github.com/modelcontextprotocol/java-sdk/issues/766
42+
// Remove once the SDK adds @JsonIgnoreProperties(ignoreUnknown=true) to capability records.
43+
bind(ObjectMapper.class).annotatedWith(McpProtocolObjectMapper.class)
44+
.toInstance(new ObjectMapper()
45+
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false));
46+
3947
// Initialize schema module binder (empty set by default, plugins can contribute)
4048
schemaModuleBinder();
4149

‎graylog2-server/src/main/java/org/graylog/mcp/server/McpService.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import com.fasterxml.jackson.core.JsonProcessingException;
2020
import com.fasterxml.jackson.core.type.TypeReference;
21-
import com.fasterxml.jackson.databind.DeserializationFeature;
2221
import com.fasterxml.jackson.databind.ObjectMapper;
2322
import com.google.common.collect.Maps;
2423
import io.modelcontextprotocol.spec.McpError;
@@ -60,8 +59,7 @@ public class McpService {
6059
static final List<String> ALL_SUPPORTED_MCP_VERSIONS = List.of(LATEST_SUPPORTED_MCP_VERSION);
6160

6261
private final ObjectMapper objectMapper;
63-
private final ObjectMapper protocolObjectMapper = new ObjectMapper()
64-
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
62+
private final ObjectMapper protocolObjectMapper;
6563
private final AuditEventSender auditEventSender;
6664
private final CustomizationConfig customizationConfig;
6765
private final GRNRegistry grnRegistry;
@@ -70,12 +68,14 @@ public class McpService {
7068

7169
@Inject
7270
protected McpService(ObjectMapper objectMapper,
71+
@McpProtocolObjectMapper ObjectMapper protocolObjectMapper,
7372
AuditEventSender auditEventSender,
7473
CustomizationConfig customizationConfig,
7574
GRNRegistry grnRegistry,
7675
Map<String, Tool<?, ?>> tools,
7776
Map<GRNType, ? extends ResourceProvider> resourceProviders) {
7877
this.objectMapper = objectMapper;
78+
this.protocolObjectMapper = protocolObjectMapper;
7979
this.auditEventSender = auditEventSender;
8080
this.customizationConfig = customizationConfig;
8181
this.grnRegistry = grnRegistry;

‎graylog2-server/src/test/java/org/graylog/mcp/server/McpRestResourceTest.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*/
1717
package org.graylog.mcp.server;
1818

19+
import com.fasterxml.jackson.databind.DeserializationFeature;
20+
import com.fasterxml.jackson.databind.ObjectMapper;
1921
import jakarta.ws.rs.core.Response;
2022
import org.graylog.mcp.config.McpConfiguration;
2123
import org.graylog.security.certutil.InMemoryClusterConfigService;
@@ -34,6 +36,7 @@ public static void setUp() throws Exception {
3436
// we have to create mocks for the rest, too
3537
resource = new McpRestResource(clusterConfigService,
3638
null,
39+
new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false),
3740
null);
3841
clusterConfigService.write(McpConfiguration.create(false, false));
3942
}

‎graylog2-server/src/test/java/org/graylog/mcp/server/McpServiceTest.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ void setUp() {
8080
when(user.getName()).thenReturn("testuser");
8181

8282
mcpService = new McpService(
83+
objectMapper,
8384
objectMapper,
8485
auditEventSender,
8586
new CustomizationConfig(null),

0 commit comments

Comments
 (0)