# MCP Tools Documentation
A VSCode/Cursor extension that provides an integrated MCP server and UI panel for retrieving and displaying command-line tool documentation. The extension automatically detects tools in your workspace and provides their documentation through a WebView panel.
## Core Features
- π **Built-in MCP Server**
- Express + SSE server (ports 54321-54421)
- Secure origin validation
- Automatic port selection
- Connection management and cleanup
- Real-time event streaming
- π **Tool Discovery**
- Package scripts (npm, yarn, pnpm)
- Local binaries (node_modules/.bin)
- Global tools (git, npm, yarn, pnpm)
- Monorepo workspace support
- π **Documentation Retrieval**
- Help command execution (-h, --help)
- Version information fetching
- Secure command validation
- Error handling
- π» **VS Code Integration**
- React-based WebView panel
- Status bar integration
- Command palette support
- Workspace path detection
## Architecture
### 1. VS Code Extension (Backend)
```
Extension Host (src/extension.ts)
βββ Activates when VS Code starts
βββ Creates MCP Server
β βββ Express + SSE Server (54321-54421 port range)
βββ Creates WebView Panel
```
### 2. MCP Server (Middle Layer)
```
MCP Server (src/server/*)
βββ SSE Event Stream
β βββ Real-time tool discovery updates
β βββ Documentation streaming
β βββ Connection state management
β
βββ Tool Discovery System
βββ path-scanner.ts
β βββ Finds tools in workspace (bin/, node_modules/.bin)
βββ package-scanner.ts
βββ Scans package.json for available tools
```
### 3. WebView Panel (Frontend)
```
React WebView (src/panel/*)
βββ UI Components
β βββ Shows available tools and their docs
β
βββ SSE Client
βββ Requests available tools
βββ Streams tool documentation
```
## Project Structure
```
my-tools-mcp/
βββ src/ # Source code
β βββ extension.ts # Extension entry point
β βββ env.ts # Environment configuration
β βββ server/ # Built-in MCP server
β β βββ index.ts # Server setup and SSE handling
β β βββ controllers/ # Tool discovery and execution
β β βββ docs/ # Documentation controllers
β β βββ path-scanner.ts # Tool discovery
β β βββ package-scanner.ts # Package.json scanning
β βββ panel/ # WebView UI (React)
β β βββ index.tsx # WebView entry point
β β βββ App.tsx # Main React component
β β βββ components/ # UI components
β βββ types/ # Shared TypeScript types
β βββ lib/ # Shared utilities
βββ dist/ # Compiled output
βββ src/__tests__/ # Test files
```
## Development Setup
1. Install dependencies:
```bash
pnpm install
```
2. Start development:
```bash
# Start webpack in watch mode
pnpm run dev
# Or build for production
pnpm run build
```
3. Launch the extension:
- Press F5 in VSCode to start debugging
- The extension will start both the MCP server and WebView panel
## Usage
1. Open the command palette (Cmd/Ctrl + Shift + P)
2. Type "MCP Tools" and select the command
3. The WebView panel will open and display available tools
4. Select a tool to view its documentation
## Technical Details
### Tool Discovery
- **Package Scripts**
- Automatically detects npm/yarn/pnpm scripts
- Shows script source and working directory
- Supports monorepo workspaces
- Validates script existence
- **Binary Tools**
- Finds tools in node_modules/.bin
- Detects global tools (git, npm, yarn, pnpm)
- Validates tool existence and permissions
- Handles path resolution
### Documentation Retrieval
- Executes help commands (-h, --help)
- Fetches version information
- Handles command execution errors
- Validates tool names and arguments
- Implements proper timeouts
### SSE Communication
- Real-time tool discovery updates
- Secure origin validation
- Connection management and cleanup
- Error handling and reporting
- Automatic reconnection support
- Event-based streaming
- Bi-directional message passing
### Security Features
- Tool name validation
- Command injection prevention
- Origin validation for SSE connections
- Proper error handling and reporting
- Resource cleanup
- Connection state management
## Testing
The extension includes comprehensive tests:
- Integration tests for server functionality
- VS Code extension tests
- Tool discovery tests
- Security validation tests
- SSE communication tests
## License
ISC