Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@ spring-ai-alibaba-jmanus/ui-vue3/pnpm-lock.yaml

# MCP configuration files
modified_mcp_config.json
.cursorindexingignore
14 changes: 14 additions & 0 deletions spring-ai-alibaba-jmanus/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,19 @@
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-mcp-client-webflux</artifactId>
</dependency>

<!-- MCP SDK -->
<dependency>
<groupId>io.modelcontextprotocol.sdk</groupId>
<artifactId>mcp</artifactId>
<version>0.11.0</version>
</dependency>
<dependency>
<groupId>io.modelcontextprotocol.sdk</groupId>
<artifactId>mcp-spring-webflux</artifactId>
<version>0.11.0</version>
</dependency>

<!--
<dependency>
<groupId>com.alibaba.cloud.ai</groupId>
Expand Down Expand Up @@ -273,6 +286,7 @@
<version>2.15.1</version>
</dependency>
</dependencies>


<build>
<finalName>jmanus</finalName>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.List;
import java.util.Map;

import io.modelcontextprotocol.client.transport.WebClientStreamableHttpTransport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
Expand All @@ -28,7 +29,6 @@
import com.alibaba.cloud.ai.example.manus.dynamic.mcp.config.McpProperties;
import com.alibaba.cloud.ai.example.manus.dynamic.mcp.model.po.McpConfigType;
import com.alibaba.cloud.ai.example.manus.dynamic.mcp.model.vo.McpServerConfig;
import com.alibaba.cloud.ai.example.manus.dynamic.mcp.transport.StreamableHttpClientTransport;
import com.fasterxml.jackson.databind.ObjectMapper;

import io.modelcontextprotocol.client.transport.ServerParameters;
Expand Down Expand Up @@ -172,10 +172,35 @@ private McpClientTransport buildStreamingTransport(McpServerConfig serverConfig,
String url = serverConfig.getUrl().trim();
configValidator.validateUrl(url, serverName);

logger.info("Building Streamable HTTP transport for server: {} with URL: {}", serverName, url);
URL parsedUrl = new URL(url);
String baseUrl = parsedUrl.getProtocol() + "://" + parsedUrl.getHost()
+ (parsedUrl.getPort() == -1 ? "" : ":" + parsedUrl.getPort());

String streamEndpoint = parsedUrl.getPath();

// Remove leading slash
if (streamEndpoint.startsWith("/")) {
streamEndpoint = streamEndpoint.substring(1);
}

// Set to null if empty
if (streamEndpoint.isEmpty()) {
streamEndpoint = null;
}

logger.info("Building Streamable HTTP transport for server: {} with Url: {} and Endpoint: {}", serverName,
baseUrl, streamEndpoint);

WebClient.Builder webClientBuilder = createWebClientBuilder(baseUrl);

logger.debug("Using WebClientStreamableHttpTransport with endpoint: {} for STREAMING mode", streamEndpoint);
return WebClientStreamableHttpTransport.builder(webClientBuilder)
.objectMapper(objectMapper)
.endpoint(streamEndpoint)
.resumableStreams(true)
.openConnectionOnStartup(false)
.build();

WebClient.Builder webClientBuilder = createWebClientBuilder();
return new StreamableHttpClientTransport(webClientBuilder, objectMapper, url);
}

/**
Expand All @@ -188,17 +213,9 @@ private WebClient.Builder createWebClientBuilder(String baseUrl) {
.baseUrl(baseUrl)
.defaultHeader("Accept", "text/event-stream")
.defaultHeader("Content-Type", "application/json")
.defaultHeader("User-Agent", mcpProperties.getUserAgent());
}
.defaultHeader("User-Agent", mcpProperties.getUserAgent())
.codecs(configurer -> configurer.defaultCodecs().maxInMemorySize(1024 * 1024 * 10));

/**
* Create WebClient builder (without baseUrl)
* @return WebClient builder
*/
private WebClient.Builder createWebClientBuilder() {
return WebClient.builder()
.defaultHeader("Accept", "application/json, text/event-stream")
.defaultHeader("Content-Type", "application/json");
}

}
Loading
Loading