Skip to content

Conversation

@bwateratmsft
Copy link
Contributor

Fixes #268487.

This PR adds support for doing StreamableHTTP MCP servers over Unix domain sockets and named pipes. For local MCP servers, this is generally more secure than standard localhost HTTP. Standard IO servers are still preferable for local MCP servers, but some scenarios are better served by StreambleHTTP--for example, an MCP server can be hosted in the extension host process by an extension using this approach.

/cc @connor4312

Below is some sample extension code. In practice, a random pipe/socket name should be used, and permissions enforced as well, but this shows the gist.

export function activate() {

    const isWindows = os.platform() === 'win32';
    const socketPath = isWindows ? '\\\\.\\pipe\\hello-world' : path.join(os.tmpdir(), 'hello-world.sock');

    const socketUri = vscode.Uri.from({
        scheme: isWindows ? 'pipe' : 'unix',
        path: socketPath,
        fragment: '/mcp' // The express app below is configured to serve MCP over the `/mcp` route
    });

    vscode.lm.registerMcpServerDefinitionProvider('hello-world', {
        provideMcpServerDefinitions(token: vscode.CancellationToken): vscode.McpServerDefinition[] {
            return [
                new vscode.McpHttpServerDefinition(
                    'hello-world',
                    socketUri,
                ),
            ];
        },
        resolveMcpServerDefinition(server: vscode.McpServerDefinition, token: vscode.CancellationToken): vscode.McpServerDefinition {
            startMcpServer(socketPath); // Additionally, the server should also be closed on extension deactivation
            return server;
        }
    });

}

function startMcpServer(socketPath: string) {
    // Uses express, same as the MCP TypeScript SDK examples
    const app = express();

    // MCP StreamableHTTP server setup, refer to examples at https://www.npmjs.com/package/@modelcontextprotocol/sdk#streamable-http
    // ...

    // Listen on the socket/named pipe
    app.listen(socketPath);
}

Copilot AI review requested due to automatic review settings September 26, 2025 15:28
@bwateratmsft bwateratmsft changed the title Add support for MCP servers over Unix Domain Sockets and Named Pipes Add support for MCP servers over Unix domain sockets and named pipes Sep 26, 2025
Copy link
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

This PR adds support for MCP (Model Context Protocol) servers over Unix domain sockets and named pipes, providing a more secure alternative to localhost HTTP for local MCP servers while still supporting StreamableHTTP scenarios.

Key changes:

  • Extends the MCP HTTP handling to support Unix domain sockets (unix://) and named pipes (pipe://) schemes
  • Introduces a Node.js-specific HTTP handler that uses the undici library for socket-based connections
  • Adds the undici dependency to handle low-level HTTP over Unix sockets and named pipes

Reviewed Changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/vs/workbench/api/node/extHostMcpNode.ts Implements Node.js-specific MCP HTTP handler with Unix socket and named pipe support using undici
src/vs/workbench/api/common/extHostMcp.ts Refactors base MCP HTTP handler to be extensible and adds common interfaces for fetch operations
package.json Adds undici dependency for Node.js HTTP over Unix sockets functionality

@bwateratmsft
Copy link
Contributor Author

Not sure what I'm supposed to do about the failing check for package-lock.json edits...

Copy link
Member

@connor4312 connor4312 left a comment

Choose a reason for hiding this comment

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

A few nits but overall good

@connor4312 connor4312 closed this pull request by merging all changes into microsoft:main in 2aaf297 Sep 26, 2025
@bwateratmsft bwateratmsft deleted the bmw/mcpOverUDS3 branch September 26, 2025 19:14
@vs-code-engineering vs-code-engineering bot locked and limited conversation to collaborators Nov 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP servers using StreamableHTTP should allow for Unix domain sockets / named pipes

3 participants