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.
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo issues