@manifest-network/manifest-mcp-core
v0.25.0
Published
Shared library for Cosmos SDK blockchain logic, tool functions, and server utilities (Manifest Network)
Readme
@manifest-network/manifest-mcp-core
Shared library for Manifest MCP servers. Contains Cosmos SDK logic, on-chain tool functions, server utilities, and the LCD/REST adapter. This package is not an MCP server itself -- it provides building blocks that the chain, lease, fred, cosmwasm, and agent packages compose into servers.
Installation
npm install @manifest-network/manifest-mcp-coreWhat's inside
- CosmosClientManager (
client.ts) -- Keyed-instance client lifecycle with rate limiting and lazy init (RPC + LCD) - LCD adapter (
lcd-adapter.ts) -- Converts LCD/REST responses to the RPC query client shape, making the codebase transport-agnostic - Module registry (
modules.ts) -- Static maps of Cosmos SDK modules with metadata and handler functions - Query/transaction routing (
cosmos.ts) -- Routes(module, subcommand, args)to per-module handlers - On-chain tool functions (
tools/) -- e.g.getBalance,fundCredits,setItemCustomDomain,stopApp,executeTx(atomic multi-message tx), plus read helpers such asgetLease/getSKUs(used by lease and fred packages) - Server utilities (
server-utils.ts) --withErrorHandling,jsonResponse,structuredResponse,bigIntReplacer,sanitizeForLogging,sanitizeForModelText - Tool annotation helpers (
tool-metadata.ts) --readOnlyAnnotations,mutatingAnnotations,manifestMeta(versioned_meta.manifestpayload,MANIFEST_TOOL_META_VERSION = 1) - Wallet providers (
wallet/) --MnemonicWalletProvider(BIP-39),signArbitraryWithAmino(ADR-036) - Logger (
logger.ts) -- Leveled logger (stderr output; defaults towarn, configurable vialogger.setLevel(); the node package's bootstrap readsLOG_LEVELand applies it) - Retry (
retry.ts) -- Exponential backoff with transient/permanent error classification. Exceptions encountered while inspecting an error or its standard.causechain stop retries and preserve the original rejection. See the retry contract. - Validation (
validation.ts) -- Input validation helpers (requireString,requireUuid,parseArgs, etc.)
Supported modules
| Module | Query | Transaction | |--------|:-----:|:-----------:| | bank | yes | yes | | staking | yes | yes | | distribution | yes | yes | | gov | yes | yes | | billing | yes | yes | | sku | yes | yes | | group | yes | yes | | wasm | yes | yes | | poa | yes | yes | | tokenfactory | yes | yes | | ibc-transfer | yes | yes | | authz | yes | yes | | feegrant | yes | yes | | auth | yes | -- | | mint | yes | -- | | manifest | -- | yes |
Usage
import {
CosmosClientManager,
cosmosQuery,
cosmosTx,
createValidatedConfig,
} from '@manifest-network/manifest-mcp-core';
const config = createValidatedConfig({
chainId: 'manifest-1',
rpcUrl: 'https://your-rpc-endpoint/',
gasPrice: '0.01umfx',
addressPrefix: 'manifest',
});Broadcast failures after submission
SDK-created signing clients snapshot the signed bytes, compute their SHA-256
transaction hash, and compare the native CheckTx response against it. After
CheckTx succeeds, a returned hash of the wrong length or value fails before any
transaction lookup; diagnostics retain the local hash. If the subsequent inclusion timer or
transaction lookup fails, cosmosTx and executeTx report TX_FAILED with
details.sent: true,
details.transactionHash, operation context and a non-enumerable cause chain to
the original error. A structured cancellation thrown by a custom transaction
lookup retains OPERATION_CANCELLED.
These errors are not automatically retried. Inspect the transaction before
submitting another mutation: acceptance does not establish block inclusion or
execution success, and no confirmation, code or height is inferred.
An arbitrary timeout or claimed txId supplies no submission evidence. Errors
before observed acceptance (including undecodable CheckTx responses) and custom
broadcast methods keep their existing behavior. Caller cancellation remains
prompt, preserves details.reason, and conservatively reports sent: true once
signing/broadcast begins. On the supported native signAndBroadcast/broadcast
path, it also includes the local transactionHash if this operation observed
acceptance before cancellation. It does not wait for acceptance or change the
error when a later observation arrives. Custom signAndBroadcast or broadcast methods,
SYNC-only calls and opaque compatibility callbacks gain no cancellation hash.
A missing hash does not establish that nothing was sent.
With a configured logger, initialization warns if unsupported signing-client
broadcast methods prevent the guard from installing; failures may then lack
submission diagnostics. MCP servers use their leveled stderr logger; SDK consumers
can supply opts.logger. A manager with no configured sink remains silent.
Compatible clients and servers share initialization diagnostics: the last sink
other than noopLogger wins, and disconnecting its holder does not restore the
previous sink. A default SDK logger cannot silence an already configured manager.
Only the exported noopLogger instance is ignored; custom logger objects,
including silent ones, are deliberate sink assignments. If post-connect
initialization fails, including a throwing diagnostic sink, the manager attempts
to disconnect the transport before propagating the failure.
Use distinct wallet-provider adapters when initialization diagnostics need
independent sinks; each SDK client's other logging still uses its own opts.logger.
See the SDK error contract for reconciliation.
SSRF-guarded fetch
Core hosts a shared, SSRF-guarded fetch factory (used by the fred and agent-core packages to route provider / off-chain HTTP). It is Node-only and exposed via the dedicated subpath export @manifest-network/manifest-mcp-core/guarded-fetch -- not the package barrel (index.ts). Keeping it off the barrel keeps the barrel isomorphic: the guard dynamic-imports undici (which transitively pulls in node:async_hooks), so re-exporting it from the root would drag Node-only modules into browser / Deno bundle graphs.
import {
createGuardedFetch,
isBlocked,
} from '@manifest-network/manifest-mcp-core/guarded-fetch';
const guardedFetch = createGuardedFetch();createGuardedFetch()returns atypeof fetchthat DNS-resolves each connection target at connect time and rejects any address whoseipaddr.jsrange is not'unicast'.- Default-deny, allow-only-
'unicast'policy. Loopback, private, link-local (incl. cloud metadata at169.254.169.254), multicast, reserved, carrier-grade-NAT, and every other non-unicastclassification are blocked; unparseable / unresolvable hosts fail closed. isBlocked(ip)exposes the same single-IP verdict for audit / test use -- returns{ range, rfc }when blocked,nullwhen allowed.- Browser / Deno:
createGuardedFetch()throws by construction on non-Node runtimes. Pass your ownopts.fetchto the consuming code path instead.
SSRF-guarded WebSocket transport
Core also hosts the Node WebSocket transport for ctx.events (@beta) -- the live-status seam that waitForLeaseStatus transparently upgrades to. Like the guarded fetch, it is Node-only and exposed via a dedicated subpath, @manifest-network/manifest-mcp-core/events-node -- not the package barrel -- because it dynamic-imports the optional ws dependency; keeping it off the root barrel keeps the barrel isomorphic (a browser injects its own native-WebSocket-backed EventTransport instead).
import { createNodeEventTransport } from '@manifest-network/manifest-mcp-core/events-node';
const events = createNodeEventTransport(); // guarded: true by defaultcreateNodeEventTransport(opts?)returns anEventTransportwhoseopen(url)connects viaws, applying the same connect-time SSRF guard as the fetch path: it DNS-resolves the host (sharedassertUnicastHost), rejects any non-'unicast'address, and pins the connection to the resolved IP while keeping the hostname for theHostheader + TLS SNI (DNS-rebinding-safe).{ guarded: false }opts out for loopback dev / e2e.wsis an exact-pinnedoptionalDependency, dynamic-imported; if it is absent,open()surfaces a clear error (viaonError+ a syntheticonClose).- Browser / Deno:
createNodeEventTransport()throws by construction on non-Node runtimes. Inject your ownEventTransportbacked by the nativeWebSocketinstead (or omitctx.eventsto fall back to polling).
Universal off-barrel subpaths
Three low-level surfaces are browser-safe (no Node builtins) but kept off the package barrel (index.ts) to keep the public surface small — each has its own subpath export:
@manifest-network/manifest-mcp-core/ssrf— the pure IP classifierisBlocked/isIpLiteral/BLOCKED_RANGES_IPV4/BLOCKED_RANGES_IPV6(ipaddr.jsonly, nonode:builtins). This is the browser-safe half of the SSRF guard — what fred's URL-string check (isUrlSsrfSafe/validateProviderUrl) imports. The connect-timecreateGuardedFetch(undici) stays Node-only on/guarded-fetch. (ENG-490)@manifest-network/manifest-mcp-core/faucet— the faucet opsrequestFaucet/requestFaucetCredit/fetchFaucetStatus(+ their types), purefetch+zod. A testnet/operator concern — deliberately off the barrel soexport type *consumers don't inherit the testnet-only surface. (ENG-531)@manifest-network/manifest-mcp-core/gas—buildGasFee+ the gas-default constantsDEFAULT_GAS_MULTIPLIER/DEFAULT_MAX_GAS, so a first-party sibling that broadcasts on its own can enforce theCOSMOS_MAX_GASgas-limit ceiling instead of passing'auto'. (ENG-556)
Build
npm run build # tsdown (platform: neutral)
npm run lint # tsc --noEmit
npm run test # vitestLicense
MIT
Browser support
The root entry point and query/transaction helpers can be bundled for browsers. Inject a browser wallet and fetch transport through the client factory. Node-only /guarded-fetch and /events-node exports require Node; filesystem-backed operations also require Node when invoked. Browser-safe importability does not make every exported operation available in a browser. See the runtime guidance.
