|
35 | 35 | import com.github.copilot.sdk.json.AgentInfo; |
36 | 36 | import com.github.copilot.sdk.json.GetMessagesResponse; |
37 | 37 | import com.github.copilot.sdk.json.HookInvocation; |
| 38 | +import com.github.copilot.sdk.json.McpServerInfo; |
38 | 39 | import com.github.copilot.sdk.json.MessageOptions; |
39 | 40 | import com.github.copilot.sdk.json.PermissionHandler; |
40 | 41 | import com.github.copilot.sdk.json.PermissionInvocation; |
@@ -1275,6 +1276,74 @@ public CompletableFuture<Void> compact() { |
1275 | 1276 | return rpc.invoke("session.compaction.compact", Map.of("sessionId", sessionId), Void.class); |
1276 | 1277 | } |
1277 | 1278 |
|
| 1279 | + /** |
| 1280 | + * Lists the MCP servers configured for this session, including their connection |
| 1281 | + * status. |
| 1282 | + * |
| 1283 | + * @return a future that resolves with the list of MCP server info objects |
| 1284 | + * @throws IllegalStateException |
| 1285 | + * if this session has been terminated |
| 1286 | + * @since 1.0.0 |
| 1287 | + */ |
| 1288 | + public CompletableFuture<List<McpServerInfo>> listMcpServers() { |
| 1289 | + ensureNotTerminated(); |
| 1290 | + return rpc.invoke("session.mcp.list", Map.of("sessionId", sessionId), McpListResponse.class) |
| 1291 | + .thenApply(response -> response.servers() != null |
| 1292 | + ? Collections.unmodifiableList(response.servers()) |
| 1293 | + : Collections.emptyList()); |
| 1294 | + } |
| 1295 | + |
| 1296 | + /** |
| 1297 | + * Enables a previously disabled MCP server in this session. |
| 1298 | + * |
| 1299 | + * @param serverName |
| 1300 | + * the name of the MCP server to enable (the key used in the |
| 1301 | + * {@link com.github.copilot.sdk.json.SessionConfig#setMcpServers(java.util.Map)} |
| 1302 | + * map) |
| 1303 | + * @return a future that completes when the server has been enabled |
| 1304 | + * @throws IllegalStateException |
| 1305 | + * if this session has been terminated |
| 1306 | + * @since 1.0.0 |
| 1307 | + */ |
| 1308 | + public CompletableFuture<Void> enableMcpServer(String serverName) { |
| 1309 | + ensureNotTerminated(); |
| 1310 | + return rpc.invoke("session.mcp.enable", Map.of("sessionId", sessionId, "serverName", serverName), Void.class); |
| 1311 | + } |
| 1312 | + |
| 1313 | + /** |
| 1314 | + * Disables an MCP server in this session without removing its configuration. |
| 1315 | + * <p> |
| 1316 | + * A disabled server can be re-enabled later via |
| 1317 | + * {@link #enableMcpServer(String)}. |
| 1318 | + * |
| 1319 | + * @param serverName |
| 1320 | + * the name of the MCP server to disable |
| 1321 | + * @return a future that completes when the server has been disabled |
| 1322 | + * @throws IllegalStateException |
| 1323 | + * if this session has been terminated |
| 1324 | + * @since 1.0.0 |
| 1325 | + */ |
| 1326 | + public CompletableFuture<Void> disableMcpServer(String serverName) { |
| 1327 | + ensureNotTerminated(); |
| 1328 | + return rpc.invoke("session.mcp.disable", Map.of("sessionId", sessionId, "serverName", serverName), Void.class); |
| 1329 | + } |
| 1330 | + |
| 1331 | + /** |
| 1332 | + * Reloads all MCP servers in this session. |
| 1333 | + * <p> |
| 1334 | + * This disconnects and reconnects all configured MCP servers, which can be |
| 1335 | + * useful to pick up configuration changes or recover from failed connections. |
| 1336 | + * |
| 1337 | + * @return a future that completes when the reload is initiated |
| 1338 | + * @throws IllegalStateException |
| 1339 | + * if this session has been terminated |
| 1340 | + * @since 1.0.0 |
| 1341 | + */ |
| 1342 | + public CompletableFuture<Void> reloadMcpServers() { |
| 1343 | + ensureNotTerminated(); |
| 1344 | + return rpc.invoke("session.mcp.reload", Map.of("sessionId", sessionId), Void.class); |
| 1345 | + } |
| 1346 | + |
1278 | 1347 | /** |
1279 | 1348 | * Verifies that this session has not yet been terminated. |
1280 | 1349 | * |
@@ -1330,4 +1399,10 @@ private record AgentGetCurrentResponse(@JsonProperty("agent") AgentInfo agent) { |
1330 | 1399 | private record AgentSelectResponse(@JsonProperty("agent") AgentInfo agent) { |
1331 | 1400 | } |
1332 | 1401 |
|
| 1402 | + // ===== Internal response types for MCP API ===== |
| 1403 | + |
| 1404 | + @JsonIgnoreProperties(ignoreUnknown = true) |
| 1405 | + private record McpListResponse(@JsonProperty("servers") List<McpServerInfo> servers) { |
| 1406 | + } |
| 1407 | + |
1333 | 1408 | } |
0 commit comments