mcpServerRequestHandler.ts ×17

Frontier kind: Code frontier

unlabeled · c_3ac2ce6da379

30 tests · 33278 LOC · 160 files · introduces 0 tests · 106 LOC · 2 files

Introduces — evidence that enters the hierarchy at this concept

Code
19 ranges106 lines · 2 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
3416 ranges33278 lines · 160 files · Browse complete extent
All tests (intent)
30 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

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 native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

2 files ranked by introduced lines: 106 introduced LOC across 19 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/workbench/contrib/mcp/common/mcpServerRequestHandler.ts 104 introduced LOC · 17 ranges

Open complete file

101 */
102 public static async create(instaService: IInstantiationService, opts: IMcpServerRequestHandlerOptions, token?: CancellationToken) {
103 > const mcp = new McpServerRequestHandler(opts); mcpServerRequestHandler.ts
104 > const store = new DisposableStore();
105 > try {
106 > const timer = store.add(new IntervalTimer());
107 > timer.cancelAndSet(() => {
108 opts.logger.info('Waiting for server to respond to `initialize` request...');
109 > }, 5000); mcpServerRequestHandler.ts
110 >
111 > await instaService.invokeFunction(async accessor => {
112 > const productService = accessor.get(IProductService);
113 > const initialized = await mcp.sendRequest<MCP.InitializeRequest, MCP.InitializeResult>({
114 > method: 'initialize',
115 > params: {
116 > protocolVersion: MCP.LATEST_PROTOCOL_VERSION,
117 > capabilities: {
118 > roots: { listChanged: true },
119 > sampling: opts.createMessageRequestHandler ? {} : undefined,
120 > elicitation: opts.elicitationRequestHandler ? { form: {}, url: {} } : undefined,
121 > tasks: {
122 > list: {},
123 > cancel: {},
124 > requests: {
125 > sampling: opts.createMessageRequestHandler ? { createMessage: {} } : undefined,
126 > elicitation: opts.elicitationRequestHandler ? { create: {} } : undefined,
127 > },
128 > },
129 > extensions: {
130 > 'io.modelcontextprotocol/ui': {
131 > mimeTypes: ['text/html;profile=mcp-app']
132 > }
133 > }
134 > },
135 > clientInfo: {
136 > name: productService.nameLong,
137 > version: productService.version,
138 > }
139 > }
140 > }, token);
141 mcp._serverInit = initialized;
142 mcp._sendLogLevelToServer(opts.logger.getLevel());
164
165 protected constructor({
167 > logger,
168 > createMessageRequestHandler,
169 > elicitationRequestHandler,
170 > requestLogLevel = LogLevel.Debug,
171 > taskManager,
172 > }: IMcpServerRequestHandlerOptions) {
173 > super();
174 > this._launch = launch;
175 > this.logger = logger;
176 > this._requestLogLevel = requestLogLevel;
177 > this._createMessageRequestHandler = createMessageRequestHandler;
178 > this._elicitationRequestHandler = elicitationRequestHandler;
179 > this._taskManager = taskManager;
180 >
181 > this._rpc = this._register(new JsonRpcProtocol(
182 > message => this.send(message as MCP.JSONRPCMessage),
183 > {
184 > handleRequest: (request, token) => this.handleServerRequest(request as MCP.JSONRPCRequest & MCP.ServerRequest, token),
185 > handleNotification: notification => this.handleServerNotification(notification as MCP.JSONRPCNotification & MCP.ServerNotification),
186 > }
187 > ));
188 >
189 > // Attach this handler to the task manager
190 > this._taskManager.setHandler(this);
191 > this._register(this._taskManager.onDidUpdateTask(task => {
192 this.send({
193 jsonrpc: MCP.JSONRPC_VERSION,
195 params: task
196 } satisfies MCP.TaskStatusNotification);
198 > this._register(toDisposable(() => this._taskManager.setHandler(undefined)));
199 >
200 > this._register(launch.onDidReceiveMessage(message => {
201 if (canLog(this.logger.getLevel(), this._requestLogLevel)) {
202 log(this.logger, this._requestLogLevel, `[server -> editor] ${JSON.stringify(message)}`);
203 }
204 void this._rpc.handleMessage(message);
206 > this._register(autorun(reader => {
207 > const state = launch.state.read(reader).state;
208 > // the handler will get disposed when the launch stops, but if we're still
209 > // create()'ing we need to make sure to cancel the initialize request.
210 > if (state === McpConnectionState.Kind.Error || state === McpConnectionState.Kind.Stopped) {
211 this.cancelAllRequests();
212 }
214 >
215 > // Listen for log level changes and forward them to the MCP server
216 > this._register(logger.onDidChangeLogLevel((logLevel) => {
217 this._sendLogLevelToServer(logLevel);
219 > }
220
221 /**
228 */
229 private async sendRequest<T extends MCP.ClientRequest, R extends MCP.ServerResult>(
230 > request: Pick<T, 'params' | 'method'>, mcpServerRequestHandler.ts
231 > token: CancellationToken = CancellationToken.None
232 > ): Promise<R> {
233 > if (this._store.isDisposed) {
234 return Promise.reject(new CancellationError());
235 }
237 > return this._rpc.sendRequest<R>(
238 > request,
239 > token,
240 > id => this.sendNotification({ method: 'notifications/cancelled', params: { requestId: id } })
241 > ).catch(error => {
242 if (error instanceof JsonRpcError) {
243 throw new MpcResponseError(error.message, error.code, error.data);
244 }
245 throw error;
247 > }
248
249 private send(mcp: MCP.JSONRPCMessage) {
250 > if (canLog(this.logger.getLevel(), this._requestLogLevel)) { // avoid building the string if we don't need to mcpServerRequestHandler.ts
251 log(this.logger, this._requestLogLevel, `[editor -> server] ${JSON.stringify(mcp)}`);
252 }
253
254 this._launch.send(mcp);
256
257 /**
src/vs/workbench/contrib/mcp/common/mcpTaskManager.ts 2 introduced LOC · 2 ranges

Open complete file

47 */
48 setHandler(handler: McpServerRequestHandler | undefined): void {
49 > for (const task of this._clientTasks.values()) { mcpTaskManager.ts
50 task.setHandler(handler);
51 }
53
54 /**