Skip to content

Commit 2a9764c

Browse files
Copilotedburns
andauthored
Port reference implementation sync: McpServerConfig types, ModelCapabilitiesOverride, agent skills, per-request headers
Agent-Logs-Url: https://github.com/github/copilot-sdk-java/sessions/514da8aa-3336-46ca-b39a-48faabcbb354 Co-authored-by: edburns <75821+edburns@users.noreply.github.com>
1 parent 391e129 commit 2a9764c

19 files changed

+1134
-64
lines changed

.lastmerge

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
c3fa6cbfb83d4a20b7912b1a17013d48f5a277a1
1+
922959f4a7b83509c3620d4881733c6c5677f00c

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@ public CompletableFuture<String> send(MessageOptions options) {
460460
request.setPrompt(options.getPrompt());
461461
request.setAttachments(options.getAttachments());
462462
request.setMode(options.getMode());
463+
request.setRequestHeaders(options.getRequestHeaders());
463464

464465
return rpc.invoke("session.send", request, SendMessageResponse.class).thenApply(SendMessageResponse::messageId);
465466
}
@@ -1552,6 +1553,51 @@ public CompletableFuture<Void> setModel(String model, String reasoningEffort) {
15521553
.thenApply(r -> null);
15531554
}
15541555

1556+
/**
1557+
* Changes the model for this session with optional reasoning effort and
1558+
* capability overrides.
1559+
* <p>
1560+
* The new model takes effect for the next message. Conversation history is
1561+
* preserved.
1562+
*
1563+
* <pre>{@code
1564+
* session.setModel("claude-sonnet-4.5", null,
1565+
* new ModelCapabilitiesOverride().setSupports(new ModelCapabilitiesOverride.Supports().setVision(false)))
1566+
* .get();
1567+
* }</pre>
1568+
*
1569+
* @param model
1570+
* the model ID to switch to (e.g., {@code "gpt-4.1"})
1571+
* @param reasoningEffort
1572+
* reasoning effort level (e.g., {@code "low"}, {@code "medium"},
1573+
* {@code "high"}, {@code "xhigh"}); {@code null} to use default
1574+
* @param modelCapabilities
1575+
* per-property overrides for model capabilities; {@code null} to use
1576+
* runtime defaults
1577+
* @return a future that completes when the model switch is acknowledged
1578+
* @throws IllegalStateException
1579+
* if this session has been terminated
1580+
* @since 1.3.0
1581+
*/
1582+
public CompletableFuture<Void> setModel(String model, String reasoningEffort,
1583+
com.github.copilot.sdk.json.ModelCapabilitiesOverride modelCapabilities) {
1584+
ensureNotTerminated();
1585+
SessionModelSwitchToParams.SessionModelSwitchToParamsModelCapabilities generatedCapabilities = null;
1586+
if (modelCapabilities != null) {
1587+
SessionModelSwitchToParams.SessionModelSwitchToParamsModelCapabilities.SessionModelSwitchToParamsModelCapabilitiesSupports supports = null;
1588+
if (modelCapabilities.getSupports() != null) {
1589+
var s = modelCapabilities.getSupports();
1590+
supports = new SessionModelSwitchToParams.SessionModelSwitchToParamsModelCapabilities.SessionModelSwitchToParamsModelCapabilitiesSupports(
1591+
s.getVision(), s.getReasoningEffort());
1592+
}
1593+
generatedCapabilities = new SessionModelSwitchToParams.SessionModelSwitchToParamsModelCapabilities(supports,
1594+
null);
1595+
}
1596+
return getRpc().model
1597+
.switchTo(new SessionModelSwitchToParams(sessionId, model, reasoningEffort, generatedCapabilities))
1598+
.thenApply(r -> null);
1599+
}
1600+
15551601
/**
15561602
* Changes the model for this session.
15571603
* <p>

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,16 @@ static CreateSessionRequest buildCreateRequest(SessionConfig config, String sess
115115
request.setHooks(config.getHooks() != null && config.getHooks().hasHooks() ? true : null);
116116
request.setWorkingDirectory(config.getWorkingDirectory());
117117
request.setStreaming(config.isStreaming() ? true : null);
118+
request.setIncludeSubAgentStreamingEvents(config.getIncludeSubAgentStreamingEvents());
118119
request.setMcpServers(config.getMcpServers());
119120
request.setCustomAgents(config.getCustomAgents());
120121
request.setAgent(config.getAgent());
121122
request.setInfiniteSessions(config.getInfiniteSessions());
122123
request.setSkillDirectories(config.getSkillDirectories());
123124
request.setDisabledSkills(config.getDisabledSkills());
124125
request.setConfigDir(config.getConfigDir());
126+
request.setEnableConfigDiscovery(config.getEnableConfigDiscovery());
127+
request.setModelCapabilities(config.getModelCapabilities());
125128

126129
if (config.getCommands() != null && !config.getCommands().isEmpty()) {
127130
var wireCommands = config.getCommands().stream()
@@ -185,14 +188,17 @@ static ResumeSessionRequest buildResumeRequest(String sessionId, ResumeSessionCo
185188
request.setHooks(config.getHooks() != null && config.getHooks().hasHooks() ? true : null);
186189
request.setWorkingDirectory(config.getWorkingDirectory());
187190
request.setConfigDir(config.getConfigDir());
191+
request.setEnableConfigDiscovery(config.getEnableConfigDiscovery());
188192
request.setDisableResume(config.isDisableResume() ? true : null);
189193
request.setStreaming(config.isStreaming() ? true : null);
194+
request.setIncludeSubAgentStreamingEvents(config.getIncludeSubAgentStreamingEvents());
190195
request.setMcpServers(config.getMcpServers());
191196
request.setCustomAgents(config.getCustomAgents());
192197
request.setAgent(config.getAgent());
193198
request.setSkillDirectories(config.getSkillDirectories());
194199
request.setDisabledSkills(config.getDisabledSkills());
195200
request.setInfiniteSessions(config.getInfiniteSessions());
201+
request.setModelCapabilities(config.getModelCapabilities());
196202

197203
if (config.getCommands() != null && !config.getCommands().isEmpty()) {
198204
var wireCommands = config.getCommands().stream()

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

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,11 @@ public final class CreateSessionRequest {
6767
@JsonProperty("streaming")
6868
private Boolean streaming;
6969

70+
@JsonProperty("includeSubAgentStreamingEvents")
71+
private Boolean includeSubAgentStreamingEvents;
72+
7073
@JsonProperty("mcpServers")
71-
private Map<String, Object> mcpServers;
74+
private Map<String, McpServerConfig> mcpServers;
7275

7376
@JsonProperty("envValueMode")
7477
private String envValueMode;
@@ -91,12 +94,18 @@ public final class CreateSessionRequest {
9194
@JsonProperty("configDir")
9295
private String configDir;
9396

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

97103
@JsonProperty("requestElicitation")
98104
private Boolean requestElicitation;
99105

106+
@JsonProperty("modelCapabilities")
107+
private ModelCapabilitiesOverride modelCapabilities;
108+
100109
/** Gets the model name. @return the model */
101110
public String getModel() {
102111
return model;
@@ -240,12 +249,12 @@ public void setStreaming(Boolean streaming) {
240249
}
241250

242251
/** Gets MCP servers. @return the servers map */
243-
public Map<String, Object> getMcpServers() {
252+
public Map<String, McpServerConfig> getMcpServers() {
244253
return mcpServers == null ? null : Collections.unmodifiableMap(mcpServers);
245254
}
246255

247256
/** Sets MCP servers. @param mcpServers the servers map */
248-
public void setMcpServers(Map<String, Object> mcpServers) {
257+
public void setMcpServers(Map<String, McpServerConfig> mcpServers) {
249258
this.mcpServers = mcpServers;
250259
}
251260

@@ -319,6 +328,29 @@ public void setConfigDir(String configDir) {
319328
this.configDir = configDir;
320329
}
321330

331+
/** Gets enable config discovery flag. @return the flag */
332+
public Boolean getEnableConfigDiscovery() {
333+
return enableConfigDiscovery;
334+
}
335+
336+
/** Sets enable config discovery flag. @param enableConfigDiscovery the flag */
337+
public void setEnableConfigDiscovery(Boolean enableConfigDiscovery) {
338+
this.enableConfigDiscovery = enableConfigDiscovery;
339+
}
340+
341+
/** Gets include sub-agent streaming events flag. @return the flag */
342+
public Boolean getIncludeSubAgentStreamingEvents() {
343+
return includeSubAgentStreamingEvents;
344+
}
345+
346+
/**
347+
* Sets include sub-agent streaming events flag. @param
348+
* includeSubAgentStreamingEvents the flag
349+
*/
350+
public void setIncludeSubAgentStreamingEvents(Boolean includeSubAgentStreamingEvents) {
351+
this.includeSubAgentStreamingEvents = includeSubAgentStreamingEvents;
352+
}
353+
322354
/** Gets the commands wire definitions. @return the commands */
323355
public List<CommandWireDefinition> getCommands() {
324356
return commands == null ? null : Collections.unmodifiableList(commands);
@@ -338,4 +370,16 @@ public Boolean getRequestElicitation() {
338370
public void setRequestElicitation(Boolean requestElicitation) {
339371
this.requestElicitation = requestElicitation;
340372
}
373+
374+
/** Gets the model capabilities override. @return the override */
375+
public ModelCapabilitiesOverride getModelCapabilities() {
376+
return modelCapabilities;
377+
}
378+
379+
/**
380+
* Sets the model capabilities override. @param modelCapabilities the override
381+
*/
382+
public void setModelCapabilities(ModelCapabilitiesOverride modelCapabilities) {
383+
this.modelCapabilities = modelCapabilities;
384+
}
341385
}

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

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,14 @@ 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;
5757

58+
@JsonProperty("skills")
59+
private List<String> skills;
60+
5861
/**
5962
* Gets the unique identifier name for this agent.
6063
*
@@ -175,7 +178,7 @@ public CustomAgentConfig setPrompt(String prompt) {
175178
*
176179
* @return the MCP servers map
177180
*/
178-
public Map<String, Object> getMcpServers() {
181+
public Map<String, McpServerConfig> getMcpServers() {
179182
return mcpServers == null ? null : Collections.unmodifiableMap(mcpServers);
180183
}
181184

@@ -186,7 +189,7 @@ public Map<String, Object> getMcpServers() {
186189
* the MCP server configurations
187190
* @return this config for method chaining
188191
*/
189-
public CustomAgentConfig setMcpServers(Map<String, Object> mcpServers) {
192+
public CustomAgentConfig setMcpServers(Map<String, McpServerConfig> mcpServers) {
190193
this.mcpServers = mcpServers;
191194
return this;
192195
}
@@ -211,4 +214,31 @@ public CustomAgentConfig setInfer(Boolean infer) {
211214
this.infer = infer;
212215
return this;
213216
}
217+
218+
/**
219+
* Gets the list of skill names to preload into this agent's context.
220+
*
221+
* @return the list of skill names, or {@code null} if not set
222+
*/
223+
public List<String> getSkills() {
224+
return skills == null ? null : Collections.unmodifiableList(skills);
225+
}
226+
227+
/**
228+
* Sets the list of skill names to preload into this agent's context.
229+
* <p>
230+
* When set, the full content of each listed skill is eagerly injected into the
231+
* agent's context at startup. Skills are resolved by name from the session's
232+
* configured skill directories
233+
* ({@link SessionConfig#setSkillDirectories(List)}). When omitted, no skills
234+
* are injected (opt-in model).
235+
*
236+
* @param skills
237+
* the list of skill names to preload
238+
* @return this config for method chaining
239+
*/
240+
public CustomAgentConfig setSkills(List<String> skills) {
241+
this.skills = skills;
242+
return this;
243+
}
214244
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
*--------------------------------------------------------------------------------------------*/
4+
5+
package com.github.copilot.sdk.json;
6+
7+
import java.util.Collections;
8+
import java.util.List;
9+
import java.util.Map;
10+
11+
import com.fasterxml.jackson.annotation.JsonInclude;
12+
import com.fasterxml.jackson.annotation.JsonProperty;
13+
14+
/**
15+
* Configuration for a remote HTTP/SSE MCP (Model Context Protocol) server.
16+
* <p>
17+
* Use this to configure an MCP server that communicates over HTTP or
18+
* Server-Sent Events (SSE).
19+
*
20+
* <h2>Example Usage</h2>
21+
*
22+
* <pre>{@code
23+
* var server = new McpHttpServerConfig().setUrl("https://mcp.example.com/sse").setTools(List.of("*"));
24+
*
25+
* var config = new SessionConfig().setMcpServers(Map.of("remote-server", server));
26+
* }</pre>
27+
*
28+
* @see McpServerConfig
29+
* @see SessionConfig#setMcpServers(java.util.Map)
30+
* @since 1.3.0
31+
*/
32+
@JsonInclude(JsonInclude.Include.NON_NULL)
33+
public final class McpHttpServerConfig extends McpServerConfig {
34+
35+
@JsonProperty("type")
36+
private final String type = "http";
37+
38+
@JsonProperty("url")
39+
private String url;
40+
41+
@JsonProperty("headers")
42+
private Map<String, String> headers;
43+
44+
/**
45+
* Gets the server type discriminator.
46+
*
47+
* @return always {@code "http"}
48+
*/
49+
public String getType() {
50+
return type;
51+
}
52+
53+
/**
54+
* Gets the URL of the remote server.
55+
*
56+
* @return the server URL
57+
*/
58+
public String getUrl() {
59+
return url;
60+
}
61+
62+
/**
63+
* Sets the URL of the remote server.
64+
*
65+
* @param url
66+
* the server URL
67+
* @return this config for method chaining
68+
*/
69+
public McpHttpServerConfig setUrl(String url) {
70+
this.url = url;
71+
return this;
72+
}
73+
74+
/**
75+
* Gets the optional HTTP headers to include in requests.
76+
*
77+
* @return the headers map, or {@code null}
78+
*/
79+
public Map<String, String> getHeaders() {
80+
return headers == null ? null : Collections.unmodifiableMap(headers);
81+
}
82+
83+
/**
84+
* Sets optional HTTP headers to include in requests to this server.
85+
*
86+
* @param headers
87+
* the headers map
88+
* @return this config for method chaining
89+
*/
90+
public McpHttpServerConfig setHeaders(Map<String, String> headers) {
91+
this.headers = headers;
92+
return this;
93+
}
94+
95+
@Override
96+
public McpHttpServerConfig setTools(List<String> tools) {
97+
super.setTools(tools);
98+
return this;
99+
}
100+
101+
@Override
102+
public McpHttpServerConfig setTimeout(Integer timeout) {
103+
super.setTimeout(timeout);
104+
return this;
105+
}
106+
}

0 commit comments

Comments
 (0)