32 lines
894 B
JavaScript
32 lines
894 B
JavaScript
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|||
|
|
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
|
||
|
|
import * as EventSource from "eventsource";
|
||
|
|
|
||
|
|
global.EventSource = EventSource;
|
||
|
|
|
||
|
|
async function run() {
|
||
|
|
console.log("Connecting...");
|
||
|
|
const transport = new SSEClientTransport(new URL("http://localhost:3002/mcp"), {
|
||
|
|
requestInit: {
|
||
|
|
headers: {
|
||
|
|
"Authorization": "Bearer MyToKeN"
|
||
|
|
}
|
||
|
|
},
|
||
|
|
eventSourceInit: {
|
||
|
|
headers: {
|
||
|
|
"Authorization": "Bearer MyToKeN"
|
||
|
|
}
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
const client = new Client({ name: "test", version: "1.0.0" }, { capabilities: { tools: {} } });
|
||
|
|
|
||
|
|
await client.connect(transport);
|
||
|
|
console.log("Connected! Fetching tools...");
|
||
|
|
const { tools } = await client.listTools();
|
||
|
|
console.log("Tools found:", tools.map(t => t.name));
|
||
|
|
process.exit(0);
|
||
|
|
}
|
||
|
|
|
||
|
|
run().catch(console.error);
|