modelcontextprotocol / modelcontextprotocol/java-sdk

io.modelcontextprotocol.util.Utils#resolveUri incorrectly handles nested paths

Abierto
#257 3 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

area/client enhancement help wanted P2
Lenguaje dominante
Java
Estrellas
3.7k
Forks
1.1k
Merge medio
1 d 15 h
PR fusionados (30 d)
9

Descripción

Please do a quick search on GitHub issues first, there might be already a duplicate issue for the one you are about to create.
If the bug is trivial, just go ahead and create the issue. Otherwise, please take a few moments and fill in the following sections:

Bug description

It took me four hours to locate and fix this Bug,
When I create a simple link, it always reminds me of http status 302. Finally, it was located that the SSE MCP Server of the business side was redirected.

Environment
Please provide as many details as possible: Spring MCP version, Java version, which vector store you use if any, etc

Java SDK

Steps to reproduce
It's very simple. When you have an SSE MCP SERVER but the interface does not end with /sse, an error will definitely be reported when creating the connection.

Expected behavior

Adapt to the SSE MCP SERVER with non-standard users

I first fork and change the IO. Modelcontextprotocol. Util. Utils# resolveUri logic is as follows

old code

	public static URI resolveUri(URI baseUrl, String endpointUrl) {
		URI endpointUri = URI.create(endpointUrl);
		if (endpointUri.isAbsolute() && !isUnderBaseUri(baseUrl, endpointUri)) {
			throw new IllegalArgumentException("Absolute endpoint URL does not match the base URL.");
		}
		else {
			return baseUrl.resolve(endpointUri);
		}
	}

new code

	public static URI resolveUri(URI baseUrl, String endpointUrl) {
		if (endpointUrl.equals(DEFAULT_SSE_ENDPOINT)) {
			return baseUrl;
		}
		else {
			URI endpointUri = URI.create(endpointUrl);
			return baseUrl.resolve(endpointUri);
		}
	}

Minimal Complete Reproducible example
You only need to replace the following URL with a URL that does not end with SSE, and it can be reproduced

import io.modelcontextprotocol.client.McpClient;
import io.modelcontextprotocol.client.McpSyncClient;
import io.modelcontextprotocol.client.transport.HttpClientSseClientTransport;
import io.modelcontextprotocol.spec.McpSchema;
import org.junit.Test;

import java.time.Duration;

public class SSEClientTest {
	private String youUrl = "https://host:port/aaa/bbb/cccc";

	@Test
	public void testSSE() {
		mockSSEClient(youUrl);
	}

	/**
	 * Test MCP Client
	 */
	private void mockSSEClient(String url) {
		McpSyncClient client = McpClient.sync(create(url))
			.requestTimeout(Duration.ofSeconds(3))
			.initializationTimeout(Duration.ofSeconds(1))
			.capabilities(McpSchema.ClientCapabilities.builder().build())
			.build();

		client.initialize();
		for (McpSchema.Tool tool : client.listTools().tools()) {
			System.out.println(" Tool :" + tool);
		}

	}

	private HttpClientSseClientTransport create(String url) {
		return HttpClientSseClientTransport.builder(url).build();
	}
}

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza en io.modelcontextprotocol.util.Utils#resolveUri e inspecciona cómo se resuelven la URL base y la URL del endpoint para rutas anidadas. Ejecuta la reproducción proporcionada de SSEClientTest con una URL de servidor SSE que no termine en /sse; se considera terminado cuando el cliente se conecta correctamente sin el error relacionado con la redirección indicado.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
java
Área
api, networking
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Tranquilo
Claridad
Bastante claro
Aptitud para principiantes
48/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.