Skip to content

[KLC-2170/KLC-2171] Add on-chain tools for Klever blockchain interaction#28

Merged
nickgs1337 merged 7 commits intodevelopfrom
feature/KLC-2170-2171-on-chain-tools
Feb 19, 2026
Merged

[KLC-2170/KLC-2171] Add on-chain tools for Klever blockchain interaction#28
nickgs1337 merged 7 commits intodevelopfrom
feature/KLC-2170-2171-on-chain-tools

Conversation

@fbsobreira
Copy link
Copy Markdown
Member

@fbsobreira fbsobreira commented Feb 15, 2026

Summary

  • 7 read-only tools: get_balance, get_account, get_asset_info, query_sc, get_transaction, get_block, list_validators — available in all profiles (including public MCP)
  • 4 write tools: send_transfer, deploy_sc, invoke_sc, freeze_klv — local profile only, builds unsigned transactions for external signing
  • Chain client (src/chain/): zero-dependency HTTP client using native fetch(), supports mainnet/testnet/devnet/local with per-call network override
  • Knowledge base: updated klever-sc crate version from 0.44.0 to 0.45.0 across all references

Details

Chain Client Architecture

  • KleverChainClient with 11 methods wrapping Klever Node and Indexer REST APIs
  • Configurable via env vars (KLEVER_NETWORK, KLEVER_NODE_URL, KLEVER_API_URL, KLEVER_TIMEOUT)
  • Defaults to mainnet with hardcoded URLs — no configuration needed for public MCP
  • AbortController-based timeout handling

MCP Tool Security

  • Read tools use MCP annotations (readOnlyHint, idempotentHint) for safe auto-approval
  • Write tools gated by profile check (this.profile !== 'public')
  • Write tools build unsigned transactions via Node API — server never handles private keys
  • AI agents can override network per-call via optional network parameter (validated against enum)

Tests

  • 26 unit tests for chain client (global fetch mocking)
  • 14 integration tests for MCP tool handlers

Test plan

  • pnpm test passes all existing + new tests
  • pnpm run lint clean
  • pnpm run build succeeds
  • Start MCP server locally and verify read tools work against mainnet
  • Verify write tools are NOT exposed when MODE=mcp (public profile)
  • Verify write tools ARE exposed in local/default profile

Add KleverChainClient (zero-dependency, native fetch) with 11 methods
for querying the Klever blockchain. Expose 7 read-only MCP tools
(get_balance, get_account, get_asset_info, query_sc, get_transaction,
get_block, list_validators) available in all profiles, plus 4 write
tools (send_transfer, deploy_sc, invoke_sc, freeze_klv) gated to
local profile only. Includes 26 unit tests for the chain client and
14 integration tests for MCP tool handlers.
Copilot AI review requested due to automatic review settings February 15, 2026 15:12
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a Klever on-chain HTTP client and exposes new MCP tools for querying chain state in all profiles, plus local-only tools that build unsigned transactions for external signing. It also updates knowledge-base references to the newer klever-sc crate version and documents the new chain client/env vars.

Changes:

  • Introduces src/chain/ (KleverChainClient) with typed helpers for node + API proxy endpoints, plus unit tests.
  • Extends MCP server tool definitions/handlers to add 7 read tools (public+local) and 4 write tools (local-only), with integration tests around exposure/blocking.
  • Bumps klever-sc / klever-sc-scenario version references in knowledge content and updates CLAUDE.md docs.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
src/mcp/server.ts Adds chain tool definitions, profile gating, and tool handlers using KleverChainClient.
src/mcp/server.test.ts Adds integration tests for chain tool listing/behavior in public vs local mode.
src/index.ts Wires KleverChainClient into MCP server startup via env vars.
src/chain/client.ts Implements the zero-dependency fetch-based Klever chain client.
src/chain/types.ts Adds typed interfaces for Klever node/API proxy responses and request bodies.
src/chain/index.ts Exposes chain client + types from a single module entrypoint.
src/chain/client.test.ts Adds unit tests for the chain client (fetch mocking).
src/knowledge/tools/ksc.ts Updates embedded Cargo.toml snippet to klever-sc 0.45.0.
src/knowledge/modules/pause.ts Updates klever-sc-modules version references to 0.45.0.
src/knowledge/modules/admin.ts Updates klever-sc-modules version references to 0.45.0.
CLAUDE.md Documents chain client architecture and new env vars/tool availability.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Add enum constraint to all network properties in tool schemas
- Validate KLEVER_NETWORK env var with fallback and warning
- Truncate large string args in debug logging (prevents wasmHex flooding)
- Save/restore global.fetch in test files for proper isolation
- Add deploy_sc and invoke_sc local-mode integration tests
- Add getKDAInfo unit tests (happy path, URL encoding, error)
Copilot AI review requested due to automatic review settings February 15, 2026 15:41
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Set idempotentHint to false on chain write tools (nonce-dependent)
- Fix getKDAInfo test mock to match KDAData interface shape
Copy link
Copy Markdown

@RomuloSiebra RomuloSiebra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current TransactionBuildRequest has a field contracts, and from what I saw, it seems to not match the actual node API body request. With that in mind, I think we will need to review the body requests from src/mcp/server.ts after the changes

- Fix SmartContract type from 9 to 63 (transaction.proto)
- Fix SC sub-types: deploy=scType:1, invoke=scType:0 (were swapped)
- Fix callValue format to map of token ID to amount ({KLV: amount})
- Fix Freeze type from 2 to 4 (FreezeContractType)
- Fix TransactionBuildRequest to use flat contracts array
- Add builder methods to KleverChainClient (buildTransfer, buildDeploy,
  buildInvoke, buildFreeze) to move chain logic out of server.ts
- Extract fetchWithTimeout to reduce duplication in fetchJson/postJson
- Add wasmPath option to deploy_sc (reads file server-side)
- Add caller field to query_sc and VMQueryRequest
- Add log() alias for console.error with comment explaining MCP stderr
Copilot AI review requested due to automatic review settings February 16, 2026 19:06
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Validate .wasm extension and enforce 10 MB max file size for wasmPath
- Fix misleading JSDoc on getTransaction (uses API proxy, not node)
@nickgs1337 nickgs1337 merged commit 4264bf3 into develop Feb 19, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants