Nex VS Code
A VS Code extension that bridges Nex with VS Code through the Model Context Protocol (MCP). This extension allows Nex to interact with your code editor, read files, apply edits, and explore your workspace.
Features
The extension spawns an MCP server that provides the following tools for Nex:
File Operations
- read_file: Read contents of files from the workspace (supports line ranges)
- apply_edit: Apply text edits to files using diff-like operations
- show_document: Open and navigate to specific files and positions
Editor Interaction
- get_active_editor: Get information about the currently active editor
- get_selection: Retrieve the currently selected text and its range
Workspace Exploration
- list_workspace_files: List files with optional glob pattern filtering
- search_files: Search for text across files in the workspace
- get_workspace_folders: Get all workspace folders
Diagnostics
- get_diagnostics: Retrieve errors and warnings from the workspace
Installation
- Clone this repository
- Install dependencies:
npm install
- Compile the extension:
npm run compile
- Press F5 to open a new VS Code window with the extension loaded
Usage
Starting the MCP Server
The MCP server starts automatically when the extension activates. You can also manually control it:
- Start Server: Run command
Nex: Start MCP Server
- Stop Server: Run command
Nex: Stop MCP Server
- Check Status: Run command
Nex: Get Server Status
Connecting Nex
The MCP server runs as an HTTP server inside the VS Code extension using the MCP Streamable HTTP transport. By default, it runs on http://localhost:3000. You can configure the port in VS Code settings:
- Open VS Code Settings (Cmd+,)
- Search for "Nex VS Code Bridge"
- Set "Server Port" to your desired port number
To connect Nex to the server:
{
"mcpServers": {
"nex-vscode": {
"url": "http://localhost:3000/mcp"
}
}
}
API Endpoints
GET /health - Health check endpoint
POST /mcp - MCP HTTP endpoint for client connections
read_file
{
"path": "src/extension.ts",
"startLine": 10,
"endLine": 20
}
get_active_editor
Returns information about the active editor including file path, language, selection, etc.
get_selection
Returns the selected text and its range in the active editor.
apply_edit
{
"path": "src/extension.ts",
"edits": [
{
"startLine": 10,
"endLine": 12,
"newText": "// New code here\n"
}
]
}
list_workspace_files
{
"pattern": "**/*.ts",
"maxResults": 100
}
search_files
{
"query": "function activate",
"isRegex": false,
"includePattern": "src/**",
"maxResults": 50
}
get_workspace_folders
Returns all workspace folders with their names and paths.
show_document
{
"path": "src/extension.ts",
"line": 10,
"column": 5
}
get_diagnostics
{
"path": "src/extension.ts"
}
Development
Build
npm run compile
Watch Mode
npm run watch
Run Tests
npm test
Architecture
- extension.ts: Main extension entry point that spawns and manages the MCP server
- mcpServer.ts: MCP server implementation that handles tool calls and interacts with VS Code API
- esbuild.js: Build configuration for both extension and MCP server