VSCode Command Server Extension
A VSCode extension that provides an HTTP server to execute VSCode commands from external applications like Python, TypeScript, curl, and more.
Features
- 🚀 HTTP Server: Exposes VSCode commands via REST API
- 🔧 Command Execution: Execute any VSCode command remotely
- 📝 Command Discovery: Get list of all available commands
- 📊 Server Info: Monitor server status and workspace information
- 🌐 CORS Support: Enable cross-origin requests for web applications
Installation
- Clone this repository
- Install dependencies:
yarn install
- Compile the extension:
yarn compile
- Press
F5
to run the extension in development mode
Usage
Starting the Server
The extension automatically starts an HTTP server when activated. You can also manually control it:
- Open Command Palette (
Ctrl+Shift+P
)
- Run one of these commands:
Start Command Server
- Start the HTTP server
Stop Command Server
- Stop the HTTP server
Show Server Status
- Check if server is running
The server will start on port 3000 by default (or next available port).
API Endpoints
GET /
- Server Status
Check if the server is running.
curl http://localhost:3000/
Get server details including port, PID, and workspace.
curl http://localhost:3000/info
GET /commands
- List Available Commands
Get all available VSCode commands.
curl http://localhost:3000/commands
POST /execute
- Execute Command
Execute a VSCode command with optional arguments.
curl -X POST http://localhost:3000/execute \
-H "Content-Type: application/json" \
-d '{"command": "workbench.action.showCommands"}'
With arguments:
curl -X POST http://localhost:3000/execute \
-H "Content-Type: application/json" \
-d '{"command": "workbench.action.openSettings", "args": ["editor"]}'
Client Examples
Python Client
from examples.http_client_new import VSCodeHTTPClient
client = VSCodeHTTPClient(port=3000)
# Check status
status = client.check_status()
print(status)
# Execute command
result = client.execute_command("workbench.action.showCommands")
print(result)
TypeScript Client
import { VSCodeHTTPClient } from './examples/http-client';
const client = new VSCodeHTTPClient(3000);
// Execute command
const result = await client.executeCommand("workbench.action.toggleTerminal");
console.log(result);
curl Examples
Run the provided script:
chmod +x examples/curl-examples.sh
./examples/curl-examples.sh 3000
Common Commands
Here are some useful VSCode commands you can execute:
workbench.action.showCommands
- Show command palette
workbench.action.openSettings
- Open settings
workbench.action.terminal.toggleTerminal
- Toggle terminal
workbench.action.files.newUntitledFile
- Create new file
workbench.action.files.save
- Save current file
workbench.action.closeActiveEditor
- Close current editor
workbench.action.quickOpen
- Quick open files
All API responses follow this format:
{
"success": true,
"result": "Command result (if any)",
"command": "executed.command.name",
"error": "Error message (if failed)"
}
Development
Building
yarn compile # Compile TypeScript
yarn watch # Watch for changes
yarn package # Build for production
Testing
yarn test # Run tests
yarn lint # Run linter
Security Notes
- The server only accepts connections from localhost (127.0.0.1)
- CORS is enabled for development convenience
- Consider security implications before exposing to external networks
License
MIT License - see LICENSE file for details.