kernl
Core

Toolkits

Tool collections. Standard Toolkit for TypeScript functions, MCPToolkit for MCP server integration.

Reference: Toolkit

A toolkit is a collection of related tools that can be used by an agent. kernl supports two flavors:

FlavorUse case
ToolkitDefine tools as TypeScript functions
MCPToolkitConnect to any MCP server

Looking for pre-built toolkits? Check out the Marketplace.

Toolkit

The standard toolkit. Define tools as TypeScript functions with full type safety.

import { tool, Toolkit } from "kernl";
import { z } from "zod";

const add = tool({
  id: "add",
  description: "Add two numbers",
  parameters: z.object({ a: z.number(), b: z.number() }),
  execute: async (ctx, { a, b }) => a + b,
});

const subtract = tool({
  id: "subtract",
  description: "Subtract two numbers",
  parameters: z.object({ a: z.number(), b: z.number() }),
  execute: async (ctx, { a, b }) => a - b,
});

export const math = new Toolkit({
  id: "math",
  description: "Basic arithmetic operations",
  tools: [add, subtract],
});

Use with an agent:

const agent = new Agent({
  id: "calculator",
  model: anthropic("claude-sonnet-4-5"),
  instructions: "You are a calculator.",
  toolkits: [math],
});

MCPToolkit

Connect to any Model Context Protocol server. Use tools from the ecosystem without writing integration code.

import { MCPToolkit, MCPServerStreamableHttp } from "kernl";

export const github = new MCPToolkit({
  id: "github",
  description: "GitHub connector via GitHub Copilot MCP",
  server: new MCPServerStreamableHttp({
    url: "https://api.githubcopilot.com/mcp/",
    requestInit: {
      headers: {
        Authorization: `Bearer ${process.env.GITHUB_TOKEN}`,
      },
    },
  }),
});

MCPToolkit handles connection lifecycle automatically — connects lazily on first tool request, and cleans up via destroy().

Server types

ServerTransportMCP Protocol
MCPServerStreamableHttpHTTP with streaming2025-03-26 (recommended)
MCPServerSSEServer-Sent Events2024-11-05 (legacy)

Most modern MCP servers support the streamable HTTP protocol. Use MCPServerSSE only for servers that haven't upgraded yet.

Filtering tools

You can filter which tools are exposed based on context:

const github = new MCPToolkit({
  id: "github",
  server: new MCPServerStreamableHttp({ ... }),
  filter: async (ctx, tool) => {
    // Only allow read operations for certain users
    if (ctx.context.role !== "admin") {
      return tool.id.startsWith("get_") || tool.id.startsWith("list_");
    }
    return true;
  },
});

On this page