Skip to content

Commit

Permalink
Update tests and CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
jspahrsummers committed Oct 11, 2024
1 parent 2b0599e commit e9c64fb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
16 changes: 8 additions & 8 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand All @@ -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",
Expand All @@ -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);
});

Expand Down
8 changes: 4 additions & 4 deletions src/client/stdio.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand All @@ -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;
};
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit e9c64fb

Please sign in to comment.