MCPConnection: avoid accidentally mutating options.transport.env

The code that added the PATH to the stdio transport environment was
mutating the original options.transport.env object, which can lead
to an infinite loop of reloading the continue config since
MCPMananagerSingletone.setConnections() compares the old and new
options and forces a refresh if any existing server changed transport
options. This triggers a config reload because in core.ts we have:

  MCPManagerSingleton.getInstance().onConnectionsRefreshed = async () => {
     await this.configHandler.reloadConfig();
  };
Which thens calls setConnections() and so forth...
This commit is contained in:
Owen W. Taylor 2025-05-02 09:34:12 -04:00
parent 7f926cad37
commit 9e05f745a5

View file

@ -55,7 +55,9 @@ class MCPConnection {
private constructTransport(options: MCPOptions): Transport {
switch (options.transport.type) {
case "stdio":
const env: Record<string, string> = options.transport.env || {};
const env: Record<string, string> = options.transport.env
? { ...options.transport.env }
: {};
if (process.env.PATH !== undefined) {
env.PATH = process.env.PATH;
}