Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@
- `Coder: Open Workspace in Agents Window` opens a workspace in the VS Code
Agents window, starting it first if needed. It opens the template's
directory, or the folder you last opened on the workspace.
- Chat and the Agents window can use the Coder deployment's MCP server when
the deployment enables the `mcp-server-http` experiment and the OAuth2
provider. Sign in to the "Coder" server from the MCP Servers view. Turn it
off with `coder.mcpServer.enabled`.

### Changed

- The extension activates when the editor starts, so its MCP server is
available in the Agents window. The "Remote SSH extension not found"
warning is shown once instead of on every activation.

## [v1.18.4](https://github.com/coder/vscode-coder/releases/tag/v1.18.4) 2026-12-03

Expand Down
15 changes: 14 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@
"type": "boolean",
"default": false
},
"coder.mcpServer.enabled": {
"markdownDescription": "Offer the Coder deployment's MCP server to chat and the Agents window. Only deployments with the `mcp-server-http` experiment and the OAuth2 provider enabled serve it. Sign in to it from the MCP Servers view.",
"type": "boolean",
"default": true,
"scope": "application"
},
"coder.disableSignatureVerification": {
"markdownDescription": "Disable Coder CLI signature verification, which can be useful if you run an unsigned fork of the binary.",
"type": "boolean",
Expand Down Expand Up @@ -330,6 +336,12 @@
}
}
},
"mcpServerDefinitionProviders": [
{
"id": "coder",
"label": "Coder"
}
],
"viewsContainers": {
"activitybar": [
{
Expand Down Expand Up @@ -841,7 +853,8 @@
"activationEvents": [
"onResolveRemoteAuthority:ssh-remote",
"onCommand:coder.connect",
"onUri"
"onUri",
"onStartupFinished"
],
"dependencies": {
"@abraham/reflection": "^0.14.0",
Expand Down
43 changes: 36 additions & 7 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
ActivationTelemetry,
type ActivationTracer,
} from "./instrumentation/activation";
import { registerMcpServerProvider } from "./mcp/mcpServerProvider";
import { OAuthSessionManager } from "./oauth/sessionManager";
import { ConnectionSetup } from "./remote/connectionSetup";
import { Remote } from "./remote/remote";
Expand All @@ -38,6 +39,9 @@ import { WorkspaceProvider } from "./workspace/workspacesProvider";

import type { WorkspaceFilter } from "@repo/shared";

import type { Logger } from "./logging/logger";
import type { MementoManager } from "./storage/mementoManager";

const MY_WORKSPACES_TREE_ID = "myWorkspaces";
const SHARED_WORKSPACES_TREE_ID = "sharedWorkspaces";
const ALL_WORKSPACES_TREE_ID = "allWorkspaces";
Expand Down Expand Up @@ -70,6 +74,8 @@ async function doActivate(
// Means that vscodium is not supported by this for now

const remoteSshExtension = getRemoteSshExtension();
const output = serviceContainer.getLogger();
const mementoManager = serviceContainer.getMementoManager();

let vscodeProposed: typeof vscode = vscode;

Expand All @@ -80,18 +86,12 @@ async function doActivate(
vscodeProposed = extensionRequire("vscode") as typeof vscode;
} else if (!isAgentsWindow()) {
// The Agents window disables Remote SSH, so its absence there is expected.
vscode.window.showErrorMessage(
"Remote SSH extension not found, this may not work as expected.\n" +
// NB should we link to documentation or marketplace?
"Please install your choice of Remote SSH extension from the VS Code Marketplace.",
);
await warnRemoteSshMissing(mementoManager, output);
}

// Initialize the global vscodeProposed module for use throughout the extension
initVscodeProposed(vscodeProposed);

const output = serviceContainer.getLogger();
const mementoManager = serviceContainer.getMementoManager();
const secretsManager = serviceContainer.getSecretsManager();
const contextManager = serviceContainer.getContextManager();
const commandManager = serviceContainer.getCommandManager();
Expand Down Expand Up @@ -180,6 +180,15 @@ async function doActivate(
);
ctx.subscriptions.push(announcementManager);

const mcpServerRegistration = registerMcpServerProvider(
client,
deploymentManager.session,
output,
);
if (mcpServerRegistration) {
ctx.subscriptions.push(mcpServerRegistration);
}

// The deprecated Tasks panel only shows on deployments old enough to
// still support it, which requires fetching the deployment version.
const updateTasksSupported = async () => {
Expand Down Expand Up @@ -594,6 +603,26 @@ async function doActivate(
}
}

/**
* Shows the missing Remote SSH warning once per install and logs it after
* that, since the extension activates at startup in every window.
*/
async function warnRemoteSshMissing(
mementoManager: MementoManager,
logger: Logger,
): Promise<void> {
logger.warn("Remote SSH extension not found");
if (mementoManager.hasShownRemoteSshMissing()) {
return;
}
await mementoManager.setShownRemoteSshMissing();
void vscode.window.showErrorMessage(
"Remote SSH extension not found, this may not work as expected.\n" +
// NB should we link to documentation or marketplace?
"Please install your choice of Remote SSH extension from the VS Code Marketplace.",
);
}

/**
* Migrates old flat storage (sessionToken) to new label-based map storage.
* This is a one-time operation that runs on extension activation.
Expand Down
145 changes: 145 additions & 0 deletions src/mcp/mcpServerProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import * as vscode from "vscode";

import { removeTrailingSlashes } from "../common/url";

import type { CoderApi } from "../api/coderApi";
import type { SessionData, SessionState } from "../deployment/sessionStore";
import type { Logger } from "../logging/logger";

const MCP_SERVER_PROVIDER_ID = "coder";
const MCP_ENDPOINT = "/api/experimental/mcp/http";
const ENABLED_SETTING = "coder.mcpServer.enabled";

/**
* Registers the Coder MCP server provider. Returns undefined when the editor
* lacks the MCP API, as some VS Code forks do.
*/
export function registerMcpServerProvider(
client: Pick<CoderApi, "getExperiments" | "getAxiosInstance">,
sessionState: SessionState,
logger: Logger,
): vscode.Disposable | undefined {
const provider = new McpServerProvider(client, sessionState, logger);
try {
const registration = vscode.lm.registerMcpServerDefinitionProvider(
MCP_SERVER_PROVIDER_ID,
provider,
);
return {
dispose: () => {
registration.dispose();
provider.dispose();
},
};
} catch (error) {
provider.dispose();
logger.info("This editor does not support MCP server definitions", error);
return undefined;
}
}

/**
* Offers the deployment's hosted MCP server, when it serves one, to VS Code
* chat and the Agents window. VS Code signs in to it with its own OAuth flow,
* so the definition carries no credentials.
*/
export class McpServerProvider
implements vscode.McpServerDefinitionProvider, vscode.Disposable
{
readonly #onDidChange = new vscode.EventEmitter<void>();
readonly #disposables: vscode.Disposable[] = [];
#serverUrl: string | undefined;

public readonly onDidChangeMcpServerDefinitions = this.#onDidChange.event;

public constructor(
private readonly client: Pick<
CoderApi,
"getExperiments" | "getAxiosInstance"
>,
private readonly sessionState: SessionState,
private readonly logger: Logger,
) {
this.#disposables.push(
this.sessionState.onDidChange((session) => {
void this.detect(session);
}),
vscode.workspace.onDidChangeConfiguration((e) => {
if (e.affectsConfiguration(ENABLED_SETTING)) {
this.#onDidChange.fire();
}
}),
);
void this.detect(this.sessionState.current);
}

public provideMcpServerDefinitions(): vscode.McpHttpServerDefinition[] {
const enabled = vscode.workspace
.getConfiguration()
.get<boolean>(ENABLED_SETTING, true);
if (!enabled || !this.#serverUrl) {
return [];
}
return [
new vscode.McpHttpServerDefinition(
"Coder",
vscode.Uri.parse(this.#serverUrl),
),
];
}

public dispose(): void {
for (const disposable of this.#disposables) {
disposable.dispose();
}
this.#onDidChange.dispose();
}

private async detect(session: SessionData): Promise<void> {
if (session.kind !== "signedIn") {
this.setServerUrl(undefined);
return;
}
const serverUrl = `${removeTrailingSlashes(session.deployment.url)}${MCP_ENDPOINT}`;
if (this.#serverUrl !== serverUrl) {
this.setServerUrl(undefined);
}
const available = await this.isServerAvailable();
// A sign-out or deployment switch during the checks supersedes them.
if (this.sessionState.current === session) {
this.setServerUrl(available ? serverUrl : undefined);
}
}

/**
* The endpoint authenticates before checking its gates, so an
* unauthenticated probe returns 401 even when disabled. Check the gates
* directly: the `mcp-server-http` experiment and the OAuth2 provider, whose
* resource metadata VS Code needs to sign in.
*/
private async isServerAvailable(): Promise<boolean> {
try {
const experiments = await this.client.getExperiments();
if (!experiments.includes("mcp-server-http")) {
this.logger.debug("Coder MCP server unavailable: experiment disabled");
return false;
}
await this.client
.getAxiosInstance()
.get(`/.well-known/oauth-protected-resource${MCP_ENDPOINT}`);
this.logger.info("Coder MCP server available");
return true;
} catch (error) {
this.logger.debug("Coder MCP server unavailable", error);
return false;
}
}

private setServerUrl(url: string | undefined): void {
if (this.#serverUrl === url) {
return;
}
this.#serverUrl = url;
this.#onDidChange.fire();
}
}
10 changes: 10 additions & 0 deletions src/storage/mementoManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const MAX_URLS = 10;
const DEPLOYMENT_ACCESS_PREFIX = "coder.access.";
const SURFACED_BANNERS_PREFIX = "coder.surfacedBanners.";
const DISMISSED_SSH_OPTIONS_PREFIX = "coder.dismissedSshOptions.";
const REMOTE_SSH_MISSING_SHOWN_KEY = "coder.remoteSshMissingShown";

const KeysSchema = z.array(z.string());

Expand Down Expand Up @@ -108,6 +109,15 @@ export class MementoManager {
await this.memento.update("url", undefined);
}

/** Whether the missing Remote SSH extension warning was already shown. */
public hasShownRemoteSshMissing(): boolean {
return this.memento.get<boolean>(REMOTE_SSH_MISSING_SHOWN_KEY) === true;
}

public async setShownRemoteSshMissing(): Promise<void> {
await this.memento.update(REMOTE_SSH_MISSING_SHOWN_KEY, true);
}

public getSurfacedBanners(safeHostname: string): string[] {
return this.getKeys(SURFACED_BANNERS_PREFIX + safeHostname);
}
Expand Down
13 changes: 13 additions & 0 deletions test/mocks/vscode.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,17 @@ export const extensions = {
all: [] as unknown[],
};

export class McpHttpServerDefinition {
constructor(
public readonly label: string,
public readonly uri: Uri,
) {}
}

export const lm = {
registerMcpServerDefinitionProvider: vi.fn(() => ({ dispose: vi.fn() })),
};

export const version = "1.106.0-test";

const vscode = {
Expand All @@ -331,6 +342,8 @@ const vscode = {
workspace,
env,
extensions,
McpHttpServerDefinition,
lm,
version,
};

Expand Down
1 change: 1 addition & 0 deletions test/scopes/probes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const apiProbes = {
getBuildInfo: ({ scoped }) => scoped.getBuildInfo(),
getAuthenticatedUser: ({ scoped }) => scoped.getAuthenticatedUser(),
getAppearance: ({ scoped }) => scoped.getAppearance(),
getExperiments: ({ scoped }) => scoped.getExperiments(),
getDeploymentSSHConfig: ({ scoped }) => scoped.getDeploymentSSHConfig(),
getWorkspaces: async ({ scoped }) =>
assertNonEmpty((await scoped.getWorkspaces({ q: "owner:me" })).workspaces),
Expand Down
Loading
Loading