Skip to main content
Glama
IrMaho

Antigravity Base MCP Server

by IrMaho
README.md
# ๐Ÿš€ Antigravity Base MCP Server Template (Model Context Protocol Starter Kit)

An enterprise-grade, clean, and extensible **Base MCP (Model Context Protocol) Server Template** built with **TypeScript**, **Zod**, **Vite**, and **Vitest**.

Designed to be your foundational starter kit: whenever you need a new MCP server with custom tools for a new project, simply **copy this directory**, define your tools in `src/tools/`, and use it instantly across **Claude Desktop**, **Google Antigravity**, **Cursor**, and **VS Code**.

---

## โšก Autonomous On-Demand Auto-Start (Zero Manual Startup)

> [!TIP]
> **No Manual Startup Required!** 
> You do **NOT** need to manually launch, keep terminal windows open, or run background daemons for this MCP server.
> - When an AI Agent (Claude, Antigravity, Cursor) sends its first request, the client automatically spawns `bin/mcp-server.js` on-demand over Stdio.
> - **Self-Healing Bootstrap**: If `node_modules/` or `dist/` is missing, the launcher automatically runs `npm install` and compiles the project on the fly in milliseconds before handling the request!

---

## ๐ŸŒŸ Key Features & Capabilities

- โšก **Strict Protocol Compliance**: Implements MCP Specification 2024-11-05 and JSON-RPC 2.0 (`initialize`, `ping`, `tools/list`, `tools/call`, `resources/list`, `resources/read`, `prompts/list`, `prompts/get`, `completion/complete`).
- ๐Ÿ›ก๏ธ **Zero Stdout Pollution**: Clean Stdio transport with all logger output strictly routed to stderr and optional file logging.
- ๐Ÿงฉ **Modular Tool Architecture**: Abstract `BaseTool` class with automatic **Zod** schema-to-JSON-Schema conversion and safe runtime validation.
- ๐Ÿ› ๏ธ **Instant Tool Generator**: Run `npm run new-tool <tool_name>` to scaffold a new tool with types and schema in seconds.
- ๐Ÿงช **Complete Test Suite**: Integrated **Vitest** unit tests and real-stdio end-to-end integration tests (`npm run test:all`).
- ๐Ÿ–ฅ๏ธ **Windows 1-Click Automation**: `.bat` files for installation, building, testing, and running.
- ๐Ÿ“– **Bilingual Guides**: Includes English and comprehensive Persian documentation ([GUIDE_FA.md](file:///c:/Users/ASUS/Desktop/flutter_project/base_mcp/GUIDE_FA.md)).

---

## ๐Ÿ“Š Why Use This Base MCP Instead of Building from Scratch?

| Comparison Criteria | Building from Scratch (From 0) | Using Antigravity Base MCP |
| :--- | :--- | :--- |
| **Setup Time** | 2 to 4 hours of tedious boilerplate | **Under 1 minute** (copy folder & rename) |
| **Stdio Stream Corruption** | High risk (`console.log` breaks JSON-RPC) | **100% Protected** with stderr-isolated Logger |
| **Parameter Validation** | Manual, error-prone JSON Schema definitions | **Type-safe Zod Schemas** with auto JSON Schema conversion |
| **Server Lifecycle** | Manual script startup and background management | **Autonomous on-demand wake-up** and auto-build |
| **Error Handling** | Repetitive try/catch boilerplate per tool | **Standardized error wrappers** with detailed diagnostics |
| **Testability** | Hard to test without full LLM client | **Built-in CLI & Vitest** for immediate isolated testing |
| **Multi-Client Support** | Unpredictable protocol quirks | **Battle-tested across Claude, Antigravity, Cursor** |

---

## ๐Ÿ—๏ธ Foundational Capabilities for Future Expansion

This template gives you the complete architecture to build:
1. ๐Ÿ—„๏ธ **Database MCPs**: Connect to SQLite, PostgreSQL, MongoDB, or Redis and expose query tools to AI agents.
2. ๐Ÿ“ฑ **Flutter / Dart MCPs**: Expose AST analyzers, automated widget generators, and emulator controllers.
3. ๐Ÿ’ป **OS & File Automation MCPs**: Create secure file management, process execution, and system diagnostics tools.
4. ๐ŸŒ **API Gateway & Webhook MCPs**: Integrate third-party APIs, payments, messaging bots, and internal microservices.
5. ๐Ÿ“„ **Dynamic Resources**: Expose live project state, documentation, and database schemas directly to agents.
6. ๐Ÿ’ก **Prompt Engineering Templates**: Provide structured multi-step reasoning prompts for refactoring and security reviews.

---

## ๐Ÿ“ Directory Structure

```text
base_mcp/
โ”œโ”€โ”€ .agents/
โ”‚   โ””โ”€โ”€ skills/
โ”‚       โ””โ”€โ”€ base-mcp-starter/
โ”‚           โ””โ”€โ”€ SKILL.md            # AI Agent skill documentation
โ”œโ”€โ”€ bin/
โ”‚   โ”œโ”€โ”€ cli.ts                      # Interactive Developer CLI
โ”‚   โ”œโ”€โ”€ mcp-server.ts               # Direct TS runner
โ”‚   โ””โ”€โ”€ mcp-server.js               # Autonomous zero-config Node runner
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ index.ts                    # Main library exports
โ”‚   โ”œโ”€โ”€ server.ts                   # Core BaseMCPServer JSON-RPC router
โ”‚   โ”œโ”€โ”€ config/
โ”‚   โ”‚   โ””โ”€โ”€ index.ts                # Server configuration & environment
โ”‚   โ”œโ”€โ”€ core/
โ”‚   โ”‚   โ”œโ”€โ”€ types.ts                # Protocol types
โ”‚   โ”‚   โ”œโ”€โ”€ logger.ts               # Stderr / file logger
โ”‚   โ”‚   โ”œโ”€โ”€ errors.ts               # JSON-RPC error codes & classes
โ”‚   โ”‚   โ””โ”€โ”€ transport.ts            # Stdio transport engine
โ”‚   โ”œโ”€โ”€ tools/
โ”‚   โ”‚   โ”œโ”€โ”€ base-tool.ts            # Abstract base tool with Zod parsing
โ”‚   โ”‚   โ”œโ”€โ”€ registry.ts             # Central tool registry
โ”‚   โ”‚   โ”œโ”€โ”€ index.ts                # Tool registry loader & registrations
โ”‚   โ”‚   โ””โ”€โ”€ examples/
โ”‚   โ”‚       โ”œโ”€โ”€ echo.tool.ts        # Echo sample tool
โ”‚   โ”‚       โ”œโ”€โ”€ system-info.tool.ts # System diagnostics sample tool
โ”‚   โ”‚       โ””โ”€โ”€ custom-template.tool.ts # Copy-paste blueprint
โ”‚   โ”œโ”€โ”€ resources/
โ”‚   โ”‚   โ”œโ”€โ”€ index.ts                # Resource manager
โ”‚   โ”‚   โ””โ”€โ”€ examples/
โ”‚   โ”‚       โ””โ”€โ”€ sample-resource.ts  # Sample dynamic resource
โ”‚   โ””โ”€โ”€ prompts/
โ”‚       โ”œโ”€โ”€ index.ts                # Prompt manager
โ”‚       โ””โ”€โ”€ examples/
โ”‚           โ””โ”€โ”€ sample-prompt.ts    # Sample prompt template
โ”œโ”€โ”€ scripts/
โ”‚   โ”œโ”€โ”€ create-tool.ts              # Tool scaffolding generator
โ”‚   โ”œโ”€โ”€ test-stdio.ts               # End-to-end stdio protocol tester
โ”‚   โ””โ”€โ”€ export-schemas.ts           # Schema exporter to JSON files
โ”œโ”€โ”€ templates/
โ”‚   โ””โ”€โ”€ mcp_config.example.json     # Client configuration snippets
โ”œโ”€โ”€ tests/
โ”‚   โ”œโ”€โ”€ server.test.ts              # Server protocol tests
โ”‚   โ””โ”€โ”€ tools.test.ts               # Tool execution tests
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ tsconfig.json
โ”œโ”€โ”€ vite.config.ts
โ”œโ”€โ”€ vitest.config.ts
โ”œโ”€โ”€ Build.bat
โ”œโ”€โ”€ Run-Tests.bat
โ”œโ”€โ”€ Start-Server.bat
โ””โ”€โ”€ Install-Dependencies.bat
```

---

## โšก Quick Start

### 1. Install Dependencies
```bash
npm install
# or double click Install-Dependencies.bat
```

### 2. Build the Server
```bash
npm run build
# or double click Build.bat
```

### 3. Run Automated Tests
```bash
npm run test:all
# or double click Run-Tests.bat
```

### 4. Test Interactive CLI
```bash
# List all registered tools:
npm run cli list

# Call a tool directly:
npm run cli call echo '{"message": "Hello World!", "repeat": 2}'
```

---

## ๐Ÿ› ๏ธ How to Create a New Tool in 3 Steps

### Step 1: Generate Scaffolding
```bash
npm run new-tool calculate_tax
```
This generates `src/tools/calculate-tax.tool.ts`.

### Step 2: Define Schema & Implement Logic
Open `src/tools/calculate-tax.tool.ts`:
```typescript
import { z } from 'zod';
import { BaseTool } from './base-tool';
import { MCPToolCallResult } from '../core/types';

export const CalculateTaxSchema = z.object({
  amount: z.number().positive().describe('Total amount in USD'),
  taxRate: z.number().min(0).max(1).default(0.09).describe('Tax rate decimal (e.g. 0.09 for 9%)'),
});

export type CalculateTaxInput = z.infer<typeof CalculateTaxSchema>;

export class CalculateTaxTool extends BaseTool<typeof CalculateTaxSchema> {
  public readonly name = 'calculate_tax';
  public readonly description = 'Calculates total tax and grand total for a given amount.';
  public readonly schema = CalculateTaxSchema;

  public async execute(args: CalculateTaxInput): Promise<MCPToolCallResult> {
    const tax = args.amount * args.taxRate;
    const total = args.amount + tax;

    return this.jsonResult({
      originalAmount: args.amount,
      taxRate: args.taxRate,
      taxAmount: Math.round(tax * 100) / 100,
      grandTotal: Math.round(total * 100) / 100,
    });
  }
}
```

### Step 3: Register in src/tools/index.ts
```typescript
import { CalculateTaxTool } from './calculate-tax.tool';

export function createDefaultToolRegistry(): ToolRegistry {
  const registry = new ToolRegistry();
  
  // Register your new tool:
  registry.register(new CalculateTaxTool());

  return registry;
}
```

Rebuild (`npm run build`) and test:
```bash
npm run cli call calculate_tax '{"amount": 100, "taxRate": 0.15}'
```

---

## ๐Ÿ”Œ Connecting to AI Clients

### Claude Desktop (`claude_desktop_config.json`)
```json
{
  "mcpServers": {
    "my-mcp": {
      "command": "node",
      "args": ["C:/Users/ASUS/Desktop/flutter_project/base_mcp/bin/mcp-server.js"]
    }
  }
}
```

### Google Antigravity / Gemini CLI (`mcp_config.json`)
```json
{
  "mcpServers": {
    "my-mcp": {
      "command": "node",
      "args": ["C:/Users/ASUS/Desktop/flutter_project/base_mcp/bin/mcp-server.js"],
      "env": {
        "MCP_LOG_LEVEL": "info"
      }
    }
  }
}
```

### Cursor IDE (`.cursor/mcp.json`)
```json
{
  "mcpServers": {
    "my-mcp": {
      "command": "node",
      "args": ["C:/Users/ASUS/Desktop/flutter_project/base_mcp/bin/mcp-server.js"]
    }
  }
}
```

---

## ๐Ÿ“œ License
MIT License. Created by Antigravity Engineering.

Maintenance

ActivityMaintained
ResponsivenessNo issues