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

未關閉
#257 3 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
1-2 天
新手友好度
48/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
冷清
技術堆疊
java
領域
api, networking

研究方向

從 io.modelcontextprotocol.util.Utils#resolveUri 開始,檢查巢狀路徑的基底 URL 和端點 URL 是如何解析的。使用不以 /sse 結尾的 SSE 伺服器 URL 執行提供的 SSEClientTest 重現;當用戶端能夠成功連線且不再出現報告的重新導向相關錯誤時,即表示完成。

由索引模型根據 Issue 內容生成。

描述

area/client enhancement help wanted P2

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();
	}
}
主要語言
Java
星號
3.7k
分支
1.1k
平均合併
1 天 15 小時
30 天內合併 PR
9

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

modelcontextprotocol/java-sdk 的其他 Issue

查看 modelcontextprotocol/java-sdk 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。