Skip to content

Commit 084f7df

Browse files
google-genai-botcopybara-github
authored andcommitted
refactor: This change adds two things:
- McpSessionManager constructor with McpTransportBuilder parameter. - McpToolset new constructor to facilitate the creation of McpToolsets with injected McpSyncClient, so we can provide custom transport builder. PiperOrigin-RevId: 785990204
1 parent eca1bd4 commit 084f7df

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

core/src/main/java/com/google/adk/tools/mcp/McpSessionManager.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,20 @@ public class McpSessionManager {
3636

3737
private final Object connectionParams; // ServerParameters or SseServerParameters
3838
private static final Logger logger = LoggerFactory.getLogger(McpSessionManager.class);
39+
private final McpTransportBuilder transportBuilder;
3940

4041
public McpSessionManager(Object connectionParams) {
4142
this.connectionParams = connectionParams;
43+
this.transportBuilder = new DefaultMcpTransportBuilder();
44+
}
45+
46+
public McpSessionManager(Object connectionParams, McpTransportBuilder transportBuilder) {
47+
this.connectionParams = connectionParams;
48+
this.transportBuilder = transportBuilder;
4249
}
4350

4451
public McpSyncClient createSession() {
45-
return initializeSession(this.connectionParams);
52+
return initializeSession(this.connectionParams, this.transportBuilder);
4653
}
4754

4855
public static McpSyncClient initializeSession(Object connectionParams) {

core/src/main/java/com/google/adk/tools/mcp/McpToolset.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,26 @@ public McpToolset(ServerParameters connectionParams) {
149149
this(connectionParams, JsonBaseModel.getMapper(), Optional.empty());
150150
}
151151

152+
/**
153+
* Initializes the McpToolset with a McpSyncClient and McpSessionManager.
154+
*
155+
* @param objectMapper An ObjectMapper instance for parsing schemas.
156+
* @param toolFilter An Optional containing either a ToolPredicate or a List of tool names.
157+
* @param mcpSession A McpSyncClient instance for testing.
158+
* @param mcpSessionManager A McpSessionManager instance for testing.
159+
*/
160+
public McpToolset(
161+
ObjectMapper objectMapper,
162+
Optional<Object> toolFilter,
163+
McpSyncClient mcpSession,
164+
McpSessionManager mcpSessionManager) {
165+
Objects.requireNonNull(objectMapper);
166+
this.objectMapper = objectMapper;
167+
this.toolFilter = toolFilter;
168+
this.mcpSession = mcpSession;
169+
this.mcpSessionManager = mcpSessionManager;
170+
}
171+
152172
@Override
153173
public Flowable<BaseTool> getTools(ReadonlyContext readonlyContext) {
154174
return Flowable.fromCallable(

0 commit comments

Comments
 (0)