Skip to content
Merged
30 changes: 30 additions & 0 deletions src/client/stdio.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,33 @@ test("should read messages", async () => {

await client.close();
});

test("should work with actual node mcp server", async () => {
const client = new StdioClientTransport({
command: "npx",
args: ["-y", "@wrtnlabs/calculator-mcp"],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's the simple mcp server
i make it for test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should not be using real servers in tests

});

await client.start();
await client.close();
});

test("should work with actual node mcp server and empty env", async () => {
const client = new StdioClientTransport({
command: "npx",
args: ["-y", "@wrtnlabs/calculator-mcp"],
env: {},
});
await client.start();
await client.close();
});

test("should work with actual node mcp server and custom env", async () => {
const client = new StdioClientTransport({
command: "npx",
args: ["-y", "@wrtnlabs/calculator-mcp"],
env: {TEST_VAR: "test-value"},
});
await client.start();
await client.close();
});
6 changes: 5 additions & 1 deletion src/client/stdio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ export class StdioClientTransport implements Transport {
this._serverParams.command,
this._serverParams.args ?? [],
{
env: this._serverParams.env ?? getDefaultEnvironment(),
// merge default env with server env because mcp server needs some env vars
env: {
...getDefaultEnvironment(),
...this._serverParams.env,
},
stdio: ["pipe", "pipe", this._serverParams.stderr ?? "inherit"],
shell: false,
signal: this._abortController.signal,
Expand Down