adityamparikh opened a new pull request, #320:
URL: https://github.com/apache/solr-mcp/pull/320

   ## Summary
   
   Every tool now reports a Solr failure as a tool error (`isError: true`) 
instead of a JSON-RPC protocol error, and the error text keeps Solr's reason 
but drops the Solr host and URL. This is group 7 (design D9) of the 
`typed-mcp-contracts` OpenSpec change.
   
   Stacked on #313, so the diff also contains groups 1–6. This PR's own commits:
   
   - 
https://github.com/apache/solr-mcp/pull/PRNUM/commits/fbf9b57b9a39d2c6c703675315d0d45cb8938b6f
 adds `util/SolrCalls`, the one helper that runs a Solr call and translates 
SolrJ's failures.
   - 
https://github.com/apache/solr-mcp/pull/PRNUM/commits/dee3901ba5df8408bd5e2aba66543849196e42fa
 routes the Solr calls of all 16 tools through it and removes `throws 
SolrServerException, IOException` from every `@McpTool` method.
   - 
https://github.com/apache/solr-mcp/pull/PRNUM/commits/646b4eecb9058438c13aaed037990532daad0a28
 adds failure conformance tests on both protocols.
   - 
https://github.com/apache/solr-mcp/pull/PRNUM/commits/7ac8d04dc0114f91baa3bb87ffc187e4eb8fb1f8
 updates the 1.0.0 changelog and the "MCP contracts" section of `AGENTS.md`.
   
   **Why.** Spring AI 2.1 turns a `RuntimeException` from an `@McpTool` method 
into an `isError` result. It rethrows a declared checked exception, though, and 
the client then gets a bare `-32603 Internal error` (#213). That is what 
happened to every tool whenever Solr was unreachable. The [MCP annotations 
docs](https://docs.spring.io/spring-ai/reference/2.0-SNAPSHOT/api/mcp/mcp-annotations-server.html)
 say to convert the failure to a `RuntimeException` in the method body, so the 
tools do that through one shared helper. There is no AOP aspect (#273).
   
   **Error rules** (`SolrCalls`). The text starts with the operation, e.g. 
`Creating the alias failed: `, and continues:
   
   | SolrJ failure | Rest of the error text | Exception |
   |---|---|---|
   | `SolrException` 404 | the tool's own hint, e.g. `collection 'x' was not 
found. Hint: call list-collections ...` | `IllegalArgumentException` |
   | 401 / 403 | Solr denied access | `IllegalStateException` |
   | any other 4xx | `Solr returned an error: <Solr's reason>`, then the tool's 
hint (`search` keeps its list-fields and Lucene-syntax hints) | 
`IllegalArgumentException` |
   | 5xx | Solr's reason, then a hint to ask the operator | 
`IllegalStateException` |
   | `HttpTimeoutException` in the cause chain | Solr did not answer in time | 
`IllegalStateException` |
   | any other `SolrServerException` / `IOException` | Solr could not be 
reached | `IllegalStateException` |
   
   - **How Solr's reason is extracted.** Both `RemoteSolrException` 
constructors in SolrJ 10.0.0 write `"Error from server at " + remoteHost` 
first. The one that takes a message then adds `": " + msg`. The one that takes 
Solr's error object adds `": "` plus the error's class and message, or nothing 
at all when the error has neither. `remoteHost` is the request URL, which 
cannot contain a literal space, so the first `": "` after the prefix ends the 
host. Every occurrence of the prefix is removed, including one quoted inside 
the reason by a node that forwarded the request to another node. Any other 
`http(s)://` URL left in the reason is replaced with `<url>`.
   - **No cause.** The translated exception carries no cause, because 
`AbstractSyncMcpToolMethodCallback.createSyncErrorResult` appends the root 
cause's message to the error text. The original exception is logged at `warn`.
   - **Exceptions to the rule.** `check-health` still returns its fixed 
`HealthStatus.Reason` (D5). The three resources still use their own fixed text 
(#275). Completions catch the translated exceptions and return no suggestions, 
as they did before.
   - **Other fixes.** `get-collection-stats` used to attach the 404 as the 
cause of its `IllegalArgumentException`, so Spring AI appended the URL to the 
error text. That cause is gone.
   
   ## Evidence
   
   - `./gradlew spotlessApply build`: 700 JVM tests, 0 failures, 0 errors, 0 
skipped. The baseline at 2d529387 was 620.
   - `./gradlew nativeTest -Pnative`: 691 found, 474 passed, 0 failed. The 217 
skipped are the `@DisabledInNativeImage` Mockito tests. The baseline was 396 
passed. The new `SolrCallsTest` and both Solr-unreachable tests run natively.
   - `SolrCallsTest` builds every failure with SolrJ 10's real constructors, 
using the messages `HttpJdkSolrClient` and `HttpSolrClientBase` produce. It 
asserts the exact message, that there is no cause, and that no host, URL or 
`Error from server at` appears.
   - Failure conformance tests run on both protocols:
     - On a running Solr, each of the 14 tools that names a target is called 
with one that does not exist: a missing collection, `create-alias` pointing at 
a missing collection, `delete-alias` on a missing alias, and 
`create-collection` with a missing configset.
     - With `solr.url` pointing at a closed port, all 16 tools are called.
     - Each call must return `isError: true`, never a JSON-RPC error, and no 
text block may contain `Error from server at`, `http://` or `https://`. 
`check-health` must instead report `COLLECTION_NOT_FOUND` or `SOLR_UNREACHABLE`.
     - The application starts without Solr.
   - **The test catches a regression.** With `create-collection`'s translation 
undone locally (the call made directly, `throws` restored), 4 tests failed, one 
per protocol and context:
     - Missing configset, legacy and modern: the text was `Error from server at 
http://localhost:59304/solr/admin/collections: Can not find the specified 
config set: ...`.
     - Solr unreachable, legacy: `McpError: JSONRPCError[code=-32603, 
message=Internal error]`.
     - Solr unreachable, modern: `{"error":{"code":-32603,"message":"Internal 
error"}}`.
   
     Restoring the translation made all four pass again.
   - `SearchServiceIntegrationTest` covers the spec's "Solr rejects a request" 
scenario against a real Solr. Sorting on an undefined field returns text that 
includes Solr's reason (it names the field), the list-fields hint, and no 
`Error from server at` or `http://`.
   
   ## Merge Danger
   
   - **The tool error text changes.** Clients see Solr's reason for a refused 
request (spec requirement "Error text does not carry Solr internals"), where 
the `search` tool used to return only fixed text. A Solr reason can name a 
node-local path. It never contains the host: the prefix and URLs are removed, 
and `solr.url` rejects user info (#277).
   - **The exception types change.** Tool methods now throw 
`IllegalArgumentException` or `IllegalStateException` instead of 
`SolrServerException`, `IOException` or `SolrException`. Java callers of the 
service methods, such as tests and other services, see the new types.
   - **Merge after #313.** This PR includes its commits.
   
   Closes #213.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to