This is an automated email from the ASF dual-hosted git repository.
epugh pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr-mcp.git
The following commit(s) were added to refs/heads/main by this push:
new 582490b fix(config): accept text/plain content-type in
JsonResponseParser (#90)
582490b is described below
commit 582490beba81f482e5e3f3bdada8db31e80fd973
Author: Yunus Emre KORKMAZ <[email protected]>
AuthorDate: Fri Jun 19 19:32:31 2026 +0300
fix(config): accept text/plain content-type in JsonResponseParser (#90)
Some Solr request handlers (notably `/admin/ping` and certain
standalone-mode paths) return JSON-encoded bodies with a
`Content-Type: text/plain` header. SolrJ validates the response
Content-Type against the set advertised by the configured
`ResponseParser` and fails otherwise-valid responses with
"Expected mime type in [application/json] but got text/plain",
which surfaces through MCP tools such as `check-health` and
`search` as errors even though the payload is a correct Solr
JSON response.
Widen `JsonResponseParser#getContentTypes()` to advertise both
`application/json` and `text/plain` so these responses are parsed
normally. No behavioural change for handlers that return
`application/json`.
Adds `JsonResponseParserContentTypesTest` pinning the advertised
set.
Signed-off-by: Yunus Emre Korkmaz <[email protected]>
Co-authored-by: Claude <[email protected]>
---
.../solr/mcp/server/config/JsonResponseParser.java | 5 ++-
.../config/JsonResponseParserContentTypesTest.java | 51 ++++++++++++++++++++++
2 files changed, 55 insertions(+), 1 deletion(-)
diff --git
a/src/main/java/org/apache/solr/mcp/server/config/JsonResponseParser.java
b/src/main/java/org/apache/solr/mcp/server/config/JsonResponseParser.java
index a78e3ab..235b57a 100644
--- a/src/main/java/org/apache/solr/mcp/server/config/JsonResponseParser.java
+++ b/src/main/java/org/apache/solr/mcp/server/config/JsonResponseParser.java
@@ -81,7 +81,10 @@ class JsonResponseParser extends ResponseParser {
@Override
public Collection<String> getContentTypes() {
- return List.of(MediaType.APPLICATION_JSON_VALUE);
+ // Some Solr endpoints (notably /admin/ping and some
standalone-mode handlers)
+ // return JSON-encoded bodies with Content-Type: text/plain.
Accept it so SolrJ
+ // does not reject otherwise-valid responses.
+ return List.of(MediaType.APPLICATION_JSON_VALUE,
MediaType.TEXT_PLAIN_VALUE);
}
@Override
diff --git
a/src/test/java/org/apache/solr/mcp/server/config/JsonResponseParserContentTypesTest.java
b/src/test/java/org/apache/solr/mcp/server/config/JsonResponseParserContentTypesTest.java
new file mode 100644
index 0000000..81181d3
--- /dev/null
+++
b/src/test/java/org/apache/solr/mcp/server/config/JsonResponseParserContentTypesTest.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.mcp.server.config;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.util.Collection;
+import org.junit.jupiter.api.Test;
+import org.springframework.http.MediaType;
+
+/**
+ * Unit tests verifying the Content-Types accepted by
+ * {@link JsonResponseParser}.
+ *
+ * <p>
+ * Some Solr request handlers (notably {@code /admin/ping} and certain
+ * standalone-mode paths) return JSON-encoded bodies with Content-Type
+ * {@code text/plain} rather than {@code application/json}. SolrJ rejects the
+ * response unless the configured
+ * {@link org.apache.solr.client.solrj.response.ResponseParser} advertises that
+ * Content-Type, so the parser must tolerate both.
+ */
+class JsonResponseParserContentTypesTest {
+
+ @Test
+ void advertisesJsonAndTextPlain() {
+ JsonResponseParser parser = new JsonResponseParser(new
ObjectMapper());
+
+ Collection<String> contentTypes = parser.getContentTypes();
+
+
assertTrue(contentTypes.contains(MediaType.APPLICATION_JSON_VALUE),
+ "Parser must advertise application/json so
SolrJ accepts standard Solr responses");
+ assertTrue(contentTypes.contains(MediaType.TEXT_PLAIN_VALUE),
+ "Parser must advertise text/plain so SolrJ
accepts responses from handlers that mislabel JSON bodies");
+ }
+}