> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://docs.navalabs.ai/api/mcp` to find what you need.

# TypeScript API \[Developer Preview]

`@navalabs/sdk` is an ESM package with types. Use it when you want the
verification flow inside your own service rather than through
[the CLI](/sdk/cli) or [the MCP server](/sdk/mcp).

The package is restricted during Developer Preview. Get package access and a
provisioned credential from Nava before installing it.

Suggested prompt for a coding agent:

```text
Integrate Nava Guardian with @navalabs/sdk in this TypeScript project. Inspect the package manager, runtime, secret handling, and existing action flow first, and confirm that I have access to the restricted package. Use NavaClient.requestVerification followed by waitForVerification for each exact proposed action. Treat prompt as audit context only; proposedTx is the structured action Guardian evaluates. Read credentials from the existing secret or environment system and never expose them in source, prompts, logs, errors, analytics, or test output. Continue only when status is APPROVED, canExecute is true, verdict.outcome is approved, and verdict.reasonCode is allowed. Treat any mismatch, rejection, pending, an unknown request hash, a missing or malformed verdict, a transport failure, and NavaTimeoutError as blocked. Request a new verdict after any material action change. Keep signing and venue submission outside Guardian. Add tests for the approved path and every fail-closed path, run the repository checks, and report changed files, checks run, preview access needs, and manual credential steps.
```

```bash
npm install @navalabs/sdk
```

Requires Node.js 22 or newer.

## Record a user prompt

Use `PromptCollectionClient.recordUserPrompt` from your inbound message
handler, before invoking a model. You can also call `recordUserPrompt` on an
existing agent-key `NavaClient`. The agent owner must enable collection first.
The [partner integration example](/sdk/partner-integration#record-incoming-user-messages)
covers credentials, receipts, and how to handle disabled collection or retry
a lost response with the original IDs.

## Verify one proposed action

This example uses an agent API key. Partner backends use the [integration-key flow](#partner-management), whose verification verdict can be approved while lifecycle `status` remains `PENDING`.

```ts
import { NavaClient } from '@navalabs/sdk';

const nava = new NavaClient({
  apiKey: process.env.NAVA_API_KEY!,
  walletAddress: process.env.WALLET_ADDRESS!,
});

const created = await nava.requestVerification({
  prompt: 'Swap WETH for USDC on Uniswap',
  proposedTx: {
    protocol: 'uniswap',
    chainId: 11155111,
    to: '0x...',
    data: '0x...',
    value: '0',
  },
});

if (!created.requestHash) throw new Error('Guardian did not return a request hash');

const status = await nava.waitForVerification(created.requestHash);
const approved =
  status.status === 'APPROVED' &&
  status.canExecute === true &&
  status.verdict?.outcome === 'approved' &&
  status.verdict?.reasonCode === 'allowed';

if (!approved) throw new Error('Guardian did not approve this action');
// Your application now decides whether to sign and submit this exact action.
```

The field is `prompt`, not `userPrompt`, and the transaction is `proposedTx`, not
`tx`. The prompt is audit context for people and records, not policy authority.
Guardian evaluates the exact structured `proposedTx` against the active policy.
Do not put secrets or personal data in either field. `proposedTx.chainId` is
required and must be a chain the registry supports; `requestVerification`
throws at the SDK boundary otherwise, before any request is sent.

`checkVerificationStatus` returns a status envelope. Treat it as approval only
when `status` is `"APPROVED"`, `canExecute` is `true`, `verdict.outcome` is
`"approved"`, and `verdict.reasonCode` is `"allowed"`. Any mismatch blocks
execution. An unknown hash returns `status: "NONE"` with `canExecute: false`.
An `EXECUTED`, `REJECTED`, or `FAILED` envelope remains blocked even if it
retains an earlier approved verdict.

`NavaClient.waitForVerification` polls for you, with the same `2000` ms interval
and `30` attempt defaults the CLI uses: a ceiling of 58 seconds of waiting,
since the loop sleeps only between polls. Exhausting the attempts **throws**
`NavaTimeoutError`; it does not return a `PENDING` status. Catch it and treat it
as neither a rejection nor an approval.

## Read the current agent policy and state

The lower-level `GuardianClient` supports the same two advisory reads exposed
by CLI and MCP:

```ts
import { GuardianClient } from '@navalabs/sdk';

const guardian = new GuardianClient({
  apiKey: process.env.NAVA_API_KEY!,
});

const currentAgent = await guardian.getCurrentAgent();
const policy = await guardian.getAgentPolicy(currentAgent.id);
const state = await guardian.getAgentState(currentAgent.id);
```

These calls require `policies:read:own`, but no wallet. They can read only the
agent represented by the API key; sibling-agent reads are forbidden. The state
is the last-known snapshot and does not trigger a live Alchemy or Hyperliquid
refresh. These reads are advisory: if an agent self-rejects without submitting
the action, Nava records no verdict and no audit trail.

## Manage agents and policies

```ts
import { bootstrapGuardian } from '@navalabs/sdk';

const context = await bootstrapGuardian({
  bearerToken: process.env.NAVA_MANAGEMENT_TOKEN!,
  agentName: 'Treasury Agent',
  walletAddress: process.env.WALLET_ADDRESS!,
  chainId: 11155111,
  policy: { presetId: 'spot-swapper' },
});
```

`bootstrapGuardian` provisions an agent, attaches its verification wallet, and
activates a policy in one call. It needs a **management** credential, which is a
different authority from the agent API key used for submissions; do not reuse
one for the other.

Two clients sit underneath it, both exported from the package root:

* `GuardianClient`: agent, wallet, API-key, policy, and verdict-history
  methods. Agent keys can use own-policy/state reads; management credentials
  are required for writes and cross-agent management.
* `GuardianVerdictClient`: submissions and verdict polling with an agent API
  key. Agent authority.

Related exports on the root: `parsePolicyVerdict`, `isTerminalPolicyVerdict`,
`extractPolicyVerdictFromCreateResponse`, `VERDICT_SCHEMA_VERSION`,
`NavaFetchError`, and `NavaTimeoutError`.

## Partner management

Use these integration-key methods on your backend to create consent contexts and manage a user's agents and wallets. See [Partner integration](/sdk/partner-integration#partner-management-consent) for the complete consent, management and policy flow.

Construct the client on your backend with an explicit API URL:

```ts
import { NavaClient } from '@navalabs/sdk';

const client = new NavaClient({
  integration: {
    appId: process.env.NAVA_APP_ID!,
    apiKey: process.env.NAVA_INTEGRATION_KEY!,
  },
  baseUrl: process.env.NAVA_API_URL!,
});
```

The integration key stays on the server. Derive `partnerUserRef` from your authenticated partner session. All results below are promises; fields with `?` are optional.

| Method | Parameters | Result |
| --- | --- | --- |
| `createLoginContext` | `parentOrigin`, `partnerUserRef`, `requestedScopes` | `PartnerLoginContext` |
| `listAgents` | `partnerUserRef` | `PartnerAgent[]` |
| `createAgent` | `partnerUserRef`, `name`, `metadata?` | `PartnerAgent` |
| `registerWallet` | `partnerUserRef`, `agentId`, `address`, `chainId?`, `label?` | `PartnerAgentWallet` |
| `updateWallet` | `partnerUserRef`, `agentId`, `walletId`, `address` | `PartnerAgentWallet` |
| `removeWallet` | `partnerUserRef`, `agentId`, `walletId` | `void` |

`IntegrationScope` is `'integrator:agents:write' | 'integrator:wallets:write'`. `requestedScopes` must be nonempty and unique. Listing and creating agents need the agents scope; wallet writes need the wallets scope. The integration, key and user's active grant must each allow the operation.

`PartnerAgent` includes nullable partner-defined `metadata` and its `wallets`. `PartnerAgentWallet` includes nullable `chainId`, `label` and `verifiedAt`, plus `verificationStatus`. Registration starts pending; an omitted `chainId` means all chains. `updateWallet` changes only the address and resets verification when the address changes. `PartnerLoginContext` contains a single-use secret `state`: return only `{ id, state }` to the browser's consent callback and keep it out of diagnostics.

The response types and `CreateLoginContextParams`, `ListAgentsParams`, `CreateAgentParams`, `RegisterWalletParams`, `UpdateWalletParams`, `RemoveWalletParams` and `IntegrationScope` are exported from `@navalabs/sdk` and `@navalabs/sdk-core`.

The SDK unwraps HTTP `{ agents: [...] }` into the list and `{ deleted: true }` into `void`. Handle `grant_revoked` by asking for consent again; a missing key scope is a configuration error. Management creation has no idempotency key. See [recovery rules](/sdk/partner-integration#recover-access-and-uncertain-writes) and the [complete SDK management example](https://github.com/navalabs-dev/sdk/blob/ba135ce042b7e137978bc6bd497dcf5038fb9bd1/packages/sdk/examples/partner-management.ts) before retrying uncertain writes.

## Subpath exports

Five import paths, and the two binaries, are the stable public contract. Each
row below was checked against the built module, not only the package manifest.

| Import | Contents |
| --- | --- |
| `@navalabs/sdk` | `NavaClient`, `GuardianClient`, `GuardianVerdictClient`, `bootstrapGuardian`, the verdict helpers. Start here. |
| `@navalabs/sdk/escrow` | Agent-execution bootstrap: `bootstrapAgentExecution`, `createAgentClient`, `signAgentTransaction`, `AgentNavaClient`, the `KeyStore` adapters (`EnvKeyStore`, `FileKeyStore`, `MemoryKeyStore`), and the P-256 helpers. |
| `@navalabs/sdk/mcp` | `startServer`, `createMCPServer`, `KNOWN_PROTOCOLS`, `parseProtocols`, and the registrar plumbing. What `nava-mcp` runs. |
| `@navalabs/sdk/cli` | `runCli`, `runCliEntry`, `parseArgs`, and the argv helpers (`requiredStringArg`, `enumArg`, `intArg`, `requireEnv`, …). What `nava` runs, and what an adapter's CLI module plugs into. |
| `@navalabs/sdk/surface` | The `ProtocolSurface` descriptor framework: `defineProtocolSurface`, `defineOperation`, `createCliModule`, `registerProtocolTools`. |

```ts
import { NavaClient, bootstrapGuardian } from '@navalabs/sdk';
import { bootstrapAgentExecution, FileKeyStore } from '@navalabs/sdk/escrow';
import { startServer, parseProtocols } from '@navalabs/sdk/mcp';
import { runCli, requiredStringArg } from '@navalabs/sdk/cli';
import { defineProtocolSurface, defineOperation } from '@navalabs/sdk/surface';
```

The descriptor helpers on `/surface` are also re-exported from the package root,
so `defineProtocolSurface`, `defineOperation`, `createCliModule`, and
`registerProtocolTools` resolve either way.

Consumers still on `moduleResolution: "node"` reach the subpath types through
`typesVersions` rather than `exports`.

## Adapter subpaths

Adapters are ESM packages too, and each exposes its own operation surface.

```ts
import { createUniswapTools } from '@navalabs/uniswap-adapter';
import { registerUniswapTools } from '@navalabs/uniswap-adapter/mcp';
import { uniswapCliModule } from '@navalabs/uniswap-adapter/cli';
```

| `@navalabs/hyperliquid-adapter` | Exports |
| --- | --- |
| package root | The full surface: clients, tools, error types, the asset resolver. |
| `/adapter` | `createHyperliquidTools`, `createHyperliquidReadTools`, `createHyperliquidWriteTools`, and the verification-mode helpers. |
| `/actions` | Action builders and `hyperliquidActionHash`: build and hash an action without executing it. |
| `/mcp` | `createProtocolRegistrarFactory` and the shared field enums. |
| `/cli` | `hyperliquidCliModule` and the per-command parsers. |

| `@navalabs/uniswap-adapter` | Exports |
| --- | --- |
| package root | The full surface: tool factories, pool and token registries, approval helpers. |
| `/tools` | The six tool factories plus `createUniswapTools`. |
| `/mcp` | `createProtocolRegistrarFactory` and the advertised field schemas. |
| `/cli` | `uniswapCliModule` and the per-command parsers. |
| `/adapter` | **Advertised but empty: exports nothing. Do not import it.** |

Uniswap's `/adapter` resolves and builds, so nothing warns you; it simply has no
members. Its Hyperliquid namesake is a real module, which makes the asymmetry
easy to trip over. Import from the package root or `/tools` instead.

## The `ProtocolSurface` descriptor

Every adapter declares its public surface once, in a `ProtocolSurface`
descriptor. The CLI commands and the MCP tool registrations are both derived
from it, so an operation cannot exist on one transport and not the other by
accident.

`defineProtocolSurface` validates the declarations when the module loads, before
either transport is wired. It throws unless the operation name is kebab-case and
unique, every operation exposes at least one transport, `cli.name` equals the
operation name, `mcp.name` is exactly `<protocol>.<name>`, and every `build`
operation supplies an output schema. A camelCase alias cannot be introduced.

```ts
import { defineOperation, defineProtocolSurface } from '@navalabs/sdk/surface';

export const exampleSurface = defineProtocolSurface({
  protocol: 'example',
  operations: [
    defineOperation({
      name: 'get-price',
      kind: 'read',
      description: 'Fetch a mid price.',
      cli: { name: 'get-price', parse: parseGetPrice },
      mcp: { name: 'example.get-price', inputSchema: getPriceSchema },
      handler: (tools, input) => tools.getPrice(input),
    }),
  ],
  capabilityViews: (tools) => ({
    read: tools,
    build: tools,
    'verified-write': tools,
    operational: tools,
  }),
});
```

`parseGetPrice`, `getPriceSchema`, and the tool factory come from the adapter. `createCliModule(surface, createTools)` produces the CLI module, while `registerProtocolTools(server, surface, tools)` registers the MCP tools. Both derive their operation names from the same surface descriptor.

Four operation kinds exist, and the kind decides how a result is reported:

| Kind | Meaning | `isError` |
| --- | --- | --- |
| `read` | Fetches state. No signing. | Always `false` unless the call threw. |
| `build` | Returns unsigned calldata. No signing, no broadcast. | Always `false` unless the call threw. |
| `verified-write` | Submits the venue-native action for verification, then may sign and send. | Derived from the payload's `success`. |
| `operational` | The six base Guardian operations. | **Set by hand, and it does not always track `success`.** A REJECTED `await-verification` verdict is `isError: false` with `success: false`. |

That `isError` split matters when you call these over MCP; the consequences are
spelled out on [the MCP page](/sdk/mcp#iserror-does-not-mean-rejected).

## Keep verification and execution separate

A terminal approving verdict permits the exact evaluated action under the
returned policy version. It does not execute anything, and it is not evidence
that the action was broadcast, filled, or confirmed. Your application owns
signing and venue submission, and a materially changed action needs its own
verification request.

Never retry a rejected action unchanged, and never split or reshape an action to
get around a policy boundary. Read
[Handle Nava Guardian verdicts](/guardian/developers/handle-verdicts) for the
outcome states and
[Execution safety](/guardian/execution-ownership) for the handoff from verdict to
execution.
