-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmcp_client.ts
81 lines (67 loc) · 1.89 KB
/
mcp_client.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
import { WebSocketClientTransport } from "@modelcontextprotocol/sdk/client/websocket.js";
const transport = new StdioClientTransport({
command: "bun",
args: ["mcp_server.ts"]
});
const client = new Client(
{
name: "pokemon-client",
version: "1.0.0"
},
{
capabilities: {
prompts: {},
resources: {},
tools: {}
}
}
);
await client.connect(transport);
// List resources
const resources = await client.listResourceTemplates();
console.log(resources)
// List tools
const tools = await client.listTools();
console.log(JSON.stringify(tools, null, 2))
// Get a abilities
const pokemon_abilities = await client.readResource({ uri: "pokemon://pikachu/abilities"})
console.log(pokemon_abilities)
// Execute tool
const attack_result = await client.callTool({
name: "attack",
arguments: {
moveName: "hurricane",
pokemonName: "Moltres"
}
});
console.log(attack_result)
// Call a tool
const lowAccuracyMoves = [
{ move: "hurricane", accuracy: 70 },
{ move: "zap-cannon", accuracy: 50 },
{ move: "hydro-pump", accuracy: 80 },
{ move: "thunder", accuracy: 70 },
{ move: "focus-blast", accuracy: 70 },
{ move: "stone-edge", accuracy: 80 },
{ move: "inferno", accuracy: 50 },
{ move: "dynamic-punch", accuracy: 50 },
{ move: "blizzard", accuracy: 70 },
{ move: "guillotine", accuracy: 30 }
];
const pokemon = [
"moltres", "zapdos", "blastoise", "raichu", "machamp",
"tyranitar", "charizard", "heracross", "articuno", "scizor"
];
// Run the attacks in a loop
for (let i = 0; i < 10; i++) {
const result = await client.callTool({
name: "attack",
arguments: {
moveName: lowAccuracyMoves[i].move,
pokemonName: pokemon[i]
}
});
console.log(`Attack ${i+1} result:`, result);
}