Skip to content

fix(client): Some mcp server need default env(#393, #196) #394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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