@@ -391,14 +391,23 @@ private void writeJson(HttpServletResponse response, int status, JSONRPCResponse
391391 /**
392392 * Validates {@code Mcp-Method}, {@code MCP-Protocol-Version} and, for the three named
393393 * methods, {@code Mcp-Name} against the request body.
394+ * <p>
395+ * Each of these headers must carry exactly one value. Intermediaries disagree on
396+ * which copy of a repeated header counts (the first, the last, or all of them joined
397+ * with {@code ", "}), so accepting a repeated header would let a request be routed or
398+ * authorized on one value while the server validates another.
394399 * @return a human-readable mismatch description, or {@code null} if the headers are
395400 * consistent with the body
396401 */
397402 private String validateHeaders (HttpServletRequest request , JSONRPCRequest jsonRpcRequest ) {
398- String methodHeader = request .getHeader ("Mcp-Method" );
399- if (methodHeader == null ) {
403+ List < String > methodHeaders = Collections . list ( request .getHeaders ("Mcp-Method" ) );
404+ if (methodHeaders . isEmpty () ) {
400405 return "Missing required header: Mcp-Method" ;
401406 }
407+ if (methodHeaders .size () > 1 ) {
408+ return "Mcp-Method header has more than one value" ;
409+ }
410+ String methodHeader = methodHeaders .get (0 );
402411 if (!methodHeader .equals (jsonRpcRequest .method ())) {
403412 return "Mcp-Method header does not match request method" ;
404413 }
@@ -407,10 +416,14 @@ private String validateHeaders(HttpServletRequest request, JSONRPCRequest jsonRp
407416 // which answers it with -32602.
408417 String bodyVersion = protocolVersionFromMeta (jsonRpcRequest .params ());
409418 if (bodyVersion != null ) {
410- String versionHeader = request .getHeader ("MCP-Protocol-Version" );
411- if (versionHeader == null ) {
419+ List < String > versionHeaders = Collections . list ( request .getHeaders ("MCP-Protocol-Version" ) );
420+ if (versionHeaders . isEmpty () ) {
412421 return "Missing required header: MCP-Protocol-Version" ;
413422 }
423+ if (versionHeaders .size () > 1 ) {
424+ return "MCP-Protocol-Version header has more than one value" ;
425+ }
426+ String versionHeader = versionHeaders .get (0 );
414427 if (!versionHeader .equals (bodyVersion )) {
415428 return "MCP-Protocol-Version header does not match _meta protocol version" ;
416429 }
@@ -427,10 +440,14 @@ private String validateHeaders(HttpServletRequest request, JSONRPCRequest jsonRp
427440 if (!(paramsMap .get (nameKey ) instanceof String expectedName )) {
428441 return null ;
429442 }
430- String nameHeader = request .getHeader ("Mcp-Name" );
431- if (nameHeader == null ) {
443+ List < String > nameHeaders = Collections . list ( request .getHeaders ("Mcp-Name" ) );
444+ if (nameHeaders . isEmpty () ) {
432445 return "Missing required header: Mcp-Name" ;
433446 }
447+ if (nameHeaders .size () > 1 ) {
448+ return "Mcp-Name header has more than one value" ;
449+ }
450+ String nameHeader = nameHeaders .get (0 );
434451 String decoded = McpHeaderDecoder .decodeValue (nameHeader );
435452 if (decoded == null ) {
436453 return "Mcp-Name header has a malformed value" ;
0 commit comments