The VS Code MCP Server extension enables AI assistants like Claude to interact directly with your VS Code workspace through the Model Context Protocol (MCP). It allows AI models to access your files, make edits, execute commands, and moreāall within your familiar VS Code environment.
You can install the VS Code MCP Server extension in two ways:
git clone https://github.com/juehang/vscode-mcp-server.git
cd vscode-mcp-server
npm install
npm run compile
After installation, you can configure the port number through VS Code settings:
vscode-mcp-server.port
setting in your VS Code preferencesTo configure Claude Desktop to work with this extension:
claude_desktop_config.json
file with the following content:{
"mcpServers": {
"vscode-mcp-server": {
"command": "npx",
"args": ["mcp-remote@next", "http://localhost:3000/mcp"]
}
}
}
For best results when using Claude with this extension, consider using this project prompt:
You are working on an existing codebase, which you can access using your tools. These code tools interact with a VS Code workspace.
Before running code tools that will make any modification to code, always present a comprehensive and detailed plan to the user, including your confidence level (out of 10). When planning, use your tools to explore the codebase so that you understand the context of the project. If you are not confident in your plan because you require more information, use your tools, such as web search, to look for this information or ask the user.
IMPORTANT: Only run code tools that will modify code after presenting such a plan to the user, and receiving explicit approval. Approval must be given each time; prior approval for a change does not imply that subsequent changes are approved.
list_files_code({
path: "/path/to/directory",
recursive: true // optional, default is false
})
read_file_code({
path: "/path/to/file.txt",
encoding: "utf-8", // optional, default is utf-8
maxCharacters: 100000 // optional, default is 100,000
})
create_file_code({
path: "/path/to/new_file.txt",
content: "File content goes here",
overwrite: false, // optional, default is false
ignoreIfExists: false // optional, default is false
})
replace_lines_code({
path: "/path/to/file.txt",
startLine: 5, // 0-based, inclusive
endLine: 10, // 0-based, inclusive
content: "New content to replace lines 5-10",
originalCode: "Original code for validation"
})
get_diagnostics_code({
path: "/path/to/file.txt", // optional, checks entire workspace if omitted
severities: [0, 1], // optional, 0=Error, 1=Warning, 2=Information, 3=Hint
format: "text", // optional, 'text' or 'json'
includeSource: true // optional, whether to include diagnostic source
})
search_symbols_code({
query: "functionName",
maxResults: 10 // optional, default is 10
})
get_symbol_definition_code({
path: "/path/to/file.js",
line: 42, // 0-based line number
symbol: "functionName"
})
execute_shell_command_code({
command: "git status",
cwd: "." // optional, working directory for the command
})
This extension can execute shell commands, which presents potential security risks. Please ensure:
http://localhost:3000/mcp
(or your configured port)There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.