Skip to content

Commit 21649b2

Browse files
committed
better
1 parent b56258a commit 21649b2

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

packages/mcp-client/cli.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,22 @@ async function main() {
4949

5050
const rl = readline.createInterface({ input: stdin, output: stdout });
5151
rl.on("SIGINT", async () => {
52-
await agent.client.cleanup();
52+
await agent.cleanup();
5353
stdout.write("\n");
5454
rl.close();
5555
});
5656

5757
await agent.loadTools();
5858

5959
stdout.write(ANSI.BLUE);
60-
stdout.write(`Agent loaded with ${agent.client.availableTools.length} tools:\n`);
61-
stdout.write(agent.client.availableTools.map((t) => `- ${t.function.name}`).join("\n"));
60+
stdout.write(`Agent loaded with ${agent.availableTools.length} tools:\n`);
61+
stdout.write(agent.availableTools.map((t) => `- ${t.function.name}`).join("\n"));
6262
stdout.write(ANSI.RESET);
6363
stdout.write("\n");
6464

6565
while (true) {
66-
const message = await rl.question("> ");
67-
for await (const bobo of boboGenerator(message)) {
66+
const input = await rl.question("> ");
67+
for await (const bobo of boboGenerator(input)) {
6868
console.log(bobo);
6969
}
7070
}

packages/mcp-client/src/Agent.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ If you are not sure about anything pertaining to the user’s request, use your
1111
You MUST plan extensively before each function call, and reflect extensively on the outcomes of the previous function calls. DO NOT do this entire process by making function calls only, as this can impair your ability to solve the problem and think insightfully.
1212
`.trim();
1313

14-
export class Agent {
15-
readonly client: McpClient;
14+
export class Agent extends McpClient {
1615
private readonly servers: StdioServerParameters[];
1716
protected messages: ChatCompletionInputMessage[];
1817

@@ -27,7 +26,7 @@ export class Agent {
2726
apiKey: string;
2827
servers: StdioServerParameters[];
2928
}) {
30-
this.client = new McpClient({ provider, model, apiKey });
29+
super({ provider, model, apiKey });
3130
this.servers = servers;
3231
this.messages = [
3332
{
@@ -38,13 +37,21 @@ export class Agent {
3837
}
3938

4039
async loadTools(): Promise<void> {
41-
return this.client.addMcpServers(this.servers);
40+
return this.addMcpServers(this.servers);
4241
}
4342

4443
async processUserMessage(query: string) {
4544
this.messages.push({
4645
role: "user",
4746
content: query,
4847
});
48+
49+
const stream = await this.client.chatCompletionStream({
50+
provider: this.provider,
51+
model: this.model,
52+
messages,
53+
tools: this.availableTools,
54+
tool_choice: "auto",
55+
});
4956
}
5057
}

0 commit comments

Comments
 (0)