Skip to content

Added cosmos shell extension.#2536

Open
mkrueger wants to merge 37 commits intomicrosoft:mainfrom
mkrueger:dev/mkrueger/cosmos_shell
Open

Added cosmos shell extension.#2536
mkrueger wants to merge 37 commits intomicrosoft:mainfrom
mkrueger:dev/mkrueger/cosmos_shell

Conversation

@mkrueger
Copy link
Copy Markdown
Member

@mkrueger mkrueger commented Jan 17, 2025

Add Cosmos DB Shell integration

Integrates the external Cosmos DB Shell (cosmosdbshell CLI / .NET tool) into the extension. Users can launch a connected shell from the resource tree and optionally expose it as an MCP server for GitHub Copilot.

Highlights

  • New command NoSQL: Launch Cosmos DB Shell with context-menu entries on NoSQL database/container items (gated by vscodeDatabases.cosmosDBShellSupportEnabled).
  • Unified connect/launch flow that reuses unconnected terminals opened from the command palette, with early-exit monitoring for clear error messages when the shell is missing.
  • Authentication: connection string passthrough, emulator (no creds), Entra ID (token via getAccessTokenForVSCode with fallback handling), and managed identity.
  • Cross-platform command resolution (cosmosDBShellCommandResolver.ts): walks PATH/PATHEXT on Windows and unwraps dotnet tool .cmd/.bat shims; passthrough on macOS/Linux. Honors a configured absolute path and surfaces actionable errors.
  • MCP server provider (cosmosDbShellMcpProvider) that exposes the shell over HTTP on 127.0.0.1 at a configurable port and refreshes when shell settings change.
  • Language contribution for .csh (cosmosdbshell) with basic bracket/comment/auto-closing config.

New settings

Setting Default Purpose
cosmosDB.shell.path null Optional explicit path to the cosmosdbshell executable.
cosmosDB.shell.MCP.enabled false Expose the shell as an MCP server.
cosmosDB.shell.MCP.port 6128 Port for the MCP HTTP endpoint (127.0.0.1).

Notes

  • Uses the proposed mcpServerDefinitionProviders API (typings vendored in vscode.proposed.d.ts).
  • Adds vscode-languageclient ~9.0.1.
  • Requires the user to install cosmosdbshell separately; degrades gracefully when not found.
  • Unit tests cover Windows command resolution and MCP endpoint formatting.

@mkrueger mkrueger requested a review from a team as a code owner January 17, 2025 12:04
@mkrueger mkrueger requested a review from sevoku January 17, 2025 12:04
@mkrueger mkrueger force-pushed the dev/mkrueger/cosmos_shell branch from 1ff098d to 23e9166 Compare January 17, 2025 12:19
@mkrueger mkrueger force-pushed the dev/mkrueger/cosmos_shell branch from 74a8e01 to e889376 Compare June 4, 2025 12:27
@mkrueger mkrueger force-pushed the dev/mkrueger/cosmos_shell branch 8 times, most recently from 9a75647 to b988636 Compare July 18, 2025 13:06
Comment thread package.json Outdated
Comment thread src/cosmosShell/CosmosShellExtension.ts Outdated
Comment thread package.json Outdated
Comment thread src/cosmosShell/CosmosShellExtension.ts Outdated
@mkrueger mkrueger force-pushed the dev/mkrueger/cosmos_shell branch from 19f5bc1 to 8103cd6 Compare July 22, 2025 09:24
@mkrueger mkrueger force-pushed the dev/mkrueger/cosmos_shell branch 2 times, most recently from 41f8a97 to cc9114b Compare September 8, 2025 13:51
@mkrueger mkrueger force-pushed the dev/mkrueger/cosmos_shell branch from 1d23eb9 to 63b3193 Compare November 5, 2025 11:57
@mkrueger mkrueger force-pushed the dev/mkrueger/cosmos_shell branch from 63b3193 to d266276 Compare January 14, 2026 10:45
@mkrueger
Copy link
Copy Markdown
Member Author

We should bump vs code in main at some point - it's getting hard to update this branch.

@mkrueger mkrueger force-pushed the dev/mkrueger/cosmos_shell branch 4 times, most recently from fd31d4d to 99694cf Compare January 21, 2026 12:42
mkrueger added a commit to mkrueger/vscode-cosmosdb that referenced this pull request Jan 21, 2026
- Implemented Cosmos Shell extension with MCP server integration
- Added credential support for Cosmos Shell (including Entra ID)
- Added MCP configuration settings
- Added LSP server support
- Added l10n localization strings
- Added settings button to error messages
- Fixed various configuration and import issues
@mkrueger mkrueger force-pushed the dev/mkrueger/cosmos_shell branch from 99694cf to 312cb64 Compare January 21, 2026 13:56
mkrueger added a commit to mkrueger/vscode-cosmosdb that referenced this pull request Jan 21, 2026
    - Implemented Cosmos Shell extension with MCP server integration
    - Added credential support for Cosmos Shell (including Entra ID)
    - Added MCP configuration settings
    - Added LSP server support
    - Added l10n localization strings
    - Added settings button to error messages
    - Fixed various configuration and import issues
@mkrueger mkrueger force-pushed the dev/mkrueger/cosmos_shell branch from 312cb64 to 9c00c4f Compare January 21, 2026 14:10
mkrueger added a commit to mkrueger/vscode-cosmosdb that referenced this pull request Jan 21, 2026
        - Implemented Cosmos Shell extension with MCP server integration
        - Added credential support for Cosmos Shell (including Entra ID)
        - Added MCP configuration settings
        - Added LSP server support
        - Added l10n localization strings
        - Added settings button to error messages
        - Fixed various configuration and import issues
@mkrueger mkrueger force-pushed the dev/mkrueger/cosmos_shell branch from 9c00c4f to 81bddf7 Compare January 21, 2026 14:17
@mkrueger mkrueger force-pushed the dev/mkrueger/cosmos_shell branch from 9539f4d to 9b21587 Compare April 22, 2026 07:47
@mkrueger mkrueger force-pushed the dev/mkrueger/cosmos_shell branch from 9b21587 to d523568 Compare April 22, 2026 07:53
…ndependent

- Rename folder src/cosmosShell -> src/cosmosDBShell, files and identifiers (CosmosShell* -> CosmosDBShell*, cosmosshell -> cosmosdbshell).
- Rename env vars COSMOS_SHELL_ACCOUNT_KEY/COSMOS_SHELL_TOKEN -> COSMOSDB_SHELL_ACCOUNT_KEY/COSMOSDB_SHELL_TOKEN.
- Update VS Code contributions (command id, context keys, language id, NLS keys).
- Use path.win32.* in the Windows branch of cosmosDBShellCommandResolver so unit tests pass on Linux CI.
Copy link
Copy Markdown
Member

@sevoku sevoku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, works much better now with the latest Shell build! Will approve after BugBash if no new issues come up.

@sevoku sevoku self-requested a review April 28, 2026 11:00
mkrueger added 2 commits May 4, 2026 14:11
- Show command on tree items even when shell isn't installed
- Detect .NET SDK and offer guided install via dotnet tool
- Stream install output, detect success/failure, auto-relaunch
- Chain SDK install -> tool install via .NET Install Tool extension
- Offer Reload Window when PATH isn't refreshed yet
Fixes AzureCosmosDB/cosmosdb-shell-preview#24. Track per-terminal launch state (endpoint + auth mode + tenant/MI client id) instead of just the endpoint, and always send 'connect <endpoint>' before navigating an existing terminal so a previously disconnected shell is re-attached. Reuse only when launch-time env credentials (account key / Entra fallback token) match; otherwise spawn a new shell so the right env vars get baked into the process.
mkrueger and others added 3 commits May 5, 2026 12:18
After acquiring the .NET SDK via the .NET Install Tool, PATH may not yet be
refreshed in the current VS Code session, so 'dotnet --list-sdks' on a bare
'dotnet' lookup fails and the install flow stalls silently. Plumb the
returned dotnetPath through isDotNetSdkInstalled and the dotnet tool install
spawn, and auto-chain into the Cosmos DB Shell install + launch instead of
asking the user to confirm again.
@sevoku sevoku force-pushed the dev/mkrueger/cosmos_shell branch from 2ef4233 to 71e063e Compare May 5, 2026 19:58
@sevoku sevoku requested a review from Copilot May 5, 2026 20:06
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Integrates the external Cosmos DB Shell CLI into the extension, adding a launch command, optional MCP server exposure, and basic language support for .csh scripts.

Changes:

  • Adds Cosmos DB Shell activation + command registration and wires MCP provider + LSP startup into extension activation.
  • Implements command resolution (with Windows PATH/PATHEXT + dotnet tool shim support) and MCP endpoint helpers with unit tests.
  • Adds VS Code contributions for settings, command/menu entry, and a new cosmosdbshell language configuration.

Reviewed changes

Copilot reviewed 13 out of 14 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
src/tree/cosmosdb/CosmosDBAccountResourceItem.ts Switches account icon helper to URI-based implementation.
src/tree/cosmosdb/CosmosDBAccountAttachedResourceItem.ts Improves tooltip composition + switches icon helper.
src/extension.ts Activates Cosmos DB Shell integration and registers MCP/LSP hooks.
src/cosmosDBShell/cosmosDBShellMcpEndpoint.ts Adds helper for MCP endpoint formatting.
src/cosmosDBShell/cosmosDBShellMcpEndpoint.test.ts Adds unit test for MCP endpoint formatting.
src/cosmosDBShell/cosmosDBShellCommandResolver.ts Adds cross-platform shell command resolution (Windows PATH + shim unwrapping).
src/cosmosDBShell/cosmosDBShellCommandResolver.test.ts Adds unit tests for Windows command resolution behavior.
src/cosmosDBShell/configuration.json Adds language configuration (brackets/comments/autoclosing) for .csh.
src/cosmosDBShell/CosmosDBShellExtension.ts Adds main Cosmos DB Shell integration: terminal orchestration, install prompts, MCP provider, LSP client.
src/constants.ts Adds getThemeAgnosticIconURI helper.
package.nls.json Adds localized strings for the new command/settings.
package.json Adds vscode-languageclient, language contribution, command/menu, settings, and MCP provider contribution.
l10n/bundle.l10n.json Adds localized strings used by the Cosmos DB Shell flows.

Comment thread src/extension.ts
ext.fileSystem = new DatabasesFileSystem();

const cosmosDBShellSupport: CosmosDBShellExtension = new CosmosDBShellExtension();
await cosmosDBShellSupport.activate();
Comment on lines +165 to +174
const listener = vscode.window.onDidCloseTerminal((closedTerminal) => {
listener.dispose();
if (closedTerminal === terminal && Date.now() - startTime < 5000) {
const exitCode = closedTerminal.exitStatus?.code;
const exitReason = closedTerminal.exitStatus?.reason;
ext.outputChannel.error(
`Cosmos DB Shell exited early.${exitCode !== undefined ? ` Exit code: ${exitCode}.` : ''}${exitReason !== undefined ? ` Reason: ${exitReason}.` : ''}`,
);
}
});
Comment on lines +46 to +49
function resolveWindowsCommand(command: string, env: NodeJS.ProcessEnv): string | undefined {
if (isExplicitPath(command)) {
return isFile(command) ? command : undefined;
}
Comment thread package.json
Comment on lines +628 to +633
{
"//": "[Database] Launch Cosmos DB Shell",
"command": "cosmosDB.launchCosmosDBShell",
"when": "view =~ /azure(ResourceGroups|Workspace|FocusView)/ && (viewItem =~ /treeitem[.]database(?![a-z.\\/])/i || viewItem =~ /treeitem[.]container(?![a-z.\\/])/i) && viewItem =~ /experience[.]core/i",
"group": "1@4"
},
Comment on lines +7 to +10
* entry-point for mongoClusters-related code. Activated from ./src/extension.ts
*
* We'll try to have everything related to mongoClusters-support managed from here.
* In case of a failure with this plan, this comment section will be updated.
Comment on lines +592 to +596
const rawConnectionString = node.model.accountInfo.endpoint;
if (!rawConnectionString) {
void vscode.window.showErrorMessage(l10n.t('Failed to extract the connection string from the selected node.'));
return;
}
Comment thread src/constants.ts
Comment on lines +41 to +48
export function getThemeAgnosticIconURI(iconName: string): IconPath {
const iconPath = Uri.joinPath(ext.context.extensionUri, 'resources', 'icons', 'theme-agnostic', iconName);
assert.ok(fs.existsSync(iconPath.fsPath), `Icon not found: ${iconPath.fsPath}`);
return {
light: iconPath,
dark: iconPath,
};
}
Comment on lines +132 to +134
// Create a singleton instance to access the context updater
//const cosmosDBShellExt = new CosmosDBShellExtension();

Resolved conflicts:
- src/tree/cosmosdb/CosmosDBAccountAttachedResourceItem.ts: kept main's spread-based return shape; kept branch's getThemeAgnosticIconURI call
- src/tree/cosmosdb/CosmosDBAccountResourceItem.ts: same as above
- package-lock.json: regenerated from main

Migrated src/cosmosDBShell/cosmosDBShellCommandResolver.test.ts from jest to vitest.
@sevoku sevoku force-pushed the dev/mkrueger/cosmos_shell branch from 7f8da65 to 7bacabf Compare May 5, 2026 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants