-
Notifications
You must be signed in to change notification settings - Fork 8
refactor(ai-config): shared MCP server config logic w/ jsonc-parser #1648
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c5c46fb
feat: integrate MCP server configuration with jsonc-parser and refact…
Marina-L-Stoyanova bccb948
feat: refactor MCP server configuration and enhance jsonc handling
Marina-L-Stoyanova d42096a
Merge branch 'master' into mstoyanova/jsonc-parser
kdinev 34aef78
feat: refactor MCP server configuration to use addMcpServers and simp…
Marina-L-Stoyanova c32329e
Merge branch 'mstoyanova/jsonc-parser' of https://github.com/IgniteUI…
Marina-L-Stoyanova 5b8c52a
refactor: revert back path param and in command message
damyanpetev 352eceb
Merge branch 'master' into mstoyanova/jsonc-parser
damyanpetev b3bcd7d
refactor(schematics): split aiConfig rule from standalone ai-config …
damyanpetev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import { FS_TOKEN, IFileSystem } from "../types/FileSystem"; | ||
| import * as jsonc from "jsonc-parser"; | ||
| import { App } from "./App"; | ||
|
|
||
| export interface McpServerEntry { | ||
| command: string; | ||
| args: string[]; | ||
| } | ||
|
|
||
| const IGNITEUI_MCP_SERVERS: Record<string, McpServerEntry> = { | ||
| "igniteui-cli": { | ||
| command: "npx", | ||
| args: ["-y", "igniteui-cli@next", "mcp"] | ||
| }, | ||
| "igniteui-theming": { | ||
| command: "npx", | ||
| args: ["-y", "igniteui-theming", "igniteui-theming-mcp"] | ||
| } | ||
| }; | ||
|
|
||
| export const VS_CODE_MCP_PATH = ".vscode/mcp.json"; | ||
|
|
||
| /** | ||
| * Reads .vscode/mcp.json, ensures all IgniteUI MCP servers are present, | ||
| * optionally adds additional servers. Creates the file if it doesn't exist. | ||
| * @param additionalServers optional extra servers to include alongside the built-in ones | ||
| * @returns whether the file was modified | ||
| */ | ||
| export function addMcpServers( | ||
| mcpFilePath: string, | ||
| additionalServers?: Record<string, McpServerEntry> | ||
| ): boolean { | ||
| const fileSystem = App.container.get<IFileSystem>(FS_TOKEN); | ||
| const servers = { ...additionalServers, ...IGNITEUI_MCP_SERVERS }; | ||
|
|
||
| let existingContent: string | undefined; | ||
| try { | ||
| existingContent = fileSystem.readFile(mcpFilePath); | ||
| } catch { | ||
| existingContent = undefined; | ||
| } | ||
|
|
||
| if (!existingContent) { | ||
| if (Object.keys(servers).length === 0) { | ||
| return false; | ||
| } | ||
| fileSystem.writeFile(mcpFilePath, JSON.stringify({ servers }, null, 2) + "\n"); | ||
| return true; | ||
| } | ||
|
|
||
| const parsed = jsonc.parse(existingContent); | ||
| const existing = parsed.servers ?? {}; | ||
| const formattingOptions: jsonc.FormattingOptions = { tabSize: 2, insertSpaces: true }; | ||
|
|
||
| let text = existingContent; | ||
| let modified = false; | ||
|
|
||
| for (const [key, value] of Object.entries(servers)) { | ||
| if (!existing[key]) { | ||
|
damyanpetev marked this conversation as resolved.
|
||
| const edits = jsonc.modify(text, ["servers", key], value, { formattingOptions }); | ||
| text = jsonc.applyEdits(text, edits); | ||
| modified = true; | ||
| } | ||
| } | ||
|
|
||
| if (modified) { | ||
| fileSystem.writeFile(mcpFilePath, text); | ||
| } | ||
|
|
||
| return modified; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.