modelcontextprotocol / modelcontextprotocol/java-sdk
io.modelcontextprotocol.util.Utils#resolveUri incorrectly handles nested paths
まだ誰も着手していません。
- 主要言語
- Java
- スター
- 3.7k
- フォーク
- 1.1k
- 平均マージ
- 1日 15時間
- マージ済み PR(30日)
- 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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
io.modelcontextprotocol.util.Utils#resolveUri から始め、ネストされたパスに対してベース URL とエンドポイント URL がどのように解決されるかを調べます。/sse で終わらない SSE サーバー URL を使って、提供されている SSEClientTest の再現手順を実行します。クライアントが報告されたリダイレクト関連のエラーなしに正常に接続できれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- java
- 領域
- api, networking
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 静か
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 48/100