vscode-mcp-extension-demo

cidrblock/vscode-mcp-extension-demo

3.1

If you are the rightful owner of vscode-mcp-extension-demo and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

This document provides a structured summary of a Model Context Protocol (MCP) server implemented as a VS Code extension for calculating the sum of three numbers.

Tools
1
Resources
0
Prompts
0

Number Sum Calculator - VS Code MCP Extension

This VS Code extension implements a Model Context Protocol (MCP) server that provides a single tool for calculating the sum of three numbers with sequential prompting.

Features

  • Single MCP Tool: calculate_sum - A tool that asks for three numbers sequentially and returns their sum
  • Sequential Prompting: The tool follows this exact flow:
    1. "Give me the first number"
    2. "Give me the second number"
    3. "Give me the third number"
    4. Returns the sum of all three numbers
  • Local Extension: Runs entirely locally within VS Code

Project Structure

extension_demo/
├── src/
│   ├── extension.ts          # Main VS Code extension code
│   └── mcp-server.mjs        # MCP server implementation
├── package.json              # Extension configuration
└── README.md                 # This file

Prerequisites

  • Node.js (v18.17.0 or later recommended)
  • VS Code (v1.101.0 or later)
  • npm

Build and Installation Guide

1. Install Dependencies

npm install

2. Compile the Extension

npm run compile

3. Open in VS Code Development Mode

  1. Open this project folder in VS Code
  2. Press F5 or go to Run > Start Debugging
  3. This will open a new VS Code window with the extension loaded

4. Using the Extension

Once the extension is running in the development window:

  1. Enable Agent Mode: Open VS Code Command Palette (Ctrl+Shift+P / Cmd+Shift+P) and run:

    Chat: Enable Agent Mode
    
  2. Use the MCP Tool: In VS Code Chat, you can now use the calculate_sum tool by asking:

    "Calculate the sum of three numbers"
    

    The tool will then prompt you sequentially:

    • "Give me the first number"
    • "Give me the second number"
    • "Give me the third number"

    And finally return the sum.

5. Alternative Testing

You can also test the MCP server directly:

node src/mcp-server.mjs

Development Scripts

  • npm run compile - Compile TypeScript
  • npm run watch - Watch for changes and recompile
  • npm run lint - Run ESLint
  • npm test - Run tests

Architecture

VS Code Extension (src/extension.ts)

  • Registers an MCP Server Definition Provider
  • Manages the MCP server process
  • Integrates with VS Code's language model API

MCP Server (src/mcp-server.mjs)

  • Implements the Model Context Protocol
  • Provides a single calculate_sum tool
  • Handles sequential number prompting logic
  • Returns sum calculations

MCP Tool Specification

Tool Name: calculate_sum

Description: Calculate the sum of three numbers with sequential prompting

Input Schema:

{
  "type": "object",
  "properties": {
    "first_number": { "type": "number" },
    "second_number": { "type": "number" },
    "third_number": { "type": "number" }
  },
  "required": ["first_number", "second_number", "third_number"]
}

Behavior:

  • If first_number is missing: Returns "Give me the first number"
  • If second_number is missing: Returns "Give me the second number"
  • If third_number is missing: Returns "Give me the third number"
  • If all numbers provided: Returns "The sum of X + Y + Z = RESULT"

Troubleshooting

Extension Not Loading

  • Ensure you're running the extension in debug mode (F5)
  • Check the Debug Console for any error messages
  • Verify all dependencies are installed (npm install)

MCP Server Not Responding

  • Check that Node.js is properly installed
  • Verify the mcp-server.mjs file is executable
  • Look for errors in the VS Code Output panel

Tool Not Available in Chat

  • Ensure Agent Mode is enabled in VS Code
  • Check that the MCP server is properly registered
  • Restart the extension development window

License

This project is provided as an example for VS Code MCP extension development.