Skip to content

Commit eb94b53

Browse files
committed
use send and wait and remove manual server control
1 parent 0b4cc4a commit eb94b53

File tree

5 files changed

+76
-91
lines changed

5 files changed

+76
-91
lines changed

docs/mcp-usage.md

Lines changed: 60 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ Below are examples for configuring both local and remote MCP servers:
3232
import { CopilotClient, type MCPLocalServerConfig, type MCPRemoteServerConfig } from "@github/copilot-sdk";
3333

3434
const client = new CopilotClient();
35-
await client.start();
3635

3736
const session = await client.createSession({
3837
mcpServers: {
@@ -45,30 +44,20 @@ const session = await client.createSession({
4544
"local-tools": {
4645
type: "local",
4746
command: "node",
48-
args: ["./local-mcp-server.js"],
49-
tools: ["my-tool"],
47+
args: ["./mcp_server.js"],
48+
tools: ["*"],
5049
env: { "DEBUG": "1" },
5150
} as MCPLocalServerConfig,
5251
},
5352
});
5453

55-
// Wait for response using session.idle event
56-
const done = new Promise<void>((resolve) => {
57-
session.on((event) => {
58-
if (event.type === "assistant.message") {
59-
console.log(event.data.content);
60-
} else if (event.type === "session.idle") {
61-
resolve();
62-
}
63-
});
64-
});
65-
6654
// Send a message and wait for completion
67-
await session.send({ prompt: "Use the GitHub MCP Server tools to fetch PR data" });
68-
await done;
55+
const response = await session.sendAndWait({ prompt: "Use the local-tools MCP Server to echo 'Hello from Copilot SDK!'." });
56+
57+
console.log(response?.data.content);
6958

70-
await session.destroy();
7159
await client.stop();
60+
process.exit(0);
7261
```
7362

7463
</details>
@@ -94,18 +83,17 @@ async def main():
9483
},
9584
"local-tools": {
9685
"type": "local",
97-
"command": "echo",
98-
"args": ["hello"],
86+
"command": "python3",
87+
"args": ["./mcp_server.py"],
9988
"tools": ["*"],
10089
"env": {"DEBUG": "1"},
10190
}
10291
}
10392
})
10493

105-
done = asyncio.Event()
94+
response = await session.send_and_wait({"prompt": "Use the local-tools MCP Server to echo 'Hello from Copilot SDK!'."})
10695

107-
await session.send({"prompt": "Use the GitHub MCP Server tools to fetch PR data"})
108-
await done.wait()
96+
print(response.data.content)
10997

11098
await session.destroy()
11199
await client.stop()
@@ -123,52 +111,54 @@ asyncio.run(main())
123111
package main
124112

125113
import (
126-
"fmt"
127-
"log"
114+
"fmt"
115+
"log"
128116

129-
copilot "github.com/github/copilot-sdk/go"
117+
copilot "github.com/github/copilot-sdk/go"
130118
)
131119

132120
func main() {
133-
client := copilot.NewClient(nil)
134-
135-
if err := client.Start(); err != nil {
136-
log.Fatal(err)
137-
}
138-
defer client.Stop()
139-
140-
mcpServers := map[string]copilot.MCPServerConfig{
141-
"github": {
142-
"type": "http",
143-
"url": "https://api.githubcopilot.com/mcp/",
144-
"tools": []string{"github-repos", "github-pull-requests"},
145-
"headers": map[string]string{
146-
"Authorization": "Bearer <token>",
147-
},
148-
},
149-
"local-tools": {
150-
"type": "local",
151-
"command": "echo",
152-
"args": []string{"hello"},
153-
"tools": []string{"*"},
154-
"env": map[string]string{"DEBUG": "1"},
155-
},
156-
}
157-
158-
session, err := client.CreateSession(&copilot.SessionConfig{
159-
MCPServers: mcpServers,
160-
})
161-
if err != nil {
162-
log.Fatalf("Failed to create session: %v", err)
163-
}
164-
defer session.Destroy()
165-
166-
_, err = session.Send(copilot.MessageOptions{
167-
Prompt: "Use the GitHub MCP Server tools to fetch PR data",
168-
})
169-
if err != nil {
170-
log.Fatal(err)
171-
}
121+
client := copilot.NewClient(nil)
122+
123+
if err := client.Start(); err != nil {
124+
log.Fatal(err)
125+
}
126+
defer client.Stop()
127+
128+
mcpServers := map[string]copilot.MCPServerConfig{
129+
"github": {
130+
"type": "http",
131+
"url": "https://api.githubcopilot.com/mcp/",
132+
"tools": []string{"github-repos", "github-pull-requests"},
133+
"headers": map[string]string{
134+
"Authorization": "Bearer <token>",
135+
},
136+
},
137+
"local-tools": {
138+
"type": "local",
139+
"command": "go run",
140+
"args": []string{"./mcp_server.go"},
141+
"tools": []string{"*"},
142+
"env": map[string]string{"DEBUG": "1"},
143+
},
144+
}
145+
146+
session, err := client.CreateSession(&copilot.SessionConfig{
147+
MCPServers: mcpServers,
148+
})
149+
if err != nil {
150+
log.Fatalf("Failed to create session: %v", err)
151+
}
152+
defer session.Destroy()
153+
154+
response, err := session.SendAndWait(copilot.MessageOptions{
155+
Prompt: "Use the local-tools MCP Server to echo 'Hello from Copilot SDK!'.",
156+
}, 0)
157+
if err != nil {
158+
log.Fatal(err)
159+
}
160+
161+
fmt.Println(*response.Data.Content)
172162
}
173163
```
174164

@@ -181,15 +171,14 @@ func main() {
181171
using GitHub.Copilot.SDK;
182172

183173
await using var client = new CopilotClient();
184-
await client.StartAsync();
185174

186175
var mcpServers = new Dictionary<string, object>
187176
{
188177
["github"] = new McpRemoteServerConfig
189178
{
190179
Type = "http",
191180
Url = "https://api.githubcopilot.com/mcp/",
192-
Tools = new[] { "github-repos", "github-pull-requests" },
181+
Tools = ["github-repos", "github-pull-requests"],
193182
Headers = new Dictionary<string, string>
194183
{
195184
["Authorization"] = "Bearer <token>"
@@ -198,9 +187,9 @@ var mcpServers = new Dictionary<string, object>
198187
["local-tools"] = new McpLocalServerConfig
199188
{
200189
Type = "local",
201-
Command = "echo",
202-
Args = new[] { "hello" },
203-
Tools = new[] { "*" },
190+
Command = "dotnet",
191+
Args = ["./mcp_server.dll"],
192+
Tools = ["*"],
204193
Env = new Dictionary<string, string> { ["DEBUG"] = "1" }
205194
}
206195
};
@@ -210,12 +199,8 @@ await using var session = await client.CreateSessionAsync(new SessionConfig
210199
McpServers = mcpServers
211200
});
212201

213-
var done = new TaskCompletionSource();
214-
215-
await session.SendAsync(new MessageOptions { Prompt = "What is 2+2?" });
216-
await done.Task;
217-
218-
await session.DisposeAsync();
202+
var response = await session.SendAndWaitAsync(new MessageOptions { Prompt = "Use the local-tools MCP Server to echo 'Hello from Copilot SDK!'." });
203+
Console.WriteLine(response?.Data.Content);
219204
```
220205

221206
</details>

dotnet/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ var mcpServers = new Dictionary<string, object>
334334
{
335335
Type = "http",
336336
Url = "https://api.githubcopilot.com/mcp/",
337-
Tools = new[] { "github-repos", "github-pull-requests" },
337+
Tools = ["github-repos", "github-pull-requests"],
338338
Headers = new Dictionary<string, string>
339339
{
340340
["Authorization"] = "Bearer <token>"
@@ -343,14 +343,14 @@ var mcpServers = new Dictionary<string, object>
343343
["local-tools"] = new McpLocalServerConfig
344344
{
345345
Type = "local",
346-
Command = "echo",
347-
Args = new[] { "hello" },
348-
Tools = new[] { "*" },
346+
Command = "dotnet",
347+
Args = ["./mcp_server.dll"],
348+
Tools = ["*"],
349349
Env = new Dictionary<string, string> { ["DEBUG"] = "1" }
350350
}
351351
};
352352

353-
var session = await client.CreateSessionAsync(new SessionConfig
353+
await using var session = await client.CreateSessionAsync(new SessionConfig
354354
{
355355
McpServers = mcpServers
356356
});

go/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -332,19 +332,19 @@ Configure local and remote MCP server usage:
332332
```go
333333
mcpServers := map[string]copilot.MCPServerConfig{
334334
"github": {
335-
"type": "http",
336-
"url": "https://api.githubcopilot.com/mcp/",
335+
"type": "http",
336+
"url": "https://api.githubcopilot.com/mcp/",
337337
"tools": []string{"github-repos", "github-pull-requests"},
338338
"headers": map[string]string{
339339
"Authorization": "Bearer <token>",
340340
},
341341
},
342342
"local-tools": {
343-
"type": "local",
344-
"command": "echo",
345-
"args": []string{"hello"},
346-
"tools": []string{"*"},
347-
"env": map[string]string{"DEBUG": "1"},
343+
"type": "local",
344+
"command": "go run",
345+
"args": []string{"./mcp_server.go"},
346+
"tools": []string{"*"},
347+
"env": map[string]string{"DEBUG": "1"},
348348
},
349349
}
350350

nodejs/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,8 @@ const session = await client.createSession({
279279
"local-tools": {
280280
type: "local",
281281
command: "node",
282-
args: ["./local-mcp-server.js"],
283-
tools: ["my-tool"],
282+
args: ["./mcp_server.js"],
283+
tools: ["*"],
284284
env: { "DEBUG": "1" },
285285
} as MCPLocalServerConfig,
286286
},

python/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,8 @@ session = await client.create_session({
288288
},
289289
"local-tools": {
290290
"type": "local",
291-
"command": "echo",
292-
"args": ["hello"],
291+
"command": "python3",
292+
"args": ["./mcp_server.py"],
293293
"tools": ["*"],
294294
"env": {"DEBUG": "1"},
295295
}

0 commit comments

Comments
 (0)