CLI, MCP, and SDK integrations
Karakeep provides authenticated ways for people, scripts, AI agents, and typed applications to work with saved content. The command-line client supports account and administration tasks. The Model Context Protocol (MCP) server exposes bookmark tools to agents. The TypeScript SDK gives programs typed access to the versioned REST contract. The OpenAPI contract keeps these clients aligned with the server.
See Client integrations for the wider integration map, API and tRPC for the application API layer, Browser extension capture for browser capture, and Mobile application for mobile access.
Integration surface
The integration surface adapts Karakeep actions to different callers. The CLI serves people and shell automation. MCP serves agents through named tools. The SDK serves TypeScript programs through typed REST calls. The OpenAPI contract describes the shared HTTP boundary.
| Surface | Primary caller | Main role | Transport or output |
|---|---|---|---|
| CLI | Engineers and shell scripts | Inspect, create, update, search, organize, export, migrate, or remove account data | HTTP requests with human or JSON output |
| MCP server | AI agents through an MCP host | Read and change bookmarks, lists, tags, highlights, and assets | MCP tool calls over standard input and output |
| TypeScript SDK | TypeScript applications and services | Call typed REST operations and use typed response schemas | HTTPS requests under /api/v1 |
| OpenAPI contract | SDK generation and API consumers | Describe paths, inputs, outputs, auth, pagination, and errors | OpenAPI 3 document |
The published CLI is the karakeep command. The published MCP package provides karakeep-mcp. The SDK publishes JavaScript and TypeScript entry points for application consumers. All three clients use a bearer API key for the authenticated user. The server address is separate from the key, so the same tools can target hosted or self-hosted Karakeep.
References: apps/…/package.json• L3-16 apps/…/index.ts• L55-98 apps/…/package.json• L3-15 apps/…/shared.ts• L8-34 packages/…/package.json• L3-18 packages/…/index.ts• L1-12 packages/…/index.ts• L21-117
Command-line client
The CLI is a shell-friendly client named karakeep. It maps account and administrator tasks to commands and can return readable terminal views or JSON for other processes. Most account actions use the tRPC HTTP endpoint. Binary assets and readable bookmark content use versioned REST endpoints.
Authentication and output
The CLI resolves the server address and API key before it runs a command. Users can pass command options, set environment variables, or save the values in the user config file. The auth init command creates or updates that config. The global --json option gives interactive and automated use the same command set.
References: apps/…/index.ts• L17-41 apps/…/index.ts• L55-74 apps/…/config.ts• L6-47 apps/…/auth.ts• L54-144 apps/…/output.ts• L11-31
Account operations
The CLI covers the main bookmark workflow. It can create links, notes, text, and image or PDF assets. It can list, search, read, update, tag, organize, and delete bookmarks. It also supports lists, tags, highlights, asset downloads, and whoami. List and search commands use cursors. The --all option follows those cursors for the caller.
Account-level commands extend this work beyond one bookmark. dump exports selected data and assets. migrate copies selected data between servers while preserving related records. wipe removes selected data after confirmation.
Administrator commands provide visibility and maintenance across users and bookmarks. They can list users with usage data, inspect bookmark processing state, delete users, purge bookmarks over quota, and queue crawl, indexing, tagging, summary, embedding, and asset work. Job commands can limit bulk work by status or by a recent modification window. Cloud deployments also expose a subscription sync command.
References: apps/…/bookmarks.ts• L154-303 apps/…/bookmarks.ts• L432-493 apps/…/bookmarks.ts• L586-772 apps/…/lists.ts• L22-180 apps/…/tags.ts• L17-126 apps/…/highlights.ts• L32-133 apps/…/assets.ts• L38-117 apps/…/dump.ts• L102-377 apps/…/migrate.ts• L65-293 apps/…/wipe.ts• L57-207 apps/…/admin.ts• L61-748
CLI request flow
The CLI turns global connection settings into an authenticated client and sends a command-specific request. Read commands format the response. Write commands report a result or an error. Long operations follow cursors or move binary data between local files and the server.
This diagram shows the normal path from a shell command to a Karakeep result.
flowchart LR
A[Shell command] --> B[Resolve API key and server]
B --> C[Create authenticated client]
C --> D[Call tRPC or REST endpoint]
D --> E{Operation type}
E -->|Read or search| F[Format object or JSON]
E -->|Write| G[Print status or updated object]
E -->|Paged work| H[Follow cursor]
H --> D
References: apps/…/index.ts• L88-107 apps/…/trpc.ts• L8-41 apps/…/http.ts• L1-24 apps/…/output.ts• L11-60 apps/…/admin.ts• L462-721
MCP server
The MCP server is a bridge between an MCP host and Karakeep. Model Context Protocol is a tool interface that lets an agent discover an operation, send structured input, and receive content. The karakeep-mcp process communicates with its host over standard input and output.
The server exposes tools rather than MCP resources. Each tool calls the versioned REST API with the configured bearer key and turns the result into compact text for an agent. The published package exposes karakeep-mcp as its executable entry point.
References: apps/…/package.json• L3-15 apps/…/index.ts• L1-16 apps/…/shared.ts• L22-34 apps/…/README.md• L1-3 apps/…/README.md• L42
MCP tool groups
The tool set follows the main Karakeep objects. Read tools help an agent gather context. Write tools let an agent maintain the account when the host allows those actions.
| Group | Agent capability |
|---|---|
| Bookmarks | Search, read metadata and bounded content, create link or text bookmarks, update fields, inspect list membership, and delete bookmarks |
| Lists | Read, create, update, delete, list contents, and add or remove bookmarks |
| Tags | List and filter tags, inspect use, rename or delete tags, list tagged bookmarks, and attach or detach tags |
| Highlights | List, inspect, create, update, and delete highlights |
| Assets | Request a temporary signed download URL |
Bookmark content is returned as readable text. Link HTML is converted to Markdown. Large content can be read in parts with continuation cursors. Search supports full-text, semantic, and hybrid modes with filters for tags, lists, dates, and bookmark type.
References: apps/…/README.md• L6-42 apps/…/bookmarks.ts• L7-96 apps/…/bookmarks.ts• L169-334 apps/…/lists.ts• L17-68 apps/…/lists.ts• L138-314 apps/…/tags.ts• L12-134 apps/…/tags.ts• L156-307 apps/…/highlights.ts• L9-124 apps/…/highlights.ts• L126-258 apps/…/assets.ts• L7-43
MCP connection and safety model
An MCP host starts the server as a local process. The server reads its API address and API key from environment variables and sends requests to <address>/api/v1. Custom headers support access layers such as a proxy. Hosts can start the published package with npx or run its container.
Tool descriptions identify read-only and data-changing actions. The host controls which tools an agent can use. Destructive actions therefore remain subject to host policy. API errors return as MCP tool errors instead of successful text results.
This diagram shows how an agent reaches a user account through the MCP host.
sequenceDiagram
participant Agent
participant Host as MCP host
participant Server as Karakeep MCP server
participant API as Karakeep REST API
Agent->>Host: Select tool and provide input
Host->>Server: MCP request over stdio
Server->>API: Bearer-authenticated REST request
API-->>Server: Data or API error
Server-->>Host: Tool text or MCP error
Host-->>Agent: Tool result
References: apps/…/shared.ts• L8-29 apps/…/index.ts• L12-16 apps/…/utils.ts• L7-23 apps/…/bookmarks.ts• L161-167 apps/…/highlights.ts• L252-258 apps/…/README.md• L44-86
TypeScript SDK
The TypeScript SDK is the program-facing client for the REST API. createKarakeepClient creates a typed client for a base URL such as <server>/api/v1/, and callers provide the bearer authorization header. The client returns parsed data and typed errors with each response.
The SDK covers REST operations for bookmarks, lists, tags, highlights, users, assets, administration, backups, and feeds. Its package build publishes JavaScript and TypeScript entry points together with the generated declaration entry point, so consumers can use the same REST contract at runtime and during type checking. The package README shows installation with npm install @karakeep/sdk and examples for creating and searching bookmarks. createHoarderClient remains as a deprecated compatibility name. New callers use createKarakeepClient.
References: packages/…/README.md• L1-64 packages/…/index.ts• L1-12 packages/…/package.json• L3-18 packages/…/package.json• L20-45 packages/…/tsconfig.build.json• L1-14 packages/…/vite.config.mts• L7-23 packages/…/karakeep-api.d.ts• L6-118 packages/…/karakeep-api.d.ts• L247-566
SDK compatibility
The SDK follows the minor version of the Karakeep server. A server minor release can add matching SDK features. Older SDK versions should continue to work with newer servers when the REST contract remains backward compatible.
The generated declarations describe the contract. They are not a second API source. The OpenAPI registries define the paths and schemas. The generated declarations give TypeScript callers those types. The current declaration set covers bookmark search and readable content, list and tag management, highlights, assets, user data, administration, backups, and feeds. It also carries typed status values for asynchronous work and typed error responses for common access and input failures.
References: packages/…/README.md• L57-64 packages/…/karakeep-api.d.ts• L1-4 packages/…/karakeep-api.d.ts• L7-246 packages/…/karakeep-api.d.ts• L247-566 packages/…/karakeep-api.d.ts• L826-975 packages/…/karakeep-api.d.ts• L2871-3799 packages/…/index.ts• L120-143
OpenAPI contract
The OpenAPI contract is the shared description of the versioned REST API. It defines server URLs, bearer authentication, resource paths, request and response schemas, cursor pagination, bookmark types, and common errors. The generated JSON supports API documentation and client generation.
The contract groups operations by product area:
- Bookmarks support creation, search, readable content, metadata changes, tags, lists, highlights, assets, and AI summaries.
- Lists support manual membership and query-based smart lists.
- Tags support names, usage counts, filters, and bookmark lookup.
- Highlights use character offsets within bookmark content.
- Assets support upload, binary download, and temporary signed URLs.
- Users expose the current profile and usage data.
- Administration supports user management and queued crawl, index, and AI work.
- Backups and feeds support account safety and RSS import flows.
All endpoints use bearer authentication. List endpoints return an opaque nextCursor. Callers pass it back as cursor until it is null. A bookmark is a link, text note, or image or PDF asset. These shared rules let the CLI, MCP server, and other API clients use the same resource model.
References: packages/…/index.ts• L37-117 packages/…/bookmarks.ts• L45-126 packages/…/lists.ts• L34-309 packages/…/tags.ts• L35-242 packages/…/highlights.ts• L28-207 packages/…/assets.ts• L21-136 packages/…/users.ts• L13-58 packages/…/backups.ts• L23-164 packages/…/feeds.ts• L42-235 packages/…/admin.ts• L33-269
Contract generation
The source contract is assembled from Zod registries and shared Karakeep schemas. The generator writes packages/…/karakeep-openapi-spec.json. A check rebuilds the document in memory and fails when the checked-in JSON is out of date.
The SDK generates path and schema declarations from that contract. Its package build emits JavaScript modules and declaration files, then includes the generated API declaration in the published output. The MCP server consumes the SDK, so a REST contract change can affect both SDK types and agent tool behavior.
This diagram shows the contract path from shared schemas to developer and agent clients.
flowchart TD
A[Shared request and response schemas] --> B[OpenAPI registries]
B --> C[OpenAPI JSON contract]
C --> D[Generated TypeScript declarations]
D --> E[TypeScript SDK]
E --> F[MCP server]
C --> G[Other REST clients and API docs]
References: packages/…/index.ts• L8-35 packages/…/index.ts• L120-143 packages/…/types.ts• L1-61 packages/…/package.json• L20-30 packages/…/tsconfig.build.json• L1-14 packages/…/vite.config.mts• L7-23 packages/…/karakeep-api.d.ts• L1-4 apps/…/package.json• L42-46 apps/…/shared.ts• L4-28
Cross-client behavior
The client surfaces share resource meaning but do not always use the same transport. The CLI uses tRPC for its broad command set because it is part of the application ecosystem. The SDK and MCP server use the versioned REST contract. That REST contract is the stable boundary for external programs and agents.
The most important shared behaviors are:
- API keys identify the current user and must be sent as bearer credentials.
- Cursors are opaque. Callers must not build or edit them.
- Full bookmark content is optional. Metadata reads are lighter, and content reads can be bounded.
- Creating a link bookmark can return an existing bookmark when the URL is already present.
- Deleting a bookmark also removes its highlights and assets. Deleting a tag removes the tag from bookmarks but does not delete bookmarks. Deleting a list does not delete its bookmarks.
- Some actions start background work. A successful request can mean that crawl, indexing, or AI processing was queued rather than completed.
References: apps/…/trpc.ts• L8-23 packages/…/index.ts• L43-57 packages/…/bookmarks.ts• L164-210 packages/…/bookmarks.ts• L247-368 packages/…/lists.ts• L133-159 packages/…/tags.ts• L133-159 packages/…/backups.ts• L47-68 packages/…/feeds.ts• L209-235
Change checklist
When these files or sections are changed, remember to consider these:
- Changes to shared bookmark, list, tag, highlight, asset, feed, or backup schemas can require a new OpenAPI document and new generated SDK declarations.
- Changes to REST paths or response shapes can affect both
@karakeep/sdkcallers and MCP tool handlers. Check tool text and error conversion as well as TypeScript types. - Changes to cursor fields or readable-content rules must stay aligned across REST responses, CLI cursor handling, and MCP pagination inputs.
- Changes to API-key or server-address handling must be checked in CLI flags, environment variables, config files, MCP environment variables, and SDK base URL setup.
- Changes to destructive REST behavior must be reflected in CLI confirmations and MCP tool descriptions.
- Changes to CLI commands that use direct asset or SingleFile endpoints must preserve the REST path and bearer header contract.
- Changes to SDK entry points or build output names must preserve the published JavaScript module and declaration entry points used by consumers.
- Changes to administrator job filters or queue status must keep CLI duration parsing, status values, and queued-work messages aligned with the server behavior.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Missing or invalid bearer key | CLI, SDK, or MCP calls receive an unauthorized response | Supply the key through the client’s supported configuration and use whoami or an equivalent profile call to verify it |
| REST path or schema changes without regenerating the contract | SDK types and MCP requests can drift from the server | Run the OpenAPI generation check and rebuild the SDK |
| SDK build entry points change without matching package export metadata | Consumers can fail to load the published module or its types | Keep build output names aligned with package exports and verify the JavaScript module and declaration entry points |
| Reusing a cursor after bookmark content changes | Readable-content pagination can fail because the cursor no longer matches the content version | Start a new content read when the API reports a cursor conflict |
Treating a non-null nextCursor as the final result | Large lists or searches are silently incomplete | Continue until nextCursor is null, or use the CLI --all option |
| Calling a smart-list membership operation as if the list were manual | The requested membership change does not match a query-derived list | Read the list type and use its saved query for smart-list results |
| Deleting a bookmark or user through CLI or MCP | Related data is permanently removed | Require explicit confirmation for destructive flows and verify the target |
| Assuming a successful crawl, inference, feed fetch, backup, or admin maintenance request is complete | A client can report success before background work finishes | Treat queued responses as pending and check the related status later |
| Supplying an invalid bulk-job duration or status | The CLI rejects the request or queues the wrong work set | Use supported status values and durations that resolve to positive whole seconds |
Key files
| File | Why to read it |
|---|---|
| apps/…/package.json | Defines the published karakeep command and its build entry point. |
| apps/…/index.ts | Shows the CLI entry point, global connection options, command registration, and authentication gate. |
| apps/…/config.ts | Defines CLI config lookup and the default server behavior. |
| apps/…/trpc.ts | Shows how CLI commands create authenticated tRPC clients. |
| apps/…/bookmarks.ts | Illustrates bookmark creation, search, content reads, pagination, and deletion from the shell. |
| apps/…/admin.ts | Shows user administration, bookmark diagnostics, and queued maintenance work from the CLI. |
| apps/…/dump.ts | Shows how account export combines paged API data with downloaded assets. |
| apps/…/migrate.ts | Shows how cross-server migration preserves relationships by mapping source IDs to destination IDs. |
| apps/…/package.json | Defines the published karakeep-mcp command and its SDK dependency. |
| apps/…/index.ts | Defines the MCP process entry point and standard I/O transport. |
| apps/…/shared.ts | Connects MCP tools to the REST SDK and reads agent connection settings. |
| apps/…/bookmarks.ts | Shows the agent-facing bookmark tools and readable-content behavior. |
| apps/…/lists.ts | Shows list tools and manual versus smart-list boundaries. |
| apps/…/highlights.ts | Shows highlight tools and destructive-action metadata. |
| apps/…/utils.ts | Defines compact tool output and MCP error conversion. |
| packages/…/README.md | Shows SDK installation, typed client use, REST request examples, and version compatibility. |
| packages/…/package.json | Defines the published SDK module, type, dependency, and build entry points. |
| packages/…/index.ts | Exposes the typed Karakeep REST client and API schemas. |
packages/sdk/vite.config.mts | Shows how the SDK build emits module formats and declaration files. |
| packages/…/tsconfig.build.json | Defines the declaration-only build that publishes SDK types with the runtime modules. |
| packages/…/karakeep-api.d.ts | Provides the generated REST paths, resource schemas, pagination types, and operation result types used by SDK consumers. |
| packages/…/index.ts | Assembles the OpenAPI document and checks the generated JSON. |
| packages/…/bookmarks.ts | Defines the core bookmark REST contract and pagination rules. |
| packages/…/types.ts | Connects shared Zod schemas to named OpenAPI schemas. |
| packages/…/karakeep-openapi-spec.json | Provides the checked-in contract consumed by documentation and client generation. |