vscode-mcp-server

repository·master·Indexed 18 days ago

https://github.com/juehang/vscode-mcp-server

A Visual Studio Code extension that acts as an MCP server, exposing the editor's filesystem, editing, symbol navigation, and terminal capabilities to MCP clients like Claude Desktop. It provides tools for file operations (list, read, move, rename, copy), code editing (create, replace lines), diagnostics, symbol searching, and shell command execution within a VS Code workspace.

Tokens
4.6K
Snippets
17
Records
24
Agent score
62%

What's inside vscode-mcp-server

  1. Use Symbol Tools for efficient context management

    master

    When working with large codebases, use symbol tools instead of reading entire files to save context window space. This allows the AI to understand structure and definitions without consuming excessive tokens.

    Recommended Workflow:

    1. Use get_document_symbols_code to get a file outline.
    2. Use search_symbols_code to find specific symbols across the project.
    3. Use get_symbol_definition_code to retrieve type info and documentation.
    4. Only use read_file_code to read the implementation once the specific location is known.
  2. Connect MCP clients to the VS Code MCP Server

    master

    To connect MCP clients (such as Claude Desktop) to this server, configure the client to use the MCP endpoint via HTTP.

    Important: You must manually enable the server first by clicking on the status bar item in VS Code before the endpoint will be active.

    Default endpoint: http://localhost:3000/mcp

    If you have configured a custom host or port in the extension settings, use: http://[your-host]:[your-port]/mcp

    http://localhost:3000/mcp
  3. Use edit tools to modify the workspace

    master

    The VS Code MCP Server provides two primary tools for modifying files in your workspace. Choosing the right tool depends on the size of the change and whether you have the exact current content for validation.

    create_file_code

    When to use:

    • Creating new files.
    • Large modifications (>10 lines).
    • Complete file rewrites.

    Key Options:

    • overwrite: Set to true to replace an existing file.
    • ignoreIfExists: Set to true to skip the operation if the file already exists.

    replace_lines_code

    When to use:

    • Small edits (≤10 lines) where you have the exact original text.
    • Inserting content of any size.

    CRITICAL: The originalCode parameter must match the current file content exactly. If the tool fails due to a mismatch, use read_file_code to retrieve the current content before retrying. This tool uses 1-based line numbers.

    Troubleshooting: If replace_lines_code fails, it is likely because the originalCode provided does not match the file's current state. Always verify line numbers and content with read_file_code first.

    // Example conceptual usage of the tools via MCP
    // 1. Create a new file
    // Tool: create_file_code
    // Args: { "path": "src/newfile.ts", "content": "console.log('hello');" }
    
    // 2. Replace a small block of code
    // Tool: replace_lines_code
    // Args: {
    //   "path": "src/app.ts",
    //   "startLine": 10,
    //   "endLine": 12,
    //   "content": "const x = 5;",
    //   "originalCode": "const old = 0;"
    // }
  4. Configure Claude Desktop to use the VS Code MCP Server

    master

    To connect Claude Desktop to your VS Code workspace, update your claude_desktop_config.json file to include the vscode-mcp-server. The server uses a remote MCP bridge via HTTP.

    Note: This extension uses the streamable HTTP API, not the SSE API.

    {
      "mcpServers": {
        "vscode-mcp-server": {
            "command": "npx",
            "args": ["mcp-remote@next", "http://localhost:3000/mcp"]
        }
      }
    }
  5. Configure vscode-mcp-server extension settings

    master

    You can customize the behavior of the VS Code MCP Server via the following extension settings:

    • vscode-mcp-server.port: The port number for the MCP server (default: 3000).
    • vscode-mcp-server.host: Host address for the MCP server (default: 127.0.0.1).
    • vscode-mcp-server.defaultEnabled: Whether the MCP server should be enabled by default on VS Code startup.
    • vscode-mcp-server.enabledTools: Configure which tool categories are enabled. Supported categories are: file, edit, shell, diagnostics, and symbol.

    Selective Tool Configuration: This is useful for avoiding tool duplication when using coding agents that already have certain capabilities. For example, if using Claude Code, you might disable file and edit tools and only enable symbol tools to provide VS Code-specific symbol searching.

  6. Configure enabled MCP tools

    master

    The ToolConfiguration interface allows you to selectively enable or disable specific tool categories within the MCPServer. This is passed to the MCPServer constructor.

    Available keys:

    • file: Enables file-related tools.
    • edit: Enables code editing tools.
    • shell: Enables shell/terminal tools.
    • diagnostics: Enables diagnostic/error reporting tools.
    • symbol: Enables symbol/navigation tools.
    export interface ToolConfiguration {
        file: boolean;
        edit: boolean;
        shell: boolean;
        diagnostics: boolean;
        symbol: boolean;
    }
  7. Reference: Diagnostics Tools

    master

    Use diagnostics tools to verify code quality and check for errors/warnings.

    • get_diagnostics_code: Checks for warnings and errors.
      • path (string, optional): File path (if omitted, checks entire workspace).
      • severities (array of numbers, optional): 0=Error, 1=Warning, 2=Information, 3=Hint. Default: [0, 1].
      • format (string, optional): 'text' or 'json'. Default: 'text'.
      • includeSource (boolean, optional): Default true.
  8. Reference: File Tools

    master

    The following tools allow for filesystem operations within the VS Code workspace:

    • list_files_code: Lists files and directories.
      • path (string): Path to list.
      • recursive (boolean, optional): Whether to list recursively.
    • read_file_code: Reads file contents.
      • path (string): Path to file.
      • encoding (string, optional): Default utf-8.
      • maxCharacters (number, optional): Default 100,000.
    • move_file_code: Moves files/directories using VS Code's WorkspaceEdit API (supports refactoring imports).
      • sourcePath (string): Current path.
      • targetPath (string): New path.
      • overwrite (boolean, optional): Default false.
    • rename_file_code: Renames files/directories using WorkspaceEdit API.
      • filePath (string): Current path.
      • newName (string): New name.
      • overwrite (boolean, optional): Default false.
    • copy_file_code: Copies files using the file system API.
      • sourcePath (string): Path to copy.
      • targetPath (string): Destination path.
      • overwrite (boolean, optional): Default false.
  9. Reference: Edit Tools

    master

    The following tools allow for modifying code within the workspace:

    • create_file_code: Creates a new file using VS Code's WorkspaceEdit API.
      • path (string): Target path.
      • content (string): File content.
      • overwrite (boolean, optional): Default false.
      • ignoreIfExists (boolean, optional): Default false.
    • replace_lines_code: Replaces specific lines in a file. Requires exact content match for validation.
      • path (string): Target file.
      • startLine (number): 1-based start line.
      • endLine (number): 1-based end line.
      • content (string): New content.
      • originalCode (string): The original code used for validation.
  10. Reference: Symbol Tools

    master

    Tools for navigating and understanding code structure:

    • search_symbols_code: Searches for symbols across the workspace.
      • query (string): Search query.
      • maxResults (number, optional): Default 10.
    • get_symbol_definition_code: Gets definition info (types, docs, range) for a symbol.
      • path (string): File containing the symbol.
      • line (number): Line number.
      • symbol (string): Symbol name.
    • get_document_symbols_code: Gets a hierarchical outline of a file (similar to VS Code Outline view).
      • path (string): Path to file.
      • maxDepth (number, optional): Maximum nesting depth.