Path: blob/main/src/vs/workbench/contrib/mcp/common/mcpConfigFileUtils.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { findNodeAtLocation, parseTree as jsonParseTree } from '../../../../base/common/json.js';6import { Location } from '../../../../editor/common/languages.js';7import { ITextModel } from '../../../../editor/common/model.js';89export const getMcpServerMapping = (opts: {10model: ITextModel;11// Path to MCP servers in the config.12pathToServers: string[];13}): Map<string, Location> => {14const tree = jsonParseTree(opts.model.getValue());15const servers = findNodeAtLocation(tree, opts.pathToServers);16if (!servers || servers.type !== 'object') {17return new Map();18}1920const result = new Map<string, Location>();21for (const node of servers.children || []) {22if (node.type !== 'property' || node.children?.[0]?.type !== 'string') {23continue;24}2526const start = opts.model.getPositionAt(node.offset);27const end = opts.model.getPositionAt(node.offset + node.length);28result.set(node.children[0].value, {29uri: opts.model.uri,30range: {31startLineNumber: start.lineNumber,32startColumn: start.column,33endLineNumber: end.lineNumber,34endColumn: end.column,35}36});37}3839return result;40};414243