# π€ CHHOTU MCP SERVER - COMPLETE PROJECT EXPLANATION
## 1οΈβ£ WHAT IS MCP (MODEL CONTEXT PROTOCOL)?
MCP is a protocol that lets LLMs (AI assistants) safely interact with your computer by calling specific "tools" you define.
**Example:**
```
You: "Search for all TypeScript files in my project"
β
Gemini: "I'll use the search_files tool"
β
MCP Server: Searches your system locally
β
Result: "Found 15 TypeScript files..."
```
**KEY:** The LLM never directly accesses your files. It only calls your tools, which run on YOUR machine.
---
## 2οΈβ£ PROJECT STRUCTURE - HOW IT'S ORGANIZED
Your project has **4 main layers**:
### LAYER 1: CONFIG (src/config/)
```
Purpose: Secure licensing for Day-1 monetization
Components:
β’ license.ts - HMAC-SHA256 license validation
β’ index.ts - Global configuration & setup
DATA FLOW: Validates ~/.mcp-license file at startup
```
### LAYER 2: CORE (src/core/)
```
Purpose: Actual computer operations
Components:
β’ fileSystem.ts - Read/write/delete files
β’ search.ts - Search files by name or content
β’ commands.ts - Execute allow-listed shell commands
β’ apps.ts - Launch applications (Mac/Win/Linux)
β’ clipboard.ts - Read/write clipboard
β’ kv.ts - Local key-value JSON storage
DATA FLOW: Direct access to OS (with safety checks)
```
### LAYER 3: TOOLS (src/tools/)
```
Purpose: Define tools that LLMs can call
Components:
β’ fileTools.ts - 5 file system tools
β’ searchTools.ts - 2 search tools
β’ commandTools.ts - 2 command tools
β’ systemTools.ts - 3 system tools
β’ automationTools.ts - 3 automation tools
β’ kvTools.ts - 5 key-value tools
β’ index.ts - Registers all 20 tools
DATA FLOW: Takes LLM input β calls core functions β returns responses
```
### LAYER 4: UTILS (src/utils/)
```
Purpose: Shared utilities used by other layers
Components:
β’ platform.ts - Detect OS (macOS/Windows/Linux)
β’ paths.ts - Safe path handling
β’ errors.ts - Consistent error responses
DATA FLOW: Helper functions used everywhere
```
---
## 3οΈβ£ HOW IT WORKS - DATA FLOW EXAMPLE
### SCENARIO: You ask Gemini to "Read my package.json file"
**Step 1:** You ask in Gemini CLI
```
You: "Read my package.json"
```
**Step 2:** Gemini decides to use a tool
```
Gemini: "I'll use read_file tool"
Request: {
tool: "read_file",
arguments: {
path: "/Users/debasishbiswal/Desktop/chhotu_sa_mcp_mvp/package.json"
}
}
```
**Step 3:** MCP Server receives request (running on your machine)
```
server.ts receives the request
β Calls src/tools/index.ts (tool registry)
β Routes to fileTools.readFileTool()
```
**Step 4:** readFileTool processes it
```
β
Validates the path is safe
β
Calls src/core/fileSystem.ts β readFileContents()
β
Reads the actual file content
β
Returns JSON response
```
**Step 5:** Response sent back to Gemini
```
{
success: true,
content: "{ \"name\": \"chhotu-mcp-mvp\", ... }",
size: 1024
}
```
**Step 6:** Gemini shows you the result
```
"Here's your package.json content:
{ \"name\": \"chhotu-mcp-mvp\", ... }"
```
**KEY POINT:** Your file never leaves your machine!
- Gemini only receives the text response
- Your file system stays on your computer
- Gemini cannot access your files directly
---
## 4οΈβ£ THE 20 TOOLS - WHAT EACH DOES
### FILE SYSTEM (5 tools)
**π list_files**
- Input: `path`, `recursive` (optional)
- Output: List of files with metadata (size, type, permissions)
- Example: "Show me all files in my Desktop folder"
**π read_file**
- Input: `path` (file path)
- Output: File contents as text
- Example: "Read my config.json"
**βοΈ write_file**
- Input: `path`, `content`
- Output: Success/failure message
- Example: "Create a new file called hello.txt with 'Hello World'"
**ποΈ delete_file**
- Input: `path`, `recursive` (for folders)
- Output: Success/failure message
- Example: "Delete the temp folder"
**βοΈ move_file**
- Input: `sourcePath`, `destPath`
- Output: Success/failure message
- Example: "Rename index.ts to main.ts"
### SEARCH (2 tools)
**π search_files**
- Input: `baseDir`, `query` (filename pattern), `maxResults`
- Output: List of matching file paths
- Example: "Find all .ts files in src/"
**π search_content**
- Input: `baseDir`, `query` (text to find), `maxResults`
- Output: List of files containing the text
- Example: "Find all files containing 'export function'"
### COMMANDS (2 tools)
**π» run_command**
- Input: `command` (pre-approved only)
- Output: stdout, stderr, exit code
- Allowed commands: ls, find, grep, cat, echo, etc. (18 total)
- Example: "List files with 'ls -la'"
**π list_allowed_commands**
- Input: none
- Output: List of all allowed commands
- Example: "What commands can I run?"
### SYSTEM (3 tools)
**π launch_app**
- Input: `appName`
- Output: Success message
- Platform-aware (macOS: open, Windows: start, Linux: exec)
- Example: "Launch VS Code"
**π get_clipboard**
- Input: none
- Output: Current clipboard content
- Example: "What's in my clipboard?"
**π set_clipboard**
- Input: `content` (text to copy)
- Output: Success message
- Example: "Copy this token to my clipboard: abc123xyz"
### AUTOMATION (3 tools)
**π create_folder_structure**
- Input: `basePath`, `structure` (nested JSON)
- Output: Success message
- Example: "Create a project folder with src/, public/, config/ folders"
**π bulk_rename**
- Input: `directory`, `pattern` (what to rename), `replacement` (new name)
- Output: List of renamed files
- Example: "Rename all .js files to .ts"
**π cleanup_desktop**
- Input: none
- Output: Files organized into Documents/, Images/, Videos/, etc.
- Example: "Clean up my desktop"
### LOCAL STORAGE (5 tools)
**πΎ kv_set**
- Input: `key`, `value`
- Output: Success message
- Stores in `~/.mcp-kv/store.json`
- Example: "Remember this API key: sk_live_abc123"
**π kv_get**
- Input: `key`
- Output: Value if found
- Example: "What was my API key?"
**β kv_delete**
- Input: `key`
- Output: Success message
- Example: "Forget the API key"
**π kv_list**
- Input: none
- Output: All stored keys
- Example: "Show me what you remember"
**π§Ή kv_clear**
- Input: none
- Output: Success message
- Example: "Forget everything you stored"
---
## 5οΈβ£ SECURITY FEATURES - HOW IT PROTECTS YOU
### π LICENSE VALIDATION
- Checks `~/.mcp-license` file on startup
- Uses HMAC-SHA256 tokens (can't be forged)
- Expires after 90 days (demo) or custom period
- Prevents unauthorized use
### β
COMMAND ALLOW-LIST
- Only 18 pre-approved shell commands can run
- Examples: `ls`, `grep`, `cat`, `find`
- Prevents dangerous commands: `rm -rf /`, etc.
- LLM cannot execute arbitrary code
### π‘οΈ PATH SAFETY
- Prevents directory traversal (`../../` escapes)
- Validates all file paths before access
- Checks file permissions
- Prevents reading/writing outside allowed areas
### π ERROR SANITIZATION
- Hides sensitive system details in production
- Shows helpful errors in development
- Never exposes passwords, tokens, or system info
### π₯οΈ PLATFORM-SPECIFIC
- Uses macOS commands on Mac (`pbcopy`/`pbpaste`)
- Uses Windows commands on Windows (PowerShell)
- Uses Linux commands on Linux (`xclip`)
- Prevents OS-specific vulnerabilities
---
## 6οΈβ£ STARTUP FLOW - WHAT HAPPENS WHEN YOU RUN `npm run dev`
```
npm run dev
β
server.ts starts
β Step 1: Initialize Config
β’ Reads ~/.mcp-license
β’ Validates license token (HMAC-SHA256)
β’ Checks expiration date
β
License valid for: mcp-user
β Step 2: Register Tools
β’ Loops through all 20 tools
β’ Registers each with MCP SDK
β’ Validates Zod schemas
β
15 tools registered (or 20 with duplicates)
β Step 3: Start Transports
β’ STDIO transport (for Claude Desktop)
β
STDIO MCP transport ready
β’ HTTP transport (REST API)
β
HTTP MCP available at http://127.0.0.1:3000/mcp
β’ WebSocket transport (real-time)
β
WebSocket MCP running at ws://127.0.0.1:4000
β
Server is now LIVE and waiting for requests!
```
---
## 7οΈβ£ THREE CONNECTION METHODS
Your MCP server can be connected to AI assistants in 3 ways:
### 1οΈβ£ STDIO (Standard Input/Output)
```
Claude Desktop
β pipes input/output
npm run dev (stdin/stdout connection)
```
Used for: Claude Desktop, native MCP clients
### 2οΈβ£ HTTP REST API
```
Gemini CLI (or any HTTP client)
β HTTP POST requests
localhost:3000/mcp (REST endpoint)
```
Used for: Web clients, CLI tools, any HTTP client
### 3οΈβ£ WebSocket
```
Web App / Real-time App
β WebSocket connection
ws://localhost:4000 (Real-time bidirectional)
```
Used for: Web applications, real-time updates
---
## 8οΈβ£ FILE PERSISTENCE - WHERE DATA IS STORED
### License File
```
~/.mcp-license
Format: licensee:timestamp:signature (HMAC-SHA256)
Example: mcp-user:1704067840:a3c5d8f...
```
### KV Store (Local Database)
```
~/.mcp-kv/store.json
Format: JSON key-value pairs
Example: {
"api_key": "sk_live_abc123",
"user_token": "token_xyz",
"settings": "{\"theme\": \"dark\"}"
}
```
### Compiled Code
```
dist/
Format: JavaScript (compiled from TypeScript)
This is what actually runs
```
### Source Code
```
src/
Format: TypeScript (.ts files)
Needs compilation before running
```
---
## 9οΈβ£ KEY DEPENDENCIES
### @modelcontextprotocol/sdk (v1.23.0)
- The MCP protocol implementation
- Handles tool registration and schema validation
- Manages STDIO, HTTP, WebSocket transports
### express (v4.18.2)
- HTTP server for REST endpoint
- Handles `localhost:3000/mcp` requests
### ws (v8.18.3)
- WebSocket server
- Handles real-time connections on `localhost:4000`
### zod (v3.25.76)
- Schema validation for tool inputs
- Type-safe input validation
- Generates TypeScript types
### typescript (v5.9.3)
- Compiles .ts files to .js
- Type checking
- Better IDE support
---
## π COMMON WORKFLOWS
### WORKFLOW 1: Organize Files
```
You: "Organize my Desktop by file type"
β Gemini calls cleanup_desktop()
β Tool moves files to Documents/, Images/, Videos/, etc.
β
Desktop organized
```
### WORKFLOW 2: Search and Read
```
You: "Find all TODO comments in my code"
β Gemini calls search_content(baseDir="/project", query="TODO")
β Returns list of files
β Gemini calls read_file() on each
β Shows you all TODOs
β
All TODOs displayed
```
### WORKFLOW 3: Batch Rename
```
You: "Rename all .jsx files to .tsx in my src folder"
β Gemini calls bulk_rename(directory="/src", pattern=".jsx", replacement=".tsx")
β Tool renames all files
β
All files renamed
```
### WORKFLOW 4: Store Sensitive Info
```
You: "Remember this API key"
β Gemini calls kv_set("api_key", "sk_live_abc123")
β Stored in ~/.mcp-kv/store.json (encrypted by OS)
β Later: kv_get("api_key") retrieves it
β
Safely stored locally
```
---
## 1οΈβ£1οΈβ£ MONETIZATION - DAY 1 READY
Your project is built for selling from Day 1:
### Demo License
- Valid for 90 days
- Created via: `npm run setup-license`
- Stored at: `~/.mcp-license`
- Generated using: `generateLicenseToken("licensee-name")`
### Selling Flow
1. Customer buys license
2. You run: `npm run setup-license`
- Prompts: "Enter licensee name: [customer name]"
3. Gets token: `"customer-name:timestamp:signature"`
4. Customer saves to `~/.mcp-license`
5. Their MCP server validates on startup
6. β
Only they can use it (tied to license)
### In src/config/license.ts
- `SHARED_SECRET` controls token signing
- Customize for your business
- Set `LICENSE_FILE` location per customer
- Add expiration logic in `validateLicenseToken()`
---
## 1οΈβ£2οΈβ£ SUMMARY - WHAT YOU NOW HAVE
β
**20 production-ready tools** that AI assistants can call
β
**4-layer architecture** (Config β Core β Tools β Utils)
β
**Full file system access** with safety checks
β
**Cross-platform support** (Mac/Windows/Linux)
β
**License validation** for monetization
β
**Local data storage** (KV store)
β
**Multiple connection methods** (STDIO/HTTP/WebSocket)
β
**Complete TypeScript codebase**
β
**Ready to deploy and distribute**
β
**No data leaves your machine**
---
## Next Steps
1. **Test the tools** - Use Gemini CLI with the MCP connected
2. **Customize** - Add more tools by following the src/tools/ pattern
3. **Deploy** - Package and distribute to customers with license validation
4. **Monitor** - Check logs and metrics as users interact with tools