Skip to content

Commit 89cc261

Browse files
Copilotedburns
andauthored
Port enableConfigDiscovery, ModelCapabilitiesOverride, McpServerConfig types, and setModel overload
Agent-Logs-Url: https://github.com/github/copilot-sdk-java/sessions/6440ac65-a609-41e9-8afc-718bccbef08a Co-authored-by: edburns <75821+edburns@users.noreply.github.com>
1 parent dfe8b17 commit 89cc261

17 files changed

+798
-34
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Java SDK for programmatic control of GitHub Copilot CLI, enabling you to build A
2525
### Requirements
2626

2727
- Java 17 or later. **JDK 25 recommended**. Selecting JDK 25 enables the use of virtual threads, as shown in the [Quick Start](#quick-start).
28-
- GitHub Copilot CLI 1.0.17 or later installed and in `PATH` (or provide custom `cliPath`)
28+
- GitHub Copilot CLI 1.0.22 or later installed and in `PATH` (or provide custom `cliPath`)
2929

3030
### Maven
3131

src/main/java/com/github/copilot/sdk/CopilotSession.java

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import com.github.copilot.sdk.json.HookInvocation;
5454
import com.github.copilot.sdk.json.InputOptions;
5555
import com.github.copilot.sdk.json.MessageOptions;
56+
import com.github.copilot.sdk.json.ModelCapabilitiesOverride;
5657
import com.github.copilot.sdk.json.PermissionHandler;
5758
import com.github.copilot.sdk.json.PermissionInvocation;
5859
import com.github.copilot.sdk.json.PermissionRequest;
@@ -1496,13 +1497,46 @@ public CompletableFuture<Void> abort() {
14961497
* @since 1.2.0
14971498
*/
14981499
public CompletableFuture<Void> setModel(String model, String reasoningEffort) {
1500+
return setModel(model, reasoningEffort, null);
1501+
}
1502+
1503+
/**
1504+
* Changes the model for this session with optional reasoning effort level and
1505+
* model capabilities overrides.
1506+
* <p>
1507+
* The new model takes effect for the next message. Conversation history is
1508+
* preserved.
1509+
*
1510+
* <pre>{@code
1511+
* session.setModel("claude-sonnet-4.5", null,
1512+
* new ModelCapabilitiesOverride().setSupports(new ModelCapabilitiesOverrideSupports().setVision(true))).get();
1513+
* }</pre>
1514+
*
1515+
* @param model
1516+
* the model ID to switch to (e.g., {@code "gpt-4.1"})
1517+
* @param reasoningEffort
1518+
* reasoning effort level (e.g., {@code "low"}, {@code "medium"},
1519+
* {@code "high"}, {@code "xhigh"}); {@code null} to use default
1520+
* @param modelCapabilities
1521+
* per-property overrides for model capabilities, deep-merged over
1522+
* runtime defaults; {@code null} to use runtime defaults
1523+
* @return a future that completes when the model switch is acknowledged
1524+
* @throws IllegalStateException
1525+
* if this session has been terminated
1526+
* @since 1.4.0
1527+
*/
1528+
public CompletableFuture<Void> setModel(String model, String reasoningEffort,
1529+
ModelCapabilitiesOverride modelCapabilities) {
14991530
ensureNotTerminated();
15001531
var params = new java.util.HashMap<String, Object>();
15011532
params.put("sessionId", sessionId);
15021533
params.put("modelId", model);
15031534
if (reasoningEffort != null) {
15041535
params.put("reasoningEffort", reasoningEffort);
15051536
}
1537+
if (modelCapabilities != null) {
1538+
params.put("modelCapabilities", modelCapabilities);
1539+
}
15061540
return rpc.invoke("session.model.switchTo", params, Void.class);
15071541
}
15081542

@@ -1524,7 +1558,7 @@ public CompletableFuture<Void> setModel(String model, String reasoningEffort) {
15241558
* @since 1.0.11
15251559
*/
15261560
public CompletableFuture<Void> setModel(String model) {
1527-
return setModel(model, null);
1561+
return setModel(model, null, null);
15281562
}
15291563

15301564
/**

src/main/java/com/github/copilot/sdk/SessionRequestBuilder.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ static CreateSessionRequest buildCreateRequest(SessionConfig config, String sess
122122
request.setSkillDirectories(config.getSkillDirectories());
123123
request.setDisabledSkills(config.getDisabledSkills());
124124
request.setConfigDir(config.getConfigDir());
125+
request.setEnableConfigDiscovery(config.getEnableConfigDiscovery());
126+
request.setModelCapabilities(config.getModelCapabilities());
125127

126128
if (config.getCommands() != null && !config.getCommands().isEmpty()) {
127129
var wireCommands = config.getCommands().stream()
@@ -193,6 +195,8 @@ static ResumeSessionRequest buildResumeRequest(String sessionId, ResumeSessionCo
193195
request.setSkillDirectories(config.getSkillDirectories());
194196
request.setDisabledSkills(config.getDisabledSkills());
195197
request.setInfiniteSessions(config.getInfiniteSessions());
198+
request.setEnableConfigDiscovery(config.getEnableConfigDiscovery());
199+
request.setModelCapabilities(config.getModelCapabilities());
196200

197201
if (config.getCommands() != null && !config.getCommands().isEmpty()) {
198202
var wireCommands = config.getCommands().stream()

src/main/java/com/github/copilot/sdk/json/CreateSessionRequest.java

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public final class CreateSessionRequest {
6868
private Boolean streaming;
6969

7070
@JsonProperty("mcpServers")
71-
private Map<String, Object> mcpServers;
71+
private Map<String, McpServerConfig> mcpServers;
7272

7373
@JsonProperty("envValueMode")
7474
private String envValueMode;
@@ -91,6 +91,12 @@ public final class CreateSessionRequest {
9191
@JsonProperty("configDir")
9292
private String configDir;
9393

94+
@JsonProperty("enableConfigDiscovery")
95+
private Boolean enableConfigDiscovery;
96+
97+
@JsonProperty("modelCapabilities")
98+
private ModelCapabilitiesOverride modelCapabilities;
99+
94100
@JsonProperty("commands")
95101
private List<CommandWireDefinition> commands;
96102

@@ -240,12 +246,12 @@ public void setStreaming(Boolean streaming) {
240246
}
241247

242248
/** Gets MCP servers. @return the servers map */
243-
public Map<String, Object> getMcpServers() {
249+
public Map<String, McpServerConfig> getMcpServers() {
244250
return mcpServers == null ? null : Collections.unmodifiableMap(mcpServers);
245251
}
246252

247253
/** Sets MCP servers. @param mcpServers the servers map */
248-
public void setMcpServers(Map<String, Object> mcpServers) {
254+
public void setMcpServers(Map<String, McpServerConfig> mcpServers) {
249255
this.mcpServers = mcpServers;
250256
}
251257

@@ -319,6 +325,30 @@ public void setConfigDir(String configDir) {
319325
this.configDir = configDir;
320326
}
321327

328+
/** Gets the enableConfigDiscovery flag. @return the flag */
329+
public Boolean getEnableConfigDiscovery() {
330+
return enableConfigDiscovery;
331+
}
332+
333+
/**
334+
* Sets the enableConfigDiscovery flag. @param enableConfigDiscovery the flag
335+
*/
336+
public void setEnableConfigDiscovery(Boolean enableConfigDiscovery) {
337+
this.enableConfigDiscovery = enableConfigDiscovery;
338+
}
339+
340+
/** Gets the model capabilities override. @return the override */
341+
public ModelCapabilitiesOverride getModelCapabilities() {
342+
return modelCapabilities;
343+
}
344+
345+
/**
346+
* Sets the model capabilities override. @param modelCapabilities the override
347+
*/
348+
public void setModelCapabilities(ModelCapabilitiesOverride modelCapabilities) {
349+
this.modelCapabilities = modelCapabilities;
350+
}
351+
322352
/** Gets the commands wire definitions. @return the commands */
323353
public List<CommandWireDefinition> getCommands() {
324354
return commands == null ? null : Collections.unmodifiableList(commands);

src/main/java/com/github/copilot/sdk/json/CustomAgentConfig.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class CustomAgentConfig {
5050
private String prompt;
5151

5252
@JsonProperty("mcpServers")
53-
private Map<String, Object> mcpServers;
53+
private Map<String, McpServerConfig> mcpServers;
5454

5555
@JsonProperty("infer")
5656
private Boolean infer;
@@ -175,7 +175,7 @@ public CustomAgentConfig setPrompt(String prompt) {
175175
*
176176
* @return the MCP servers map
177177
*/
178-
public Map<String, Object> getMcpServers() {
178+
public Map<String, McpServerConfig> getMcpServers() {
179179
return mcpServers == null ? null : Collections.unmodifiableMap(mcpServers);
180180
}
181181

@@ -186,7 +186,7 @@ public Map<String, Object> getMcpServers() {
186186
* the MCP server configurations
187187
* @return this config for method chaining
188188
*/
189-
public CustomAgentConfig setMcpServers(Map<String, Object> mcpServers) {
189+
public CustomAgentConfig setMcpServers(Map<String, McpServerConfig> mcpServers) {
190190
this.mcpServers = mcpServers;
191191
return this;
192192
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
*--------------------------------------------------------------------------------------------*/
4+
5+
package com.github.copilot.sdk.json;
6+
7+
import java.util.Map;
8+
9+
import com.fasterxml.jackson.annotation.JsonInclude;
10+
import com.fasterxml.jackson.annotation.JsonProperty;
11+
12+
/**
13+
* Configuration for a remote HTTP/SSE MCP server.
14+
* <p>
15+
* Use this class to configure an MCP server accessed via HTTP or Server-Sent
16+
* Events.
17+
*
18+
* <h2>Example</h2>
19+
*
20+
* <pre>{@code
21+
* var server = new McpHttpServerConfig().setUrl("https://example.com/mcp")
22+
* .setHeaders(Map.of("Authorization", "Bearer token")).setTools(List.of("*"));
23+
* }</pre>
24+
*
25+
* @see McpServerConfig
26+
* @since 1.4.0
27+
*/
28+
@JsonInclude(JsonInclude.Include.NON_NULL)
29+
public final class McpHttpServerConfig extends McpServerConfig {
30+
31+
@JsonProperty("url")
32+
private String url;
33+
34+
@JsonProperty("headers")
35+
private Map<String, String> headers;
36+
37+
/** Returns the URL of the remote server. */
38+
public String getUrl() {
39+
return url;
40+
}
41+
42+
/**
43+
* Sets the URL of the remote server.
44+
*
45+
* @param url
46+
* the server URL
47+
* @return this instance for method chaining
48+
*/
49+
public McpHttpServerConfig setUrl(String url) {
50+
this.url = url;
51+
return this;
52+
}
53+
54+
/** Returns the optional HTTP headers to include in requests. */
55+
public Map<String, String> getHeaders() {
56+
return headers;
57+
}
58+
59+
/**
60+
* Sets optional HTTP headers to include in requests.
61+
*
62+
* @param headers
63+
* HTTP header map
64+
* @return this instance for method chaining
65+
*/
66+
public McpHttpServerConfig setHeaders(Map<String, String> headers) {
67+
this.headers = headers;
68+
return this;
69+
}
70+
71+
@Override
72+
public McpHttpServerConfig setTools(java.util.List<String> tools) {
73+
super.setTools(tools);
74+
return this;
75+
}
76+
77+
@Override
78+
public McpHttpServerConfig setTimeout(Integer timeout) {
79+
super.setTimeout(timeout);
80+
return this;
81+
}
82+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
*--------------------------------------------------------------------------------------------*/
4+
5+
package com.github.copilot.sdk.json;
6+
7+
import java.util.List;
8+
9+
import com.fasterxml.jackson.annotation.JsonInclude;
10+
import com.fasterxml.jackson.annotation.JsonProperty;
11+
import com.fasterxml.jackson.annotation.JsonSubTypes;
12+
import com.fasterxml.jackson.annotation.JsonTypeInfo;
13+
14+
/**
15+
* Abstract base class for MCP server configurations.
16+
* <p>
17+
* Use {@link McpStdioServerConfig} for local/stdio MCP servers or
18+
* {@link McpHttpServerConfig} for remote HTTP/SSE MCP servers.
19+
*
20+
* <h2>Example: Local server</h2>
21+
*
22+
* <pre>{@code
23+
* var servers = Map.of("my-server",
24+
* new McpStdioServerConfig().setCommand("node").setArgs(List.of("mcp-server.js")).setTools(List.of("*")));
25+
* var session = client.createSession(new SessionConfig().setMcpServers(servers)).get();
26+
* }</pre>
27+
*
28+
* <h2>Example: Remote server</h2>
29+
*
30+
* <pre>{@code
31+
* var servers = Map.of("remote-server",
32+
* new McpHttpServerConfig().setUrl("https://example.com/mcp").setTools(List.of("*")));
33+
* var session = client.createSession(new SessionConfig().setMcpServers(servers)).get();
34+
* }</pre>
35+
*
36+
* @see McpStdioServerConfig
37+
* @see McpHttpServerConfig
38+
* @see SessionConfig#setMcpServers(java.util.Map)
39+
* @since 1.4.0
40+
*/
41+
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type", defaultImpl = McpStdioServerConfig.class)
42+
@JsonSubTypes({@JsonSubTypes.Type(value = McpStdioServerConfig.class, name = "stdio"),
43+
@JsonSubTypes.Type(value = McpHttpServerConfig.class, name = "http")})
44+
@JsonInclude(JsonInclude.Include.NON_NULL)
45+
public abstract class McpServerConfig {
46+
47+
@JsonProperty("tools")
48+
private List<String> tools;
49+
50+
@JsonProperty("timeout")
51+
private Integer timeout;
52+
53+
/**
54+
* Private constructor to prevent direct subclassing outside this package.
55+
*/
56+
McpServerConfig() {
57+
}
58+
59+
/**
60+
* Returns the list of tools to include from this server. An empty list means
61+
* none; use {@code "*"} for all.
62+
*/
63+
public List<String> getTools() {
64+
return tools;
65+
}
66+
67+
/**
68+
* Sets the list of tools to include from this server. Use {@code "*"} to
69+
* include all tools.
70+
*
71+
* @param tools
72+
* tool names, or {@code List.of("*")} for all
73+
* @return this instance for method chaining
74+
*/
75+
public McpServerConfig setTools(List<String> tools) {
76+
this.tools = tools;
77+
return this;
78+
}
79+
80+
/**
81+
* Returns the optional timeout in milliseconds for tool calls to this server.
82+
*/
83+
public Integer getTimeout() {
84+
return timeout;
85+
}
86+
87+
/**
88+
* Sets the optional timeout in milliseconds for tool calls to this server.
89+
*
90+
* @param timeout
91+
* timeout in milliseconds, or {@code null} for no override
92+
* @return this instance for method chaining
93+
*/
94+
public McpServerConfig setTimeout(Integer timeout) {
95+
this.timeout = timeout;
96+
return this;
97+
}
98+
}

0 commit comments

Comments
 (0)