CAMEL-23476: camel-jbang-mcp: strip null fields from MCP JSON responses#23169
Merged
Conversation
Configures the Quarkus Jackson ObjectMapper with serialization-inclusion=non-null so the @tool result records serialized via JsonTextContentEncoder no longer emit fields with null values, reducing LLM context-window pressure for every caller of the camel-jbang-mcp server. Signed-off-by: Andrea Cosentino <ancosen@gmail.com>
Contributor
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
Contributor
|
🧪 CI tested the following changed modules:
|
davsclaus
approved these changes
May 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Configures the Quarkus Jackson
ObjectMapperfor thecamel-jbang-mcpmodulewith
quarkus.jackson.serialization-inclusion=non-nullso the@Toolresultrecords serialized via
JsonTextContentEncoderno longer emit fields withnullvalues.This reduces LLM context-window pressure for every caller of the
camel-jbang-mcp server. The module exposes 31 tools, 6 resources and 3 prompts,
so per-call token bloat from useless
\"field\": nullentries adds up quickly.Closes CAMEL-23476.
Why this works
io.quarkiverse.mcp.server.runtime.JsonTextContentEncoder(the default contentencoder used for arbitrary objects returned from
@Toolmethods) injects thedefault Quarkus
ObjectMapperand callswriteValueAsString(...)on it.Quarkus' built-in
io.quarkus.jackson.runtime.ConfigurationCustomizer(priority
Integer.MAX_VALUE) readsJacksonBuildTimeConfig.serializationInclusion()and invokes
setSerializationInclusion(...)on thatObjectMapper, so thesingle property line is enough to strip nulls from every result the MCP server
emits.
The framework already ships an
McpObjectMapperCustomizerthat adds a@JsonInclude(NON_NULL)mixin to MCP envelope types (ToolResponse,PromptResponse, etc.), but not to application-level result records likeComponentDetailResultorOptionInfo— which is the bug filed in the JIRA.Changes
application.properties: addquarkus.jackson.serialization-inclusion=non-nullMcpJsonSerializationTest: new test verifyingapplication.propertiesComponentInfo,OptionInfoandComponentDetailResultinstances withnull fields produce JSON that omits those fields
Test plan
mvn -pl dsl/camel-jbang/camel-jbang-mcp test— 231 tests pass (227 existing + 4 new)mvn clean install -DskipTestsfrom the repo root — full reactor build greenClaude Code on behalf of Andrea Cosentino