1
>
/*---------------------------------------------------------------------------------------------
extHostMcpNode.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { ChildProcessWithoutNullStreams, spawn } from 'child_process';
7
>
import { readFile } from 'fs/promises';
8
>
import { homedir } from 'os';
9
>
import type { RequestInit as UndiciRequestInit } from 'undici';
10
>
import { parseEnvFile } from '../../../base/common/envfile.js';
11
>
import { untildify } from '../../../base/common/labels.js';
12
>
import { Lazy } from '../../../base/common/lazy.js';
13
>
import { DisposableMap } from '../../../base/common/lifecycle.js';
14
>
import * as path from '../../../base/common/path.js';
15
>
import { URI } from '../../../base/common/uri.js';
16
>
import { StreamSplitter } from '../../../base/node/nodeStreams.js';
17
>
import { findExecutable } from '../../../base/node/processes.js';
18
>
import { LogLevel } from '../../../platform/log/common/log.js';
19
>
import { McpConnectionState, McpServerLaunch, McpServerTransportStdio, McpServerTransportType } from '../../contrib/mcp/common/mcpTypes.js';
20
>
import { McpStdioStateHandler } from '../../contrib/mcp/node/mcpStdioStateHandler.js';
21
>
import { CommonRequestInit, CommonResponse, ExtHostMcpService, McpHTTPHandle } from '../common/extHostMcp.js';
22
>
23
>
export class NodeExtHostMpcService extends ExtHostMcpService {
24
private nodeServers = this._register(new DisposableMap<number, McpStdioStateHandler>());
26
>
protected override _startMcp(id: number, launch: McpServerLaunch, defaultCwd?: URI, errorOnUserInteraction?: boolean): void {
27
if (launch.type === McpServerTransportType.Stdio) {
28
this.startNodeMpc(id, launch, defaultCwd);