Knowledge Base
Overview
The Klever MCP Server includes a curated knowledge base covering all aspects of Klever smart contract development.
Statistics
- Total Contexts: Use
get_knowledge_statstool to see current totals - Coverage: 11 categories across all aspects of Klever development
- Languages: Primarily Rust with bash scripts
- Contract Types: Gaming, DeFi, NFT, Token, Governance
Context Types
The knowledge base uses 7 context types to organize information:
code_example: Complete contract implementations and code snippetsbest_practice: Development guidelines and recommended patternssecurity_tip: Security recommendations and vulnerability preventionoptimization: Performance optimizations and gas efficiencydocumentation: API and framework referenceserror_pattern: Common errors and solutionsdeployment_tool: Deployment and tooling guides
Knowledge Categories
1. Core Concepts (core)
What's included:
- Contract structure templates and patterns
- Required imports and macros
- Module integration (admin, pause, governance)
- Critical differences from other blockchains
Key entries:
- Basic contract structure with
#[klever_sc::contract] - Required imports:
use klever_sc::imports::* - Contract initialization patterns
- Proxy patterns and upgradeability
2. Storage Patterns (storage)
What's included:
- Storage mapper types and usage
- Namespace patterns and data organization
- View functions and read optimization
- State migration strategies
- Performance comparisons
Storage Mapper Types:
- SingleValueMapper: Single value storage
- MapMapper: Key-value mapping
- SetMapper: Unique value sets
- VecMapper: Ordered lists
- OptionMapper: Optional values
Key entries:
- When to use each mapper type
- Namespace best practices
- Performance characteristics
- Migration patterns
3. Event Handling (events)
What's included:
- Event definition and annotation
- Parameter indexing strategies
- Event-driven architecture patterns
- Logging and monitoring
Key rules:
- Maximum 3 indexed parameters per event
- Event emission best practices
- Indexed vs non-indexed parameters
- Event querying patterns
4. Token Operations (tokens)
What's included:
- KLV (native token) handling
- KDA (custom token) operations
- Multi-token payment validation
- Payment splitting and escrow patterns
- Fee calculation and distribution
- Decimal precision conversions
Key entries:
FungibleTokenMapperusage- Token issuance with
issue_and_set_all_roles - Mint, burn, and transfer operations
- KLV vs KDA differences
- Precision handling (6 decimals for KLV/KFI)
Critical notes:
- Use
--valuesNOT--valuefor payments in koperator - KLV has 6 decimal places (1 KLV = 1,000,000 units)
- Always validate payment amounts
5. Built-in Modules (modules)
What's included:
- Admin module integration
- Pause/Pausable module usage
- Access control patterns
- Module configuration
6. Development Tools (tools)
What's included:
- koperator: Complete CLI reference with all commands and argument encoding
- ksc: Smart contract compiler usage and optimization flags
- Network configuration (testnet/mainnet)
- Return data parsing and formatting
- Interactive contract management
Key entries:
- koperator command syntax and examples
- Argument encoding for different types
- Query result parsing
- Network endpoint configurations
7. Helper Scripts (scripts)
What's included:
- Build scripts with proper optimization
- Deployment scripts for testnet/mainnet
- Upgrade scripts preserving contract state
- Query scripts with data decoding
- Interactive contract management tools
Generated by init_klever_project:
build.sh- Compile to WASMdeploy.sh- Deploy with network detectionupgrade.sh- Upgrade existing contractsquery.sh- Query endpointsinteract.sh- Interactive callscommon.sh- Shared utilities
8. Complete Examples (examples)
What's included:
- Complete, working contract implementations
- Lottery game contract
- Staking contract with rewards
- Token mapper usage examples
- Cross-contract communication
- NFT contracts
All examples include:
- Full source code
- Explanation of patterns used
- Testing strategies
- Deployment considerations
9. Error Patterns (errors)
What's included:
- Common compilation errors
- Runtime error patterns
- Deployment failures
- Query encoding mistakes
Most critical errors:
- Missing imports or macros
- Incorrect payment flag (
--valuevs--values) - Payable handlers without
call_value()usage - Storage mapper annotation errors
- Gas limit miscalculations
10. Best Practices (best-practices)
What's included:
- Input validation patterns
- Error handling strategies
- Gas optimization techniques
- Security patterns
- Code organization
Key practices:
- Always validate user inputs
- Use built-in modules (admin, pause)
- Optimize storage access
- Handle errors gracefully
- Write comprehensive tests
- Follow Rust idioms
11. Documentation (documentation)
What's included:
- API reference for Klever SDK
- Framework guides
- Feature documentation
- Network information
- Deployment guides
Next Steps
- View All Functions: Complete MCP tools reference
- Try MCP Prompts: Use guided workflows
- See Workflow Example: Complete development workflow
- Installation Guide: Set up your development environment
Try it online: Explore AI-assisted Klever development at ai.klever.org.