modelcontextprotocol / modelcontextprotocol/java-sdk
io.modelcontextprotocol.util.Utils#resolveUri incorrectly handles nested paths
还没有人认领这个 Issue。
- 主要语言
- Java
- 星标
- 3.7k
- 派生
- 1.1k
- 平均合并
- 1 天 15 小时
- 30 天内合并 PR
- 9
描述
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();
}
}
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 io.modelcontextprotocol.util.Utils#resolveUri 开始,检查嵌套路径的基础 URL 和端点 URL 是如何解析的。使用一个不以 /sse 结尾的 SSE 服务器 URL 运行提供的 SSEClientTest 复现;当客户端能够成功连接且不再出现报告的重定向相关错误时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- java
- 领域
- api, networking
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 48/100