@leashmarket/mcp-core is the shared kernel that all Leash MCP adapters build on. It defines the LeashHost runtime contract, the LeashTool primitive, and the canonical LEASH_TOOLS list — keeping each adapter thin and free of duplicated logic.

Install

npm install @leashmarket/mcp-core
# or
pnpm add @leashmarket/mcp-core

Concepts

LeashHost

The LeashHost interface is the only contract an adapter must satisfy. It carries everything the tools need at runtime: credentials, network, signer, and API base URL.
import type { LeashHost } from '@leashmarket/mcp-core';

const host: LeashHost = {
  apiKey: process.env.LEASH_API_KEY!,
  apiUrl: 'https://api.leash.market',
  network: 'solana-mainnet',
  rpcUrl: 'https://api.mainnet-beta.solana.com',
  signer: mySolanaKitSigner,
};

LeashTool / defineTool

Each tool is a typed triple: a name, a Zod input schema, and a handler that receives (host, args) and returns a LeashToolResult.
import { defineTool, jsonResult } from '@leashmarket/mcp-core';
import { z } from 'zod';

const myTool = defineTool({
  name: 'my_tool',
  description: 'Does something useful.',
  schema: z.object({ query: z.string() }),
  handler: async (host, { query }) => {
    const data = await fetch(`${host.apiUrl}/v1/search?q=${query}`);
    return jsonResult(await data.json());
  },
});

LEASH_TOOLS

The full set of built-in tools exported as an array. Adapters iterate this list to register every capability without importing each tool individually.
import { LEASH_TOOLS } from '@leashmarket/mcp-core';

for (const tool of LEASH_TOOLS) {
  // wire into your adapter (MCP server, Claude Agent SDK, etc.)
  adapter.register(tool.name, tool.schema, (args) => tool.handler(host, args));
}
Payment tools: leash_create_payment_link accepts optional protocol (x402 | mpp, default x402), method (GET | POST), and upstream_url. When upstream_url is set, the hosted payment link monetizes that existing endpoint and forwards paid calls there after settlement. For POST endpoints, pass expected_request_body as any JSON object to describe what buyers should send to the hosted paywall URL. leash_pay_payment_link accepts optional method (GET | POST) and body (string, e.g. JSON) for POST paywalls — same dual-protocol behaviour as the CLI leash pay command. Agent API-key tools: leash_create_agent_api_key, leash_list_agent_api_keys, and leash_revoke_agent_api_key let a configured agent bootstrap its own agent scoped API key by signing with the local executive keypair. The created key is bound to the active agent mint, owned by the executive public key, and returns plaintext only once.

Built-in tools

Tool nameDescription
leash_discoverBrowse the Leash + pay-skills provider catalog
leash_create_agent_api_keyCreate an agent-scoped API key with X-Leash-Sig
leash_list_agent_api_keysList this agent’s API keys (no plaintext)
leash_revoke_agent_api_keyDisable an agent-owned API key
leash_pay_payment_linkPay an x402 or MPP payment link with the agent’s treasury
leash_pay_skills_endpointsFetch endpoint list for a pay-skills provider
leash_create_payment_linkCreate a new payable link for your own endpoints
leash_receiptsList receipts for the agent
leash_get_receiptLook up a single receipt by ID
leash_check_balancesCheck treasury USDC / token balances
leash_withdraw_treasuryWithdraw funds from the treasury
leash_get_identityResolve the on-chain identity for an agent
leash_resolve_identityResolve a public identity by mint, handle, or domain
leash_verify_identityVerify an identity selector, or request an allow/warn/deny decision
leash_register_agentRegister a new agent on-chain
leash_set_spend_limitUpdate the agent’s spend delegation limit
leash_get_spend_limitRead the current spend limit
leash_reputationFetch reputation scores for a provider
leash_transaction_historyPaginated on-chain transaction history
leash_daily_transactionsDaily aggregated transaction stats

Helpers

The @leashmarket/mcp-core/helpers sub-export provides pure utilities with no runtime dependencies on MCP or Claude.
import {
  probePaymentLink,
  fetchDiscover,
  fetchIdentityProfile,
  fetchIdentityVerify,
  fetchReputation,
  fetchPaySkillsProvider,
  isLikelyBase58Address,
  lookupTokenBySymbolSafe,
} from '@leashmarket/mcp-core/helpers';
Sends a probe GET and classifies a 402 response as x402 (payment-required header) or MPP (problem+json with challengeId). Returns a normalised preview:
  • protocol: 'x402' | 'mpp'
  • network, pay_to, asset, amount_atomic, currency
  • optional description; for MPP, challenge_id
Throws if the response is not a paywall 402 or the body cannot be parsed as either protocol.
const preview = await probePaymentLink('https://api.example.com/premium?network=solana-devnet');
console.log(preview.protocol, preview.amount_atomic, preview.currency);

fetchDiscover(apiUrl, opts)

Queries the Leash discover endpoint and returns a list of DiscoverItem results.
const { items } = await fetchDiscover('https://api.leash.market', {
  capability: 'translate text',
  source: 'all', // 'leash' | 'pay-skills' | 'all'
  limit: 20,
});

fetchIdentityProfile(apiUrl, opts) / fetchIdentityVerify(apiUrl, opts)

Resolve or verify a public agent identity by mint, handle, or verified domain. When you include intent, capability, or thresholds, fetchIdentityVerify uses POST /v1/identity/verify and returns the same allow/warn/deny decision shape as the public API.
const profile = await fetchIdentityProfile({
  apiBaseUrl: 'https://api.leash.market',
  query: { handle: 'payce-demo' },
});

const verdict = await fetchIdentityVerify({
  apiBaseUrl: 'https://api.leash.market',
  query: {
    domain: 'agent.example',
    intent: 'pay',
    capability: { slug: 'seller/quote-api', protocol: 'x402' },
    thresholds: { min_rating: 0.7 },
  },
});

Adapters built on this package

PackageRuntime
@leashmarket/mcpMCP stdio / SSE server (Claude Desktop, Cursor, …)
@leashmarket/clileash CLI — uses MCP tools directly in your terminal

Develop

pnpm --filter @leashmarket/mcp-core build
pnpm --filter @leashmarket/mcp-core test