cidrblock/vscode-mcp-extension-demo
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.
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:
- "Give me the first number"
- "Give me the second number"
- "Give me the third number"
- 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
- Open this project folder in VS Code
- Press
F5or go toRun > Start Debugging - 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:
-
Enable Agent Mode: Open VS Code Command Palette (
Ctrl+Shift+P/Cmd+Shift+P) and run:Chat: Enable Agent Mode -
Use the MCP Tool: In VS Code Chat, you can now use the
calculate_sumtool 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 TypeScriptnpm run watch- Watch for changes and recompilenpm run lint- Run ESLintnpm 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_sumtool - 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_numberis missing: Returns "Give me the first number" - If
second_numberis missing: Returns "Give me the second number" - If
third_numberis 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.mjsfile 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.