-
Notifications
You must be signed in to change notification settings - Fork 851
Allow registering Aspire MCP server in VS Code extension #14917
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
adamint
merged 6 commits into
microsoft:release/13.2
from
adamint:dev/adamint/auto-mcp-server-provider
Mar 4, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
dbe86a3
Auto-register Aspire MCP server in VS Code extension
adamint ac847a7
Update extension/src/mcp/AspireMcpServerDefinitionProvider.ts
adamint fca39e8
Update extension/src/mcp/AspireMcpServerDefinitionProvider.ts
adamint cd6131f
Merge branch 'release/13.2' into dev/adamint/auto-mcp-server-provider
adamint 1de221c
add a setting whether to register mcp (false by default)
adamint cc5d3c2
Merge branch 'dev/adamint/auto-mcp-server-provider' of https://github…
adamint 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,83 @@ | ||
| import * as vscode from 'vscode'; | ||
| import { resolveCliPath } from '../utils/cliPath'; | ||
| import { extensionLogOutputChannel } from '../utils/logging'; | ||
| import { getRegisterMcpServerInWorkspace, registerMcpServerInWorkspaceSetting } from '../utils/settings'; | ||
|
|
||
| /** | ||
| * Provides the Aspire MCP server definition to VS Code so it appears | ||
| * automatically in the MCP tools list when the Aspire CLI is available | ||
| * and the workspace contains an Aspire project. | ||
| */ | ||
| export class AspireMcpServerDefinitionProvider implements vscode.McpServerDefinitionProvider<vscode.McpStdioServerDefinition> { | ||
| private readonly _onDidChange = new vscode.EventEmitter<void>(); | ||
| readonly onDidChangeMcpServerDefinitions = this._onDidChange.event; | ||
|
|
||
| private _cliPath: string | undefined; | ||
| private _cliAvailable: boolean = false; | ||
| private _shouldProvide: boolean = false; | ||
| private _configChangeDisposable: vscode.Disposable | undefined; | ||
| private _workspaceFolderChangeDisposable: vscode.Disposable | undefined; | ||
|
|
||
| constructor() { | ||
| // Re-evaluate when the setting changes | ||
| this._configChangeDisposable = vscode.workspace.onDidChangeConfiguration(e => { | ||
| if (e.affectsConfiguration(registerMcpServerInWorkspaceSetting)) { | ||
| this.refresh(); | ||
| } | ||
| }); | ||
|
|
||
| // Re-evaluate when workspace folders change | ||
| this._workspaceFolderChangeDisposable = vscode.workspace.onDidChangeWorkspaceFolders(() => { | ||
| this.refresh(); | ||
| }); | ||
| } | ||
|
|
||
| async refresh(): Promise<void> { | ||
| const [cliResult, shouldProvide] = await Promise.all([ | ||
| resolveCliPath(), | ||
| checkShouldProvideMcpServer(), | ||
| ]); | ||
|
|
||
| const changed = | ||
| this._cliAvailable !== cliResult.available || | ||
| this._cliPath !== cliResult.cliPath || | ||
| this._shouldProvide !== shouldProvide; | ||
|
|
||
| this._cliAvailable = cliResult.available; | ||
| this._cliPath = cliResult.cliPath; | ||
| this._shouldProvide = shouldProvide; | ||
|
|
||
| if (changed) { | ||
| extensionLogOutputChannel.info(`Aspire MCP server definition changed: cliAvailable=${cliResult.available}, shouldProvide=${shouldProvide}`); | ||
| this._onDidChange.fire(); | ||
| } | ||
| } | ||
|
|
||
| provideMcpServerDefinitions(_token: vscode.CancellationToken): vscode.ProviderResult<vscode.McpStdioServerDefinition[]> { | ||
| if (!this._cliAvailable || !this._shouldProvide || !this._cliPath) { | ||
| return []; | ||
| } | ||
adamint marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return [new vscode.McpStdioServerDefinition('Aspire', this._cliPath, ['agent', 'mcp'])]; | ||
adamint marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| dispose(): void { | ||
| this._configChangeDisposable?.dispose(); | ||
| this._workspaceFolderChangeDisposable?.dispose(); | ||
| this._onDidChange.dispose(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Determines whether the Aspire MCP server should be provided. | ||
| * | ||
| * The server is provided only when workspace folders are open and the | ||
| * "aspire.registerMcpServerInWorkspace" setting is enabled. | ||
| */ | ||
| async function checkShouldProvideMcpServer(): Promise<boolean> { | ||
| if (!vscode.workspace.workspaceFolders || vscode.workspace.workspaceFolders.length === 0) { | ||
| return false; | ||
| } | ||
|
|
||
| return getRegisterMcpServerInWorkspace(); | ||
| } | ||
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,17 @@ | ||
| import * as vscode from 'vscode'; | ||
|
|
||
| const aspireConfigSection = 'aspire'; | ||
|
|
||
| const registerMcpServerInWorkspaceSettingName = 'registerMcpServerInWorkspace'; | ||
| export const registerMcpServerInWorkspaceSetting = `${aspireConfigSection}.${registerMcpServerInWorkspaceSettingName}`; | ||
|
|
||
| /** | ||
| * Returns the Aspire extension configuration object. | ||
| */ | ||
| function getAspireConfig(): vscode.WorkspaceConfiguration { | ||
| return vscode.workspace.getConfiguration(aspireConfigSection); | ||
| } | ||
|
|
||
| export function getRegisterMcpServerInWorkspace(): boolean { | ||
| return getAspireConfig().get<boolean>(registerMcpServerInWorkspaceSettingName, false); | ||
| } |
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,40 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| // Type declarations for the vscode proposed API: mcpServerDefinitions | ||
| // https://github.com/microsoft/vscode/blob/main/src/vscode-dts/vscode.proposed.mcpServerDefinitions.d.ts | ||
|
|
||
| declare module 'vscode' { | ||
|
|
||
| export class McpStdioServerDefinition { | ||
| readonly label: string; | ||
| cwd?: Uri; | ||
| command: string; | ||
| args: string[]; | ||
| env: Record<string, string | number | null>; | ||
| version?: string; | ||
| constructor(label: string, command: string, args?: string[], env?: Record<string, string | number | null>, version?: string); | ||
| } | ||
|
|
||
| export class McpHttpServerDefinition { | ||
| readonly label: string; | ||
| uri: Uri; | ||
| headers: Record<string, string>; | ||
| version?: string; | ||
| constructor(label: string, uri: Uri, headers?: Record<string, string>, version?: string); | ||
| } | ||
|
|
||
| export type McpServerDefinition = McpStdioServerDefinition | McpHttpServerDefinition; | ||
|
|
||
| export interface McpServerDefinitionProvider<T extends McpServerDefinition = McpServerDefinition> { | ||
| readonly onDidChangeMcpServerDefinitions?: Event<void>; | ||
| provideMcpServerDefinitions(token: CancellationToken): ProviderResult<T[]>; | ||
| resolveMcpServerDefinition?(server: T, token: CancellationToken): ProviderResult<T>; | ||
| } | ||
|
|
||
| export namespace lm { | ||
| export function registerMcpServerDefinitionProvider(id: string, provider: McpServerDefinitionProvider): Disposable; | ||
| } | ||
| } |
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.