Update tests and CLI

This commit is contained in:
Justin Spahr-Summers 2024-10-11 16:49:17 +01:00
commit e9c64fbc53
No known key found for this signature in database
GPG key ID: E78498BF3C053CA7
2 changed files with 12 additions and 12 deletions

View file

@ -31,17 +31,17 @@ async function runClient(url_or_command: string, args: string[]) {
}
if (url?.protocol === "http:" || url?.protocol === "https:") {
clientTransport = new SSEClientTransport();
await clientTransport.connect(new URL(url_or_command));
clientTransport = new SSEClientTransport(new URL(url_or_command));
await clientTransport.start();
} else if (url?.protocol === "ws:" || url?.protocol === "wss:") {
clientTransport = new WebSocketClientTransport();
await clientTransport.connect(new URL(url_or_command));
clientTransport = new WebSocketClientTransport(new URL(url_or_command));
await clientTransport.start();
} else {
clientTransport = new StdioClientTransport();
await clientTransport.spawn({
clientTransport = new StdioClientTransport({
command: url_or_command,
args,
});
await clientTransport.start();
}
console.log("Connected to server.");
@ -62,7 +62,7 @@ async function runServer(port: number | null) {
app.get("/sse", async (req, res) => {
console.log("Got new SSE connection");
const transport = new SSEServerTransport("/message");
const transport = new SSEServerTransport("/message", res);
const server = new Server({
name: "mcp-typescript test server",
version: "0.1.0",
@ -75,7 +75,7 @@ async function runServer(port: number | null) {
servers = servers.filter((s) => s !== server);
};
await transport.connectSSE(req, res);
await transport.start();
await server.connect(transport);
});

View file

@ -6,7 +6,7 @@ const serverParameters: StdioServerParameters = {
};
test("should start then close cleanly", async () => {
const client = new StdioClientTransport();
const client = new StdioClientTransport(serverParameters);
client.onerror = (error) => {
throw error;
};
@ -16,14 +16,14 @@ test("should start then close cleanly", async () => {
didClose = true;
};
await client.spawn(serverParameters);
await client.start();
expect(didClose).toBeFalsy();
await client.close();
expect(didClose).toBeTruthy();
});
test("should read messages", async () => {
const client = new StdioClientTransport();
const client = new StdioClientTransport(serverParameters);
client.onerror = (error) => {
throw error;
};
@ -51,7 +51,7 @@ test("should read messages", async () => {
};
});
await client.spawn(serverParameters);
await client.start();
await client.send(messages[0]);
await client.send(messages[1]);
await finished;