io.github.klever-io/mcp-klever-vm
MCP server for Klever blockchain smart contract development.
ā
30MITdevtools
Install
Config snippet generator goes here (5 client tabs)
README
# Klever MCP Server
A Model Context Protocol (MCP) server tailored for Klever blockchain smart contract development. This server maintains and serves contextual knowledge including code patterns, best practices, and runtime behavior for developers working with the Klever VM SDK.
## Features
- š **Triple Mode Operation**: Run as HTTP API server, MCP stdio server, or public hosted MCP server
- š¾ **Flexible Storage**: In-memory or Redis backend support
- š **Smart Context Retrieval**: Query by type, tags, or contract type
- š **Automatic Pattern Extraction**: Parse Klever contracts to extract examples and patterns
- šÆ **Relevance Ranking**: Intelligent scoring and ranking of context
- š **Live Updates**: Add and update context in real-time
- š”ļø **Type Safety**: Full TypeScript with Zod validation
- š **Comprehensive Knowledge Base**: Pre-loaded with Klever VM patterns, best practices, and examples
- š§ **Contract Validation**: Automatic detection of common issues and anti-patterns
- š **Deployment Scripts**: Ready-to-use scripts for contract deployment, upgrade, and querying
## Quick Start
Install and run instantly via npx ā no cloning required:
```bash
npx -y @klever/mcp-server
```
Or connect to the hosted public server:
```bash
claude mcp add -t http klever-vm https://mcp.klever.org/mcp
```
See [MCP Client Integration](#mcp-client-integration) for client-specific configuration.
## Architecture
```
mcp-klever-vm/
āāā src/
ā āāā api/ # HTTP API routes with validation
ā āāā context/ # Context management service layer
ā āāā mcp/ # MCP protocol server implementation
ā āāā parsers/ # Klever contract parser and validator
ā āāā storage/ # Storage backends (memory/Redis)
ā ā āāā memory.ts # In-memory storage with size limits
ā ā āāā redis.ts # Redis storage with optimized queries
ā āāā types/ # TypeScript type definitions
ā āāā utils/ # Utilities and ingestion tools
ā āāā knowledge/ # Modular knowledge base (95+ entries)
ā āāā core/ # Core concepts and imports
ā āāā storage/ # Storage patterns and mappers
ā āāā events/ # Event handling and rules
ā āāā tokens/ # Token operations and decimals
ā āāā modules/ # Built-in modules (admin, pause)
ā āāā tools/ # CLI tools (koperator, ksc)
ā āāā scripts/ # Helper scripts
ā āāā examples/ # Complete contract examples
ā āāā errors/ # Error patterns
ā āāā best-practices/ # Optimization and validation
ā āāā documentation/ # API reference
āāā tests/ # Test files
āāā docs/ # Documentation
```
### Key Improvements Made
1. **Storage Layer**
- Added memory limits to prevent OOM in InMemoryStorage
- Optimized Redis queries to avoid O(N) KEYS command
- Added atomic transactions for Redis operations
- Improved error handling and validation
2. **API Security**
- Added input validation for all endpoints
- Batch operation size limits
- Proper error responses without leaking internals
- Environment-aware error messages
3. **Type Safety**
- Centralized schema validation
- Proper TypeScript interfaces for options
- Runtime validation of stored data
4. **Performance**
- Batch operations using Redis MGET
- Index-based queries instead of full scans
- Optimized count operations
## Installation
1. Clone the repository:
```bash
git clone https://github.com/klever-io/mcp-klever-vm.git
cd mcp-klever-vm
```
2. Install dependencies:
```bash
pnpm install
```
3. Copy environment configuration:
```bash
cp .env.example .env
```
4. Install Klever SDK tools (required for transactions):
```bash
chmod +x scripts/install-sdk.sh && ./scripts/install-sdk.sh
```
5. Build the project:
```bash
pnpm run build
```
## Configuration
Edit `.env` file to configure the server:
```env
# Server Mode (http, mcp, or public)
MODE=http
# HTTP Server Port (only for http mode)
PORT=3000
# Storage Backend (memory or redis)
STORAGE_TYPE=memory
# Maximum contexts for in-memory storage (default: 10000)
MEMORY_MAX_SIZE=10000
# Redis URL (only if STORAGE_TYPE=redis)
REDIS_URL=redis://localhost:6379
# Node environment (development or production)
NODE_ENV=development
```
## MCP Client Integration
### Claude Code
```bash
# Add via npx (recommended)
claude mcp add klever-vm -- npx -y @klever/mcp-server
# Or connect to the public hosted server
claude mcp add -t http klever-vm https://mcp.klever.org/mcp
```
### Claude Desktop
Add to your `claude_desktop_config.json`:
```json
{
"mcpServers": {
"klever-vm": {
"command": "npx",
"args": ["-y", "@klever/mcp-server"]
}
}
}
```
For detailed setup, see the [Claude Desktop Installation Guide](docs/install-claude.md).
### Cursor
Add to your Cursor MCP settings (`.cursor/mcp.json`):
```json
{
"mcpServers": {
"klever-vm": {
"command": "npx",
"args": ["-y", "@klever/mcp-server"]
}
}
}
```
###