Skip to content

fix: keep Solr failure text out of MCP resource responses; drop JsonUtils - #275

Merged
epugh merged 2 commits into
apache:mainfrom
adityamparikh:refactor/inline-json-utils
Oct 26, 2026
Merged

epugh merged 2 commits into
apache:mainfrom
adityamparikh:refactor/inline-json-utils

Conversation

@adityamparikh

@adityamparikh adityamparikh commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Two related changes to the MCP resource endpoints solr://collections and solr://{collection}/schema.

Keep Solr failure text out of resource responses

Solr and SolrJ failure text can carry internal host names, URLs and paths (for example Server refused connection at: http://solr-internal:8983/solr). Both resources were passing that text to the client:

  • SchemaService.getSchemaResource returned e.getMessage() in its error JSON.
  • CollectionService.getCollectionsResource let SolrServerException / IOException escape, and MCP reports exceptions to the client by their root-cause message.

Both now follow the pattern SearchService already uses. They log the full failure on the server and throw an IllegalStateException with a fixed message, a next-step hint and no cause (SCHEMA_RESOURCE_ERROR, COLLECTIONS_RESOURCE_ERROR), so Spring AI's resource callback has no Solr failure to report. The client gets a proper MCP error. The schema resource no longer returns {"error": ...} as a successful read, which a client could not tell apart from a schema. getCollectionsResource no longer declares checked exceptions.

Tests:

  • McpClientIntegrationTestBase (HTTP and stdio) reads solr://no_such_collection_xyz/schema and asserts that the MCP error names the failure, without Error from server or an http(s):// URL. Before this change the read succeeded with {"error": "Error from server at http://…"}.
  • SchemaServiceTest and CollectionServiceTest feed a Solr failure containing an internal URL and assert that the exception carries only the fixed message and no cause. A success-path test is also added for the collections resource, which had no tests before.

Drop JsonUtils

JsonUtils.toJson(objectMapper, obj) existed to wrap Jackson 2's checked JsonProcessingException. Since the move to Jackson 3, JacksonException is unchecked. Both callers already have an ObjectMapper injected, so the three call sites now call objectMapper.writeValueAsString(...) directly. A serialization failure goes through the same safe error handling as above.

./gradlew build passes: 470 tests, 0 failures, 0 skipped. Merges cleanly with #276.

🤖 Generated with Claude Code

@adityamparikh adityamparikh changed the title refactor: drop JsonUtils and call ObjectMapper.writeValueAsString directly fix: keep Solr failure text out of MCP resource responses; drop JsonUtils Oct 21, 2026
@adityamparikh
adityamparikh force-pushed the refactor/inline-json-utils branch from 9c7b379 to 67d6c9b Compare October 21, 2026 15:14
adityamparikh and others added 2 commits October 26, 2026 15:19
…ectly

JsonUtils.toJson existed to wrap Jackson 2's checked
JsonProcessingException. Jackson 3's JacksonException is unchecked, so the
helper now only swallows serialization failures into an error JSON body,
and every caller already holds an injected ObjectMapper.

Signed-off-by: Aditya Parikh <aditya.m.parikh@gmail.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
getSchemaResource returned the exception message in its error JSON, and
getCollectionsResource let SolrServerException, IOException and
JacksonException escape. Spring AI's resource callback reports the root
cause's message to the client, and Solr and SolrJ failure text carries the
internal Solr URL ("Error from server at <url>: ...").

Both resources now log the full failure and throw an IllegalStateException
with a fixed message, a next-step hint and no cause, following
SearchService. The schema resource no longer returns {"error": ...} as a
successful read, which a client cannot tell apart from a schema.

McpClientIntegrationTestBase reads solr://no_such_collection_xyz/schema
over HTTP and stdio and asserts the MCP error names the failure without
"Error from server" or a Solr URL.

Signed-off-by: Aditya Parikh <aditya.m.parikh@gmail.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@adityamparikh
adityamparikh force-pushed the refactor/inline-json-utils branch from 67d6c9b to e66a469 Compare October 26, 2026 19:24
@sonarqubecloud

Copy link
Copy Markdown

@epugh
epugh merged commit 83ab54b into apache:main Oct 26, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants