Skip to main content

Requirements

@modelcontextprotocol/sdk and zod are peer dependencies. Install them in your project if you do not already have them.

Install

bun add @waniwani/sdk
The SDK has zero runtime dependencies and targets a sub-5KB core bundle. It runs in long-lived Node processes, serverless functions, and edge runtimes.

Create a client

import { waniwani } from "@waniwani/sdk";

const wani = waniwani();
With no arguments, the client reads WANIWANI_API_KEY from the environment and uses https://app.waniwani.ai as the base URL. This is the recommended setup. See API keys for how to obtain and configure the key.

Configuration reference

All fields are optional.
apiKey
string
Your MCP environment API key. Defaults to process.env.WANIWANI_API_KEY. If both are missing, track() / flush() / shutdown() throw at runtime.
apiUrl
string
default:"https://app.waniwani.ai"
Base URL of the WaniWani API. Override for self-hosted deployments or staging backends.
tracking
object
Fine-tune the event tracking transport.

Fully configured client

import { waniwani } from "@waniwani/sdk";

const wani = waniwani({
  apiKey: process.env.WANIWANI_API_KEY,
  apiUrl: "https://app.waniwani.ai",
  tracking: {
    flushIntervalMs: 500,
    maxBatchSize: 50,
    maxRetries: 5,
    shutdownTimeoutMs: 5000,
  },
});

Graceful shutdown

In Node environments, the SDK attaches handlers for beforeExit, SIGINT, and SIGTERM that flush buffered events automatically. For serverless, edge runtimes, tests, or short-lived scripts, call shutdown() explicitly:
const result = await wani.shutdown({ timeoutMs: 5000 });
// => { timedOut: false, pendingEvents: 0 }

Also supported

  • Project config file. Create a waniwani.config.ts with defineConfig({ ... }) from @waniwani/sdk, then import it once at startup. Subsequent calls to waniwani() pick up the registered config.
  • Framework adapters. Pass the client to toNextJsHandler(wani, { ... }) from @waniwani/sdk/next-js for Next.js route handlers.
Next: get your API key, then wrap your MCP server.