src/vs/workbench/contrib/mcp/node/mcpStdioStateHandler.ts

101 LOC · 82 covered · 19 uncovered · 19 ranges · 5 concepts · 3 introducers · 9 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the filesrc/vs/base/common/async.ts · 2749 LOCcommon/async.tssrc/vs/base/node/processes.ts · 180 LOCnode/processes.tsextHostMcpNode.ts ×8 · 45 introduced LOCextHostMcpNode.ts ×8mcpStdioStateHandler.ts ×3 · 7 introduced LOCmcpStdioStateHandler.ts …mcpStdioStateHandler.test|title=McpStdioStateHandler stdin ends process|occurrence=1, mcpStdioStateHandler.test|title=McpStdioStateHandler sigterm after grace|occurrence=1 · 0 introduced LOCmcpStdioStateHandler.tes…mcpStdioStateHandler.ts ×8 · 46 introduced LOCmcpStdioStateHandler.ts …mcpStdioStateHandler.ts ×8 · 51 introduced LOCmcpStdioStateHandler.ts …extHostMcpNode.test|title=extHostMcpNode - escapeCmdArg does not add stray ^ to argument values|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/api/test/node/extHostMcpNode.test|title=extHostMcpNode - escapeCmdArg does not add stray ^ to argument values|occurrence=1extHostMcpNode.test|titl…extHostMcpNode.test|title=extHostMcpNode - escapeCmdArg doubles embedded double quotes (cmd.exe convention)|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/api/test/node/extHostMcpNode.test|title=extHostMcpNode - escapeCmdArg doubles embedded double quotes (cmd.exe convention)|occurrence=1extHostMcpNode.test|titl…extHostMcpNode.test|title=extHostMcpNode - escapeCmdArg neutralizes cmd.exe metacharacters inside quotes (CVE-2024-27980)|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/api/test/node/extHostMcpNode.test|title=extHostMcpNode - escapeCmdArg neutralizes cmd.exe metacharacters inside quotes (CVE-2024-27980)|occurrence=1extHostMcpNode.test|titl…extHostMcpNode.test|title=extHostMcpNode - escapeCmdArg preserves paths with parentheses without injecting ^|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/api/test/node/extHostMcpNode.test|title=extHostMcpNode - escapeCmdArg preserves paths with parentheses without injecting ^|occurrence=1extHostMcpNode.test|titl…extHostMcpNode.test|title=extHostMcpNode - escapeCmdArg preserves paths with spaces|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/api/test/node/extHostMcpNode.test|title=extHostMcpNode - escapeCmdArg preserves paths with spaces|occurrence=1extHostMcpNode.test|titl…extHostMcpNode.test|title=extHostMcpNode - escapeCmdArg wraps simple values in double quotes|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/api/test/node/extHostMcpNode.test|title=extHostMcpNode - escapeCmdArg wraps simple values in double quotes|occurrence=1extHostMcpNode.test|titl…mcpStdioStateHandler.test|title=McpStdioStateHandler sigkill after grace|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/mcp/test/node/mcpStdioStateHandler.test|title=McpStdioStateHandler sigkill after grace|occurrence=1mcpStdioStateHandler.tes…mcpStdioStateHandler.test|title=McpStdioStateHandler sigterm after grace|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/mcp/test/node/mcpStdioStateHandler.test|title=McpStdioStateHandler sigterm after grace|occurrence=1mcpStdioStateHandler.tes…mcpStdioStateHandler.test|title=McpStdioStateHandler stdin ends process|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/mcp/test/node/mcpStdioStateHandler.test|title=McpStdioStateHandler stdin ends process|occurrence=1mcpStdioStateHandler.tes…Focused file · src/vs/workbench/contrib/mcp/node/mcpStdioStateHandler.ts · 101 LOCnode/mcpStdioStateHandle…

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 > /*--------------------------------------------------------------------------------------------- mcpStdioStateHandler.ts ×8
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 } from 'child_process';
7 > import { TimeoutTimer } from '../../../../base/common/async.js';
8 > import { IDisposable } from '../../../../base/common/lifecycle.js';
9 > import { killTree } from '../../../../base/node/processes.js';
10 > import { isWindows } from '../../../../base/common/platform.js';
11 >
12 > const enum McpProcessState {
13 > Running,
14 > StdinEnded,
15 > KilledPolite,
16 > KilledForceful,
17 > }
18 >
19 > /**
20 > * Manages graceful shutdown of MCP stdio connections following the MCP specification.
21 > *
22 > * Per spec, shutdown should:
23 > * 1. Close the input stream to the child process
24 > * 2. Wait for the server to exit, or send SIGTERM if it doesn't exit within 10 seconds
25 > * 3. Send SIGKILL if the server doesn't exit within 10 seconds after SIGTERM
26 > * 4. Allow forceful killing if called twice
27 > */
28 > export class McpStdioStateHandler implements IDisposable {
29 > private static readonly GRACE_TIME_MS = 10_000;
30 >
31 > private _procState = McpProcessState.Running;
32 > private _nextTimeout?: IDisposable;
33 >
34 > public get stopped() {
35 return this._procState !== McpProcessState.Running;
36 }
38 > constructor(
39 > private readonly _child: ChildProcessWithoutNullStreams, mcpStdioStateHandler.ts ×8
40 > private readonly _graceTimeMs: number = McpStdioStateHandler.GRACE_TIME_MS
41 > ) { }
43 > /**
44 > * Initiates graceful shutdown. If called while shutdown is already in progress,
45 > * forces immediate termination.
46 > */
47 > public stop(): void {
48 > if (this._procState === McpProcessState.Running) { mcpStdioStateHandler.ts ×8
49 > let graceTime = this._graceTimeMs;
50 > try {
51 > this._child.stdin.end();
52 > } catch (error) {
53 // If stdin.end() fails, continue with termination sequence
54 // This can happen if the stream is already in an error state
55 graceTime = 1;
56 }
57 > this._procState = McpProcessState.StdinEnded; mcpStdioStateHandler.ts ×8
58 > this._nextTimeout = new TimeoutTimer(() => this.killPolite(), graceTime);
59 > } else {
60 this._nextTimeout?.dispose();
61 this.killForceful();
62 }
65 > private async killPolite() {
66 > this._procState = McpProcessState.KilledPolite; mcpStdioStateHandler.ts ×8
67 > this._nextTimeout = new TimeoutTimer(() => this.killForceful(), this._graceTimeMs);
68 >
69 > if (this._child.pid) {
70 > if (!isWindows) {
71 > await killTree(this._child.pid, false).catch(() => {
72 this._child.kill('SIGTERM');
74 > }
75 > } else {
76 this._child.kill('SIGTERM');
77 }
80 > private async killForceful() {
81 > this._procState = McpProcessState.KilledForceful; mcpStdioStateHandler.ts ×3
82 >
83 > if (this._child.pid) {
84 > await killTree(this._child.pid, true).catch(() => {
85 this._child.kill('SIGKILL');
87 > } else {
88 this._child.kill();
89 }
92 > public write(message: string): void {
93 if (!this.stopped) {
94 this._child.stdin.write(message + '\n');
95 }
96 }
98 > public dispose() {
99 > this._nextTimeout?.dispose(); mcpStdioStateHandler.ts ×8
100 > }