Back to MCP Servers

Klever Vm

Klever blockchain MCP server for smart contract development, on-chain data exploration, account and asset queries, transaction analysis, and contract deployment tooling.

finance-fintechdeploymentai
By klever-io
315Updated 1 month agoTypeScriptMIT

Installation

npx -y mcp-klever-vm

Configuration

{
  "mcpServers": {
    "mcp-klever-vm": {
      "command": "npx",
      "args": ["-y", "mcp-klever-vm"]
    }
  }
}

How to use

  1. Run the installation command above (if needed)
  2. Open your Claude Code settings file (~/.claude/settings.json)
  3. Add the configuration to the mcpServers section
  4. Restart Claude Code to apply changes

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:

npx -y @klever/mcp-server

Or connect to the hosted public server:

claude mcp add -t http klever-vm https://mcp.klever.org/mcp

See 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:
git clone https://github.com/klever-io/mcp-klever-vm.git
cd mcp-klever-vm
  1. Install dependencies:
pnpm install
  1. Copy environment configuration:
cp .env.example .env
  1. Install Klever SDK tools (required for transactions):
chmod +x scripts/install-sdk.sh && ./scripts/install-sdk.sh
  1. Build the project:
pnpm run build

Configuration

Edit .env file to configure the server:

# 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

# 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:

{
  "mcpServers": {
    "klever-vm": {
      "command": "npx",
      "args": ["-y", "@klever/mcp-server"]
    }
  }
}

For detailed setup, see the Claude Desktop Installation Guide.

Cursor

Add to your Cursor MCP settings (.cursor/mcp.json):

{
  "mcpServers": {
    "klever-vm": {
      "command": "npx",
      "args": ["-y", "@klever/mcp-server"]
    }
  }
}

VS Code (GitHub Copilot)

Add to .vscode/mcp.json in your project:

{
  "servers": {
    "klever-vm": {
      "type": "stdio",
      "command": "npx",
      "args": ["-y", "@klever/mcp-server"]
    }
  }
}

For detailed setup, see the VS Code Installation Guide.

Public MCP Server

The Klever MCP Server can be hosted as a public shared service, allowing any developer to connect without running it locally.

Connecting to the Public Server

# Add permanently (user-level)
claude mcp add -t http klever-vm https://mcp.klever.org/mcp

# Add for current project only
claude mcp add -t http -s project klever-vm https://mcp.klever.org/mcp

Available Tools (Public Mode)

The public server exposes a read-only subset of tools for security:

ToolDescription
query_contextSearch the Klever VM knowledge base
get_contextRetrieve a specific context by ID
find_similarFind contexts similar to a given context
get_knowledge_statsGet knowledge base statistics
enhance_with_contextEnhance queries with relevant Klever VM context

Write operations (add_context) and shell-based tools (init_klever_project, add_helper_scripts) are disabled in public mode.

Self-Hosting with Docker

# Build and run
docker build -t mcp-klever-vm .
docker run -p 3000:3000 mcp-klever-vm

# Or using docker compose
docker compose up -d

Then connect:

claude mcp add -t http klever-vm-local http://localhost:3000/mcp

Self-Hosting without Docker

pnpm install
pnpm run build
pnpm run start:public

Environment Variables (Public Mode)

VariableDefaultDescription
MODEhttpSet to public for hosted mode
PORT3000Server port
CORS_ORIGINS(unset)Comma-separated allowed origins. Unset or * allows all origins
RATE_LIMIT_MCP60MCP endpoint requests/min per IP
RATE_LIMIT_API30API endpoint requests/min per IP
BODY_SIZE_LIMIT1mbMax request body size

Deployment Notes

For production at mcp.klever.org:

  • Deploy Docker container behind a reverse proxy (nginx/Caddy/cloud LB) for TLS termination
  • Ensure proxy passes mcp-session-id header and supports SSE (disable response buffering)
  • Single instance is sufficient as the server is read-only with an in-memory knowledge base
  • Consider Cloudflare for DDoS protection (SSE is supported)

Usage

Knowledge Base Loading

The server automatically loads the Klever knowledge base based on your storage type:

Memory Storage (Default)

  • Knowledge is automatically loaded when the server starts
  • No need to run pnpm run ingest separately
  • Data exists only while server is running
  • Best for development and testing

Redis Storage

# First, ingest the knowledge base (one time)
pnpm run ingest

# Then start the server
pnpm run dev
  • Knowledge persists in Redis database
  • Survives server restarts
  • Best for production use

This will load:

  • Smart contract templates and examples
  • Annotation rules and best practices
  • Storage mapper patterns and comparisons
  • Deployment and query scripts
  • Common errors and solutions
  • Testing patterns
  • API reference documentation

Running as HTTP Server

# Development mode
pnpm run dev

# Production mode
pnpm run build && pnpm start

The HTTP API will be available at http://localhost:3000/api

Running as MCP Server

MODE=mcp pnpm start

Use with any MCP-compatible client.

API Endpoints

POST /api/context

Ingest new context into the system.

{
  "type": "code_example",
  "content": "contract code here",
  "metadata": {
    "title": "Token Contract Example",
    "description": "ERC20-like token implementation",
    "tags": ["token", "fungible"],
    "contractType": "token"
  }
}

GET /api/context/:id

Retrieve specific context by ID.

POST /api/context/query

Query contexts with filters.

{
  "query": "transfer",
  "types": ["code_example", "best_practice"],
  "tags": ["token"],
  "contractType": "token",
  "limit": 10,
  "offset": 0
}

PUT /api/context/:id

Update existing context.

DELETE /api/context/:id

Delete context.

GET /api/context/:id/similar

Find similar contexts.

POST /api/context/batch

Batch ingest multiple contexts.

MCP Tools

When running as MCP server, the following tools are available:

  • query_context: Search for relevant Klever development context
  • add_context: Add new context to the knowledge base
  • get_context: Retrieve specific context by ID
  • find_similar: Find contexts similar to a given context
  • get_knowledge_stats: Get statistics about the knowledge base
  • init_klever_project: Initialize a new Klever smart contract project with helper scripts
  • enhance_with_context: Automatically enhance queries with relevant Klever VM context

Context Types

  • code_example: Working code snippets and examples (Rust smart contract code)
  • best_practice: Recommended patterns and practices
  • security_tip: Security considerations and warnings
  • optimization: Performance optimization techniques
  • documentation: General documentation and guides
  • error_pattern: Common errors and solutions
  • deployment_tool: Deployment scripts and utilities (bash scripts, tools)
  • runtime_behavior: Runtime behavior explanations

Pre-loaded Knowledge Base

The MCP server includes a comprehensive knowledge base with 95+ entries organized into 11 categories:

Critical Patterns

  • Payment handling and token operations
  • Decimal conversions and calculations
  • Event emission and parameter rules
  • CLI tool usage and best practices

Contract Patterns & Examples

  • Basic contract structure templates
  • Complete lottery game implementation
  • Staking contract with rewards
  • Cross-contract communication patterns
  • Remote storage access patterns
  • Token mapper helper modules

Development Tools

  • Koperator: Complete CLI reference with argument encoding
  • KSC: Build commands and project setup
  • Deployment, upgrade, and query scripts
  • Interactive contract management tools
  • Common utilities library (bech32, network management)

Storage & Optimization

  • Storage mapper selection guide with performance comparisons
  • Namespace organization patterns
  • View endpoints for efficient queries
  • Gas optimization techniques
  • OptionalValue vs Option patterns

Best Practices & Security

  • Input validation patterns
  • Error handling strategies
  • Admin and pause module usage
  • Access control patterns
  • Common mistakes and solutions

Ingesting Contracts

Use the built-in ingestion utilities to parse and import Klever contracts:

import { StorageFactory } from './storage/index.js';
import { ContextService } from './context/service.js';
import { ContractIngester } from './ut

…
View source on GitHub