Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/mcp/common/mcpConfigFileUtils.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
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 { findNodeAtLocation, parseTree as jsonParseTree } from '../../../../base/common/json.js';
7
import { Location } from '../../../../editor/common/languages.js';
8
import { ITextModel } from '../../../../editor/common/model.js';
9
10
export const getMcpServerMapping = (opts: {
11
model: ITextModel;
12
// Path to MCP servers in the config.
13
pathToServers: string[];
14
}): Map<string, Location> => {
15
const tree = jsonParseTree(opts.model.getValue());
16
const servers = findNodeAtLocation(tree, opts.pathToServers);
17
if (!servers || servers.type !== 'object') {
18
return new Map();
19
}
20
21
const result = new Map<string, Location>();
22
for (const node of servers.children || []) {
23
if (node.type !== 'property' || node.children?.[0]?.type !== 'string') {
24
continue;
25
}
26
27
const start = opts.model.getPositionAt(node.offset);
28
const end = opts.model.getPositionAt(node.offset + node.length);
29
result.set(node.children[0].value, {
30
uri: opts.model.uri,
31
range: {
32
startLineNumber: start.lineNumber,
33
startColumn: start.column,
34
endLineNumber: end.lineNumber,
35
endColumn: end.column,
36
}
37
});
38
}
39
40
return result;
41
};
42
43