Skip to content

Commit c293a8d

Browse files
committed
Add CHANGELOG.md for version tracking, revert module type to CommonJS in package.json, update tsconfig.json for CommonJS compatibility, and refactor imports in source files to remove .js extensions. Fix critical issues related to ES Module compatibility and improve WebSocket server initialization.
1 parent 66cbf39 commit c293a8d

File tree

7 files changed

+121
-21
lines changed

7 files changed

+121
-21
lines changed

CHANGELOG.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Change Log
2+
3+
All notable changes to the "MCP VSCode Commands" extension will be documented in this file.
4+
5+
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
6+
7+
## [Unreleased]
8+
9+
## [0.1.2] - 2025-08-15
10+
11+
### 🐛 Fixed
12+
- **Critical**: Fixed ES Module compatibility issue preventing extension activation
13+
- Reverted from ESM to CommonJS module system for VSCode compatibility
14+
- Maintained dynamic imports for @modelcontextprotocol/sdk (ESM package)
15+
- **Critical**: Fixed "undefined_publisher" issue by adding publisher field to package.json
16+
- Fixed async/await usage in WebSocket server initialization
17+
18+
### 🔧 Changed
19+
- Updated TypeScript configuration:
20+
- Module output: CommonJS (required for VSCode extensions)
21+
- Target: ES2022 (for modern JavaScript features)
22+
- Added moduleResolution: "node" for better compatibility
23+
- Removed `.js` extensions from local imports (CommonJS style)
24+
- Optimized `.vscodeignore` to reduce package size
25+
26+
### ✨ Added
27+
- Added `publisher` field in package.json (louisfghbvc)
28+
- Created `.vscodeignore` file to exclude unnecessary files from VSIX package
29+
- Added this CHANGELOG.md file
30+
31+
## [0.1.1] - 2025-08-14
32+
33+
### ✨ Added
34+
- WebSocket server support on port 3001 for remote MCP connections
35+
- Enhanced error handling with detailed error messages
36+
- Improved logging system with timestamp and context
37+
38+
### 🔧 Changed
39+
- Improved command execution result serialization
40+
- Better handling of VSCode-specific objects (URI, Range, Position)
41+
- Enhanced command listing with filtering support
42+
43+
### 📚 Documentation
44+
- Added WebSocket configuration examples
45+
- Updated README with connection instructions
46+
47+
## [0.1.0] - 2025-08-14
48+
49+
### 🎉 Initial Release
50+
51+
#### Core Features
52+
- **MCP Server Implementation**: Full Model Context Protocol server for VSCode
53+
- **Command Execution**: Execute any VSCode command via MCP protocol
54+
- **Command Discovery**: List and filter all available VSCode commands
55+
- **Auto-start Support**: Configurable automatic server startup
56+
57+
#### Tools Available
58+
- `vscode.executeCommand`: Execute VSCode commands with arguments
59+
- `vscode.listCommands`: List all available commands with optional filtering
60+
61+
#### Configuration
62+
- `mcpVscodeCommands.autoStart`: Auto-start server on extension activation (default: true)
63+
- `mcpVscodeCommands.logLevel`: Configure logging verbosity (debug|info|warn|error)
64+
65+
#### Transport Support
66+
- Stdio transport for local connections
67+
- WebSocket transport for remote connections (port 3001)
68+
69+
#### Developer Features
70+
- TypeScript implementation with strict typing
71+
- Comprehensive error handling
72+
- Detailed logging for debugging
73+
- Clean architecture with separated concerns
74+
75+
---
76+
77+
## Version History Summary
78+
79+
| Version | Date | Status | Key Changes |
80+
|---------|------|--------|-------------|
81+
| 0.1.2 | 2025-01-15 | Current | Fixed critical ES Module compatibility issues |
82+
| 0.1.1 | 2025-01-14 | Released | Added WebSocket support |
83+
| 0.1.0 | 2025-01-13 | Released | Initial release with core MCP functionality |
84+
85+
## Links
86+
- [GitHub Repository](https://github.com/louisfghbvc/mcp-vscode-commands)
87+
- [Report Issues](https://github.com/louisfghbvc/mcp-vscode-commands/issues)
88+
- [Model Context Protocol](https://modelcontextprotocol.io/)

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"version": "0.1.2",
66
"author": "louisfghbvc",
77
"publisher": "louisfghbvc",
8-
"type": "module",
98
"engines": {
109
"vscode": "^1.74.0"
1110
},

src/extension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as vscode from 'vscode';
2-
import { MCPVSCodeServer } from './mcp-server.js';
3-
import { MCPServerConfig } from './types.js';
2+
import { MCPVSCodeServer } from './mcp-server';
3+
import { MCPServerConfig } from './types';
44

55
let mcpServer: MCPVSCodeServer | undefined;
66

src/mcp-server.ts

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import * as vscode from 'vscode';
2-
import WebSocket from 'ws';
3-
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
4-
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
5-
import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
6-
import { MCPServerConfig, CommandExecutionResult, LogContext } from './types.js';
7-
import { VSCodeCommandsTools } from './tools/vscode-commands.js';
2+
import * as WebSocket from 'ws';
3+
import { MCPServerConfig, CommandExecutionResult, LogContext } from './types';
4+
import { VSCodeCommandsTools } from './tools/vscode-commands';
5+
6+
// Dynamic imports for ES modules
7+
let Server: any;
8+
let StdioServerTransport: any;
9+
let CallToolRequestSchema: any;
10+
let ListToolsRequestSchema: any;
811

912
export class MCPVSCodeServer {
1013
private server: any;
@@ -22,10 +25,20 @@ export class MCPVSCodeServer {
2225
this.tools = new VSCodeCommandsTools(this.config);
2326
}
2427

25-
private initializeServer(): void {
28+
private async loadESModules(): Promise<void> {
2629
if (this.initialized) return;
2730

2831
try {
32+
// Dynamic import of ES modules
33+
const serverModule = await import('@modelcontextprotocol/sdk/server/index.js');
34+
const stdioModule = await import('@modelcontextprotocol/sdk/server/stdio.js');
35+
const typesModule = await import('@modelcontextprotocol/sdk/types.js');
36+
37+
Server = serverModule.Server;
38+
StdioServerTransport = stdioModule.StdioServerTransport;
39+
CallToolRequestSchema = typesModule.CallToolRequestSchema;
40+
ListToolsRequestSchema = typesModule.ListToolsRequestSchema;
41+
2942
// 初始化 MCP 服務器
3043
this.server = new Server({
3144
name: 'mcp-vscode-commands',
@@ -38,7 +51,7 @@ export class MCPVSCodeServer {
3851
this.initialized = true;
3952
this.log('info', 'MCP VSCode Server 已初始化');
4053
} catch (error) {
41-
this.log('error', 'Failed to initialize server', { error: String(error) });
54+
this.log('error', 'Failed to load ES modules', { error: String(error) });
4255
throw error;
4356
}
4457
}
@@ -167,8 +180,8 @@ export class MCPVSCodeServer {
167180

168181
async start(): Promise<void> {
169182
try {
170-
// Initialize server
171-
this.initializeServer();
183+
// Load ES modules first
184+
await this.loadESModules();
172185

173186
// 同時啟動 stdio 和 WebSocket transport
174187
await this.startStdioTransport();
@@ -189,11 +202,11 @@ export class MCPVSCodeServer {
189202
}
190203

191204
private async startWebSocketServer(): Promise<void> {
192-
return new Promise(async (resolve, reject) => {
205+
return new Promise((resolve, reject) => {
193206
try {
194207
// 創建 HTTP server
195-
const { createServer } = await import('http');
196-
this.httpServer = createServer();
208+
const http = require('http');
209+
this.httpServer = http.createServer();
197210

198211
// 創建 WebSocket server
199212
this.wsServer = new WebSocket.Server({
@@ -222,9 +235,9 @@ export class MCPVSCodeServer {
222235
}
223236

224237
private async handleWebSocketConnection(ws: WebSocket.WebSocket): Promise<void> {
225-
// Ensure server is initialized
238+
// Ensure ES modules are loaded
226239
if (!this.initialized) {
227-
this.initializeServer();
240+
await this.loadESModules();
228241
}
229242

230243
// 為每個 WebSocket 連接創建新的 server 實例

src/tools/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
* MCP Tools 導出模組
33
*/
44

5-
export { VSCodeCommandsTools } from './vscode-commands.js';
5+
export { VSCodeCommandsTools } from './vscode-commands';

src/tools/vscode-commands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as vscode from 'vscode';
2-
import { CommandExecutionResult, MCPServerConfig } from '../types.js';
2+
import { CommandExecutionResult, MCPServerConfig } from '../types';
33

44
export class VSCodeCommandsTools {
55
private config: MCPServerConfig;

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"module": "ES2022",
3+
"module": "commonjs",
44
"target": "ES2022",
55
"outDir": "out",
66
"lib": [

0 commit comments

Comments
 (0)