MCPcopy Create free account
hub / github.com/github/copilot-sdk / main

Method main

java/jbang-example.java:13–41  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

11
12class CopilotSDK {
13 public static void main(String[] args) throws Exception {
14 // Create and start client
15 try (var client = new CopilotClient()) {
16 client.start().get();
17
18 // Create a session
19 var session = client.createSession(
20 new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL).setModel("claude-sonnet-4.5")).get();
21
22 // Handle assistant message events
23 session.on(AssistantMessageEvent.class, msg -> {
24 out.println(msg.getData().content());
25 });
26
27 // Handle session usage info events
28 session.on(SessionUsageInfoEvent.class, usage -> {
29 var data = usage.getData();
30 out.println("\n--- Usage Metrics ---");
31 out.println("Current tokens: " + data.currentTokens().intValue());
32 out.println("Token limit: " + data.tokenLimit().intValue());
33 out.println("Messages count: " + data.messagesLength().intValue());
34 });
35
36 // Send a message
37 var completable = session.sendAndWait(new MessageOptions().setPrompt("What is 2+2?"));
38 // and wait for completion
39 completable.get();
40 }
41 }
42}

Callers

nothing calls this directly

Calls 9

getMethod · 0.45
startMethod · 0.45
createSessionMethod · 0.45
setModelMethod · 0.45
onMethod · 0.45
getDataMethod · 0.45
sendAndWaitMethod · 0.45
setPromptMethod · 0.45

Tested by

no test coverage detected