Skip to content
devops-infinityPublic

About

OwnSERP, an MCP server for the Serper.dev search API with per-call credit accounting

Topics

Resources

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

71 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OwnSERP

An MCP server and REST API for the Serper.dev search API, with per-call credit accounting.

Status

Stable. Every release ships from a tagged commit after the full local gate passes. The semantic version promise covers the command line, the profile schema, the ledger format, the tool result shape, and the public Rust API of the ownserp-core crate, which the gate checks against the last published release with cargo semver-checks. A breaking change to any of them takes a major version, a new tool, flag, or setting takes a minor version, and a fix takes a patch. CHANGELOG.md records every change, and UPGRADING.md lists the steps for each breaking change.

Contents

Overview

OwnSERP exposes the Serper.dev search endpoints as MCP (Model Context Protocol) tools, as REST routes, and as commands. A model can search the web, images, news, places, maps, videos, shopping, scholar, patents, reviews, and lens, extract a page, research a question with numbered sources, resolve a location name, and read its own spend, all through one local server.

It is built for agents that spend metered credits. Every tool description states its price, every result carries a cost object, and a local ledger records each call. Before a call spends anything, the server can check a per-call ceiling and a session budget and refuse the call when either would be passed. Both are off until you set them, through per_call_credit_ceiling and session_budget_credits in the profile, or OWNSERP_PER_CALL_CREDIT_CEILING and OWNSERP_SESSION_BUDGET_CREDITS in the environment. An HTTP server that callers beyond this machine can reach, through a bind beyond loopback or an allowed host that is not a loopback name, refuses to start without a session budget. Results are shaped for a model rather than for a browser: invisible characters are stripped, long text is capped and marked, absent fields are omitted, and key order is fixed.

The server is one binary and needs no language runtime. It speaks MCP revision 2026-07-28 and answers clients on 2025-11-25. It runs over stdio by default, or over Streamable HTTP with a bearer token gate, where the same port also serves the REST API under /v1.

Requirements

  • To run a published binary: no runtime, no toolchain. Prebuilt binaries cover macOS, Linux, and Windows.
  • To build from source: Rust 1.94 or newer, pinned to 1.100.1 in rust-toolchain.toml.
  • A Serper.dev account and API key from https://serper.dev/api-keys.
  • A client that speaks MCP over stdio, or any HTTP client for Streamable HTTP and the REST API.
  • Optional: about 132 MB of disk for the passage model that research uses to rank passages, installed with ownserp passage-model sync.

Installation

The first path builds from a checkout, so it needs no release and suits a test machine. Every other path uses a prebuilt binary: no Rust toolchain and no compile step.

From a checkout

This path installs the code of any branch or commit on a machine, with no release, no registry, and no archive. Run it on each machine you test on.

It needs:

  • macOS or Linux. The installer refuses Windows.
  • Rust through rustup. rust-toolchain.toml pins 1.100.1, and the build uses it when rustup has it.
  • cargo-auditable: cargo install --locked cargo-auditable.
  • Bash 4.4 or later. On macOS, run brew install bash.
  • git and jq.
  1. Clone the repository.

    git clone https://github.com/devops-infinity/ownserp.git
    cd ownserp
  2. Switch to the branch or commit to test, when it is not main, then build and install.

    tools/install-local.sh
  3. Confirm the installed copy.

    command -v ownserp
    ownserp --version

The installer does these things:

  • It builds the dist profile with the locked dependencies and cargo auditable, for this machine only.
  • It installs the binary into ~/.local/bin, or into the folder given with --dir.
  • It removes an ownserp Homebrew formula after the binary is in place, unless you pass --keep-brew, and it warns when another ownserp comes first on PATH, such as an npm or cargo install copy.
  • It installs the agent skill into every client folder under the home folder, unless ownserp skill auto-install off is set.
  • It runs tools/set-up-machine.sh, unless you pass --skip-setup.
  • It runs ownserp doctor last. A problem that doctor reports, such as a missing API key, exits 1 with the binary already installed.

The machine setup does these things, and each step is safe to run again:

  • It downloads the passage model that research uses, about 132 MB.
  • It writes the bash, zsh, and fish completions and the manual page.
  • It adds the ownserp MCP entry to Claude Code, Codex, and Command Code where it is missing. An existing entry stays.
  • It names each running ownserp process that still runs an older build, so you can restart it.

A step that cannot finish is a warning, and the last line repeats the command that finishes it. tools/install-local.sh --help lists every option, and --check prints the plan and builds nothing. Store the API key on each machine with ownserp config set-api-key.

To update a machine, pull and install again, then restart any running ownserp serve:

git pull --ff-only
tools/install-local.sh

Release archives cover macOS ARM64 and x86_64, Linux x86_64 with glibc, Linux ARM64 with glibc, Linux x86_64 and ARM64 with static musl, and Windows x86_64.

npm

npx @devops-infinity/ownserp serve

The package downloads the archive for the current platform on install and runs the binary. Node 22 or newer.

Homebrew

brew install devops-infinity/tap/ownserp

macOS and Linux both install the release binary. The tap is updated by hand after each release, so it can lag the release by a few minutes.

Shell installer

curl --proto '=https' --tlsv1.2 -LsSf https://github.com/devops-infinity/ownserp/releases/latest/download/ownserp-installer.sh | sh

On Windows, in PowerShell:

powershell -ExecutionPolicy Bypass -c "irm https://github.com/devops-infinity/ownserp/releases/latest/download/ownserp-installer.ps1 | iex"

Release archive

VERSION=3.0.0
BASE="https://github.com/devops-infinity/ownserp/releases/download/v$VERSION"
TARGET=x86_64-unknown-linux-gnu
curl -LO "$BASE/ownserp-$TARGET.tar.gz"
curl -LO "$BASE/ownserp-$TARGET.tar.gz.sha256"
sha256sum -c "ownserp-$TARGET.tar.gz.sha256"
tar -xzf "ownserp-$TARGET.tar.gz"
install -m 0755 "ownserp-$TARGET/ownserp" ~/.local/bin/ownserp

Set TARGET to aarch64-apple-darwin or x86_64-apple-darwin on macOS, aarch64-unknown-linux-gnu or x86_64-unknown-linux-musl or aarch64-unknown-linux-musl on those platforms, and use the .zip file with x86_64-pc-windows-msvc on Windows.

The binary prints its shell completions and manual page on demand with ownserp completions <shell> and ownserp man. Install them where your shell and manual reader look, under ~/.local/share/bash-completion/completions/, a directory on fpath, ~/.config/fish/completions/, and ~/.local/share/man/man1/.

Every release signs sha256.sum with minisign and attaches the signature as sha256.sum.minisig; the release workflow fails rather than publish unsigned checksums. sha256.sum lists every archive, the shell and PowerShell installers, the Homebrew formula ownserp.rb, the npm package archive ownserp-npm-package.tar.gz, the CycloneDX SBOM, and the MCPB bundle. To check a download, verify the signature against the public key in this repository, then check the archive against the file:

minisign -Vm sha256.sum -P RWSPyQWAsXwP5vjgAFI/PAAtbFAd5tA4BlhyFrT+MCPNmE2J+jgT26kC
grep "ownserp-x86_64-unknown-linux-gnu.tar.gz" sha256.sum | sha256sum --check

The npm package is published from a maintainer machine after the release is signed, so the published tarball is not in sha256.sum; the unmodified ownserp-npm-package.tar.gz that it is built from is. The release carries the published tarball's SHA-256 line in ownserp-npm.sha256, which matches the tarball that npm pack @devops-infinity/ownserp@<version> downloads.

Container

The published image is built for linux/amd64 only.

docker run --rm -v ownserp-data:/var/lib/ownserp \
  ghcr.io/devops-infinity/ownserp:latest token create docker
docker run --rm -p 127.0.0.1:8777:8777 \
  -v ownserp-data:/var/lib/ownserp \
  -e SERPER_API_KEY \
  -e OWNSERP_ALLOWED_HOSTS=127.0.0.1,localhost \
  -e OWNSERP_SESSION_BUDGET_CREDITS=5000 \
  ghcr.io/devops-infinity/ownserp:latest

The first command creates a bearer token named docker and prints it once; copy it into the client. The image sets OWNSERP_TOKEN_STORE=/var/lib/ownserp/tokens.json, so the token store sits on the same volume as the ledger, and the server container that mounts that volume accepts the token. Mount a volume there, or the store is lost with the container. Run token list, token revoke docker, or token create the same way while the server runs; it reads the store again within about one second. An orchestrator that injects secrets can pass OWNSERP_BEARER_TOKENS instead.

The image serves Streamable HTTP on 0.0.0.0:8777. That bind reaches beyond the container, so the server refuses to start without a bearer token and without OWNSERP_SESSION_BUDGET_CREDITS, the most credits all callers may spend together. Add OWNSERP_PER_CALL_CREDIT_CEILING to cap one call too. It runs as uid 10001 and keeps the ledger at /var/lib/ownserp/ledger, inside the /var/lib/ownserp volume, so mount a named volume there to keep spend history and the session budget across restarts. A named volume starts with the image's owner and mode; a bind-mounted host folder must be owned by uid 10001 and must not be writable by its group or by other users. OWNSERP_ALLOWED_HOSTS must name every Host a client sends, because the allowlist derived from 0.0.0.0 matches no real Host; list the address or hostname that clients connect to. The server speaks plain HTTP, so publish the port on loopback, as above, or on a private interface that only trusted clients reach, such as -p 10.0.0.5:8777:8777 with OWNSERP_ALLOWED_HOSTS=10.0.0.5:8777. The health check calls /readyz, which needs no token and answers 503 while the API key is missing, the ledger cannot be written, store tokens are refused because the token store does not load, or the server is shutting down. The package is public, so docker pull needs no login.

Windows

Use the PowerShell installer above, or download ownserp-x86_64-pc-windows-msvc.zip from the release page, extract ownserp.exe, and put the folder on your PATH. A client configuration that cannot resolve the name uses the absolute path to ownserp.exe.

MCPB bundle

The bundle carries the Linux x86_64 binary only. On another architecture, install the archive for that platform instead.

Download ownserp-<version>.mcpb from the release page and open it in a client that supports MCP Bundles. The bundle asks for the API key and stores it in the OS keychain.

Upgrading

ownserp update asks GitHub for the latest release and prints the command that fits this install: brew upgrade ownserp, cargo install --locked ownserp, the npm global install, or the container pull. It checks and reports only, so the upgrade runs through the channel you installed with and that channel's own signing and review stay in force. ownserp update --json gives current, latest, updateAvailable, and command for scripts. The check calls api.github.com and nothing else, and the server itself still sends no telemetry. When GitHub declines the lookup, the command reports ownserp.update_rate_limited; wait a few minutes and run it again.

UPGRADING.md lists every change that needs a step from you, in these sections: before you start, tool names, client allowlists, serve installing the skill, the Overrides struct of ownserp-core, error codes, environment variables, proxies, arguments, country and language, result counts, scrape videos, bearer tokens, the spending cap and token for a reachable server, a bearer token required by default, probes, lockout, HTTP routes and the OpenAPI document, rate limit, request body size, exit codes, the API key, status and doctor output, the arguments key file, the ledger directory, the profile file, allowed hosts, the ledger, the session budget across processes, upstream failures that may have been billed, the resolve tool, containers, the MCPB bundle, the ownserp-core Rust API, releasing (for maintainers), scripts under tools/, verifying the upgrade, and rolling back.

Quick start

export SERPER_API_KEY="your key"
npx @devops-infinity/ownserp doctor
npx @devops-infinity/ownserp serve

The first command sets the key for the shell. The second prints every resolved setting with its source, the key masked, any problem it finds, and the answer from both Serper hosts. The third starts the server on stdio, which is the command an MCP client launches, so it keeps running until the client stops it.

To connect a client, add the server as shown in the next section. Stdio needs no bearer token. To serve Streamable HTTP and the REST API instead, create a token first, because serve --http refuses to start without one:

npx @devops-infinity/ownserp token create laptop
npx @devops-infinity/ownserp serve --http

token create prints the token once; the store keeps only its hash. Give the token to the client as Authorization: Bearer <token>.

Connect a client

Every client runs ownserp serve as a stdio process and passes SERPER_API_KEY in the environment. When a desktop client cannot resolve ownserp on its PATH, use the absolute path printed by command -v ownserp.

ownserp mcp-config --client <client> prints the entry below for one client, in that client's format, with the key left as an environment reference or a placeholder. The clients are claude-code, claude-desktop, codex, cursor, vscode, windsurf, zed, and command-code. --url <url> prints a Streamable HTTP entry instead, with an Authorization: Bearer header that reads OWNSERP_BEARER_TOKEN where the client starts; set that variable to a token from ownserp token create <name>. It takes https://, or http:// only for a loopback address (127.0.0.1, localhost, or [::1]) or a private IP literal: 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, 169.254.0.0/16, fc00::/7, or fe80::/10, such as http://10.0.0.5:8777/mcp or http://[fd00::1]:8777/mcp. Any other host over http://, any other hostname included, is refused, because a name can resolve to a public address. --name <NAME> sets the server name in the entry, ownserp by default. --command <PATH> sets the command the client starts and cannot be combined with --url.

Claude Code

claude mcp add --scope project ownserp -- ownserp serve

Or commit a .mcp.json at the project root:

{
  "mcpServers": {
    "ownserp": {
      "command": "ownserp",
      "args": ["serve"]
    }
  }
}

Claude Desktop

Add this to claude_desktop_config.json, at ~/Library/Application Support/Claude/ on macOS or %APPDATA%\Claude\ on Windows. Use the absolute path to the installed binary, because a desktop application does not inherit the shell PATH:

{
  "mcpServers": {
    "ownserp": {
      "command": "/absolute/path/to/ownserp",
      "args": ["serve"],
      "env": { "SERPER_API_KEY": "your key" }
    }
  }
}

The npm package installs the prebuilt binary for the current platform. Point command at ownserp when the client inherits your PATH, or at the absolute path command -v ownserp prints when it does not.

OpenAI Codex CLI

In ~/.codex/config.toml, or a project .codex/config.toml:

[mcp_servers.ownserp]
command = "ownserp"
args = ["serve"]
env_vars = ["SERPER_API_KEY"]

env_vars passes the variable from the environment, so the key never enters a command line.

Command Code

commandcode mcp add-json --scope project ownserp '{"type":"stdio","command":"ownserp","args":["serve"]}'

Cursor

In ~/.cursor/mcp.json, or .cursor/mcp.json for one project:

{
  "mcpServers": {
    "ownserp": {
      "command": "ownserp",
      "args": ["serve"],
      "env": { "SERPER_API_KEY": "your key" }
    }
  }
}

Windsurf (Cascade)

In ~/.config/devin/mcp_config.json on Linux and macOS, or %APPDATA%\devin\mcp_config.json on Windows:

{
  "mcpServers": {
    "ownserp": {
      "command": "ownserp",
      "args": ["serve"],
      "env": { "SERPER_API_KEY": "your key" }
    }
  }
}

VS Code

Run MCP: Add Server from the Command Palette, or add .vscode/mcp.json to the workspace:

{
  "servers": {
    "ownserp": {
      "type": "stdio",
      "command": "ownserp",
      "args": ["serve"],
      "env": { "SERPER_API_KEY": "your key" }
    }
  }
}

Zed

In settings.json:

{
  "context_servers": {
    "ownserp": {
      "command": "ownserp",
      "args": ["serve"],
      "env": { "SERPER_API_KEY": "your key" }
    }
  }
}

Other MCP clients

Use stdio with command ownserp and argument serve, and set SERPER_API_KEY in the client's environment block or in the shell the client inherits.

API key

Three sources work, and the process environment wins over the keychain.

  • Environment variable, in the shell or in the client's env block:
export SERPER_API_KEY="your key"
  • OS keychain, read from stdin so the key does not enter shell history:
printf '%s' "$SERPER_API_KEY" | ownserp config set-api-key
  • Client JSON config, where the client injects the env block it holds.

The key is never read from a command line argument, never written to the profile file, and never printed unmasked. On Linux the keychain store is Secret Service, so a desktop session bus must be running; on a headless server, set SERPER_API_KEY instead. A keychain that does not answer within 5 seconds counts as unreadable, and the error says so. That read is abandoned, and later reads in the same process fail at once with the same timeout text. ownserp config delete-api-key removes the stored key and says when there was none. Use one named key per project or agent at https://serper.dev/api-keys, because a key cannot be scoped to a smaller spend.

Tools

Every tool description in the tool list states the price, so a model can budget before spending.

  • search, 1 credit. Web results with knowledge graph, answer box, and related searches.
  • images, 1 credit, 2 when num is above 10. Image results with dimensions and source.
  • news, 1 credit. Dated news results.
  • places, 1 credit. Local businesses filtered by a Serper location name.
  • maps, 3 credits. Places anchored to a map viewport in @lat,lng,zoomz form.
  • videos, 1 credit. Video results with channel and duration.
  • shopping, 2 credits. Product listings with price and delivery.
  • scholar, 1 credit. Papers with publication info and citation counts.
  • patents, 1 credit. Patents with assignee and dates.
  • autocomplete, 1 credit. Query suggestions, taking only q, gl, hl, resolveLinks, fields, and resultText.
  • reviews, 1 credit. Reviews for one place, with cursor pagination through nextPageToken.
  • lens, 3 credits. Reverse image search for a public image URL.
  • scrape, 2, 6, or 10 credits by page difficulty. Page content as Markdown or text, with an optional title, images, links, and videos, and the actual credits read from the response. maxChars and offset read a long page in parts, and an offset read within 600 seconds answers from memory at 0 credits.
  • research, the sum of its sub-calls: 1 credit per search angle and 2, 6, or 10 per page read, about 14 credits for the default effort. One question in a bounded run: it searches 1 to 4 angles, reads the best pages, and returns numbered sources with the passages that match the question, a verdict of empty, thin, or sufficient, and up to 3 next calls. isPlanOnly shows the plan and its price for free. A local passage model ranks the passages once ownserp passage-model sync has installed it; until then word match picks them and the answer carries a passages_by_words note.
  • status, free and unauthenticated. The status of the Serper API from api.serper.dev.
  • locations, free and unauthenticated. Canonical location names to pass as location.
  • resolve, free. Real destination URLs for the https://www.google.com/goto?... links a search returns. Any other link is refused with ownserp.bad_request.
  • usage, free. The version, call count, failed calls, credits, dollars, tokens served and saved, cache hits, the budget left, and the ledger's health.
  • batch, the single price per query. Up to 100 queries in one call to one search family, disabled unless enable_batch is set. tools/list omits it while it is disabled, and a call to it is refused with ownserp.tool_disabled, naming enable_batch.

Argument names are camelCase, for example resolveLinks, resultText, nextPageToken, sortBy, topicId, placeId, and includeMarkdown. A request that sends an unknown name, such as the older resolve_links, is refused as a bad request. Free tools set the readOnlyHint and idempotentHint annotations to true; every paid tool, batch included, sets them to false, because a repeat spends again.

search, news, images, videos, scholar, patents, each batch query of those kinds, and research take query-shaping arguments that add search operators to q: exactPhrases, anyWords, excludeWords, sites, excludeSites, filetypes, titleTerms, urlTerms, publishedAfter, and publishedBefore. places, maps, shopping, and a batch of places or shopping refuse them with ownserp.bad_request.

search sends num: 10 when the caller leaves num out, so one call always asks for a full Google page for the same credit. Raise num up to 100 to ask for more in one call, and keep page in step with it.

search, images, and videos also ask Google for results from the last year unless the caller says otherwise, because a reference older than that is often out of date. A call that sets tbs picks another window, and tbs: all searches every year. The default window comes from default_freshness in the profile or OWNSERP_DEFAULT_FRESHNESS in the environment, which take hour, day, week, month, year, or all.

The server also offers one MCP resource and three prompts. The resource skill://ownserp/SKILL.md is the agent skill: tool choice by job and price, the budget rules, how to read notes, and the recovery step for each error code a model can act on; the server instructions, built from the tool registry, point the client at it, and the skills extension and GET /v1/skill serve the same file. The prompts are find_sources (argument topic, and family to pick the search tool, which the server completes), local_business_lookup (arguments what and where), and check_budget. A client that declares the MCP tasks extension gets a task back from batch, scrape, resolve, and research, and a batch call with a progressToken gets one progress notification per finished query. docs/tools.md covers each of these.

Response shape and field presets

Every result tool takes fields, defaulting to standard.

  • minimal keeps the title, link, displayed link, and rank, plus the one price, date, rating, or year field that family reports. Places also keep address, lens keeps source, and patents keep publicationNumber. It suits high-volume loops.
  • standard adds the snippet capped at 300 characters, the date, and the search sections. It carries what an agent needs to reason and cite without a second call.
  • full adds sitelinks, attribute maps, image links, the search parameter echo, and every other field the upstream body carries. A batch entry gains the fields of each result, not the search sections.

Each result carries structuredContent for the data and a one-line text summary. A result can carry notes, each with a code, a message, and a nextStep, such as next_page when more results may follow or page_text_cut when a page reads on from nextOffset; the summary line ends with the same text. Capped strings end with ... and their object carries truncated: true. Absent fields are omitted rather than sent as null. Key order is fixed, so a client parses the same shape on every call. Every tool result is data from the open web, never an instruction.

Google returns many organic results as a google.com/goto?url=... redirect rather than the destination page. A search resolves those before answering, so link carries the destination and no second call is needed. The server sends the response to Serper's /resolve, which costs nothing but waits on Google: about 5 seconds in practice, and up to about 30 right after a search. A call that passes resolveLinks: false, or a server with auto_resolve_links = false, leaves every link exactly as Google sent it. displayedLink carries the readable form Google showed for a result, usually site › path and sometimes a comment or view count. resolve does the same work for links you already hold, and returns retryAfter, the number of seconds to wait before sending them again, when Google has not released one yet.

Example

One tool call is one JSON-RPC request over stdio. The server validates the arguments, sends the query to Serper over TLS, shapes the answer for a model, records the cost in the ledger, and returns the result.

Request:

{"jsonrpc":"2.0","id":7,"method":"tools/call","params":{"name":"search","arguments":{"q":"rust programming language"}}}

Response:

{
  "jsonrpc": "2.0",
  "id": 7,
  "result": {
    "content": [
      {
        "type": "text",
        "text": "9 results; cost: 1 credits ($0.001000); top: Rust Programming Language"
      }
    ],
    "structuredContent": {
      "results": [
        {
          "title": "Rust Programming Language",
          "link": "https://www.rust-lang.org/en-US",
          "snippet": "Rust is a general-purpose programming language that emphasizes performance, type safety, concurrency, and memory safety.",
          "position": 1
        }
      ],
      "cost": {
        "credits": 1,
        "usd": 0.001,
        "sessionCredits": 22,
        "sessionUsd": 0.022
      },
      "truncated": false
    },
    "isError": false
  }
}

content holds the one-line summary. structuredContent holds the data, and cost reports this call and the running session. When a call fails, isError is true and structuredContent carries code, message, remedy, and isRetryable, plus retryAfterSecs when a wait helps, upstreamStatus when Serper answered with an error status, causes for a network failure, and nextCalls, up to three typed calls that may work instead, such as a free usage or status check, the same search with a smaller num, or the same call with afterSecs when the failure was not billed.

Command line

Every tool also runs as a command, so ownserp search "rust async" makes the same call as tools/call and records it in the same ledger. A tool command takes its query, URL, links, or batch queries as bare values, and its other arguments as kebab-case flags, such as --num, --resolve-links=false, or --result-text full, or the whole argument object with --args '{"q":"rust async"}', --args @FILE to read it from a file, or --args - to read it from stdin; a flag given beside --args replaces the same field. It prints the structured result as JSON, or only the one-line summary with --summary, and it accepts --profile and --ledger-dir. A command line it refuses prints an ownserp.bad_request body as JSON on standard error and exits 2. ownserp tools lists every enabled tool with its flags, price, and REST route, and --json adds each input schema. Run ownserp <tool> --help for the flags of one tool, followed by its REST route and MCP tool name.

The other commands:

  • ownserp serve serves MCP over stdio, or over Streamable HTTP and the REST API with --http. Its flags are --http, --no-http, --bind, --profile, --ledger-dir, --pack, --cache-ttl <SECONDS>, --enable-batch, --no-batch, --bearer-token-file, --token-store, and --allowed-tools <TOOLS>. --pack takes starter, standard, scale, ultimate, or custom. At startup it installs or refreshes the agent skill in each client folder under the home folder, unless ownserp skill auto-install off turned that off.
  • ownserp doctor prints every resolved setting with its source, lists every problem, lists warnings, and probes api.serper.dev and the account balance. It previews what serve would refuse: the HTTP checks run when the profile sets http = true or when --http or --bind is given; --bearer-token-file and --token-store only name the files to check, and the ledger directory, the ledger file, the reservation file, the arguments key, and the token store are checked every time. A note counts the active, expired, and revoked store tokens, a warning names each store token that expires within 7 days, and another warns when require_token is off and no token is configured, because the HTTP server then runs open. A damaged ledger or a damaged reservation file is a problem. The warnings section names any old OWN_SERPER_* variable, SERPER_USD_PER_1K, or other removed variable still set, a ledger file above 64 MiB, a ledger with a partial last line that the next write trims, spending is not capped; set session_budget_credits to cap what all callers spend together, because per_call_credit_ceiling alone caps only one call when no session budget is set, and a missing per_call_credit_ceiling when an HTTP server that callers beyond this machine reach has a session budget but no ceiling. The warnings also name a write probe in the ledger directory that could not be removed. A notes section lists the live claims in the reservation file, the credits held in abandoned rows, and the caller policy file with the callers it names; a broken caller policy is a problem with --http and a warning without it. A skill section shows the auto install switch and the state of the skill copy of each client and of each project copy in the current folder, and a passage model row shows whether the model is installed and its folder, as passageModel in --json. The same lists appear under warnings and notes in --json, and neither changes the exit code.
  • ownserp token create <name>, ownserp token list, ownserp token revoke <id-or-name>, and ownserp token remove <id-or-name> --yes manage the bearer tokens of the HTTP server, as described in HTTP deployment. Each takes --profile and --token-store; create, list, and revoke take --json, and create takes --expires-in-days <DAYS> and --bearer-token-file <PATH>. Give create the same file as the server's serve --bearer-token-file, so a new name cannot repeat a static token name in it. An unknown id or name, a taken or malformed name, and remove without --yes exit 2.
  • ownserp config set-api-key, ownserp config show, and ownserp config delete-api-key store, show, and remove the key. set-api-key reads the key from a pipe and exits 2 when standard input is a terminal or the key is empty, longer than 512 characters, holds whitespace or a control character, or is not UTF-8.
  • ownserp audit verify, ownserp audit rotate, and ownserp audit remove check, archive, and delete the ledger. audit verify also checks the reservation file. audit remove without --yes lists the files it would delete and exits 2.
  • ownserp audit clear-reservations deletes calls.reservations.jsonl and its .tmp file under the ledger lock, so paid calls that a damaged reservation file refuses can run again. Without --yes it lists the files and the claims they hold and exits 2. It takes --ledger-file and --json, and the dry run and the real run print one JSON shape: removed, wouldRemove, note, and claims.
  • ownserp skill show prints the built-in agent skill. ownserp skill install writes it into a client's skills folder: --tool claude-code (the default), codex, or command-code, and --scope user (the default) or project. --to <PATH> names a skills folder instead, and --to auto writes into every client folder under the home folder. --dry-run prints what it would write, and --if-enabled writes nothing while ownserp skill auto-install off is set. An existing file with other content is replaced only with --force. It exits 2 when HOME (or USERPROFILE on Windows) is missing or relative and no --to is given, when the target is a symbolic link or not a regular file, when it holds other content and --force is not given, and when the folder cannot be written, naming --to. ownserp skill auto-install on, off, and status set and show the switch that lets serve install the skill.
  • ownserp sbom writes a CycloneDX 1.6 bill of materials from the Cargo.lock of the matching ownserp source, to stdout or to --output. It lists the runtime and build dependencies only, so dev-dependencies such as wiremock are absent. It refuses a lockfile from another project or another version, and it replaces an existing --output file only with --force. It marks each value its inputs cannot supply, such as a third-party license, as unknown.
  • ownserp mcp-config --client <client> prints a client entry, as described in Connect a client. --write merges it into the client's config file in place, for codex, command-code, claude-desktop, and cursor, and --scope user (the default) or --scope project picks the file. --only-if-missing keeps an existing entry of that name as it is.
  • ownserp eval --file <golden.json> --max-credits <CREDITS> scores search quality against a golden file: a JSON array of cases, each with query, an optional search tool, gl, hl, expectUrls or expectHosts, and maxAgeDays. Every case is a paid call, reserved and recorded like a tool command, and the command refuses to start when the cases plan to spend more than --max-credits. It reports the hit rate, recall, reciprocal rank, freshness, and latency, and exits 1 when --min-hit-rate, --min-recall, --min-reciprocal-rank, --min-freshness, or --max-p95-ms is missed. --json prints the report as JSON.
  • ownserp passage-model sync downloads the passage model that research uses to rank passages: cross-encoder/ettin-reranker-32m-v1, under the Apache-2.0 license, about 132 MB from huggingface.co at a pinned revision, into passage-model in the data folder. Each file is checked against its pinned size and SHA-256 before it is saved, and a file already saved and verified is kept. --dry-run lists each file and whether it would be downloaded, and downloads nothing. ownserp passage-model status shows whether the model is installed, and its folder. The server never downloads the model. docs/operations.md covers it.
  • ownserp update, ownserp completions <shell>, and ownserp man [command] check for a release, print completions, and print a manual page.

ownserp doctor, ownserp config show, ownserp audit verify, and ownserp audit clear-reservations take --json and print one JSON document. The global flags -v, -q, and --log-level set the log level on standard error, and RUST_LOG still wins.

Exit codes:

  • 0: success. A reader that closes the output early, as head does, still reads as success unless the command had already failed.
  • 1: a runtime failure, such as ownserp.config_error, ownserp.ledger_fault, ownserp.keychain_error, or ownserp.internal_error; a doctor run that found a problem; an eval run that missed a threshold; an audit verify that found a ledger or a reservation file it cannot use; an audit remove that could not list the files it would delete; and an audit remove --yes or audit clear-reservations --yes that found the ledger lock held by a running process.
  • 2: a usage error: a wrong flag or value, ownserp.bad_request, ownserp.tool_not_found, ownserp.tool_disabled, or ownserp.caller_refused; a refused config set-api-key, skill install, or eval; and audit remove or audit clear-reservations without --yes when files exist.
  • 3: the key: ownserp.auth_missing or ownserp.auth_failed, and a doctor run with no key or a rejected key.
  • 4: a refusal: ownserp.budget_refused, ownserp.credits_exhausted, ownserp.rate_limited, ownserp.auth_rate_limited, ownserp.caller_rate_limited, or ownserp.update_rate_limited.
  • 5: the upstream: ownserp.upstream_failed or ownserp.deadline_exceeded, and a doctor run where api.serper.dev/health did not answer or answered with a status that is not a success.
  • 130, 143, and 129: a tool command stopped by a signal: 130 for Ctrl-C, 143 for SIGTERM, 129 for SIGHUP, each with ownserp.cancelled. A second signal gives the call 2 seconds, writes queued rows for up to 2 more, and exits with that signal's code, with a warning line when rows stay queued. A call that ends within the first 2 seconds can exit with the first signal's code. A tool command writes its queued ledger rows before it returns.

Cost accounting and the ledger

The ledger lives at $XDG_DATA_HOME/ownserp/ledger/calls.jsonl, or ~/.local/share/ownserp/ledger/calls.jsonl. On Windows it lives at %LOCALAPPDATA%\ownserp\ledger\calls.jsonl, and when HOME is set it follows the Unix path. A row holds the tool, the endpoint, a keyed hash of the arguments, estimated credits, actual credits when the response reports them, duration, status, bytes, and token counts. Query text is never written.

A call that Serper refuses before processing it is recorded at zero credits, because nothing was billed: a redirect, a 400, 401, 403, 404, 422, or 429 status, or a 500 or 503 status. Any other status, such as a 408, a 502 or 504 from a gateway in front of Serper, or another 4xx or 5xx, is recorded at the estimate and counts against the budget, because the request may have been processed and billed. A timeout, a cancel, or a deadline is recorded at the estimate, because the request may have reached Serper and been billed. A paid call is sent again only when the connection could not be made, never after a 5xx or a timeout, so one call cannot be billed twice; the free GET lookups (locations, status, and the balance probe) also retry a 5xx. A REST or HTTP client that hangs up mid-call does not lose the row: the call is cancelled and recorded at the estimate.

ownserp audit verify

On Unix the ledger directory is owner-only (0700) and the file is owner-only (0600). A ledger directory that its group or other users can write is refused at start, with the chmod go-w fix in the message. On Windows the directory sits under %LOCALAPPDATA%, so it inherits the user profile's access rules. One line is capped at 1 MiB. Any number of ownserp serve processes on one machine share this one file, one hash chain, and one running total. A process takes the file lock only while it reads the rows written since its last call and appends its own row, so no process holds the lock for as long as it runs. A final row that only lost its newline is kept, because its hash proves it was written; anything less complete is dropped under that lock, and the chain check covers every complete row. Each row carries the format version, and a file written by a newer binary is refused by name instead of being read as damage. On Windows a running server does not notice a rotate, so restart it to pick up the new chain.

The arguments hash is an HMAC, a keyed hash, keyed by args.key inside the ledger directory (<ledger dir>/args.key), created with owner-only permissions, so the ledger alone cannot confirm a guessed query. A key file that the group or other users can read or write, that belongs to a user other than the one that runs ownserp, or that is not 32 bytes is refused. A key in the folder above the ledger directory is not read.

When a ledger write fails, the rows wait in memory and the server retries the write; paid calls pause until a write succeeds, and /readyz answers 503 meanwhile. The background retry waits 500 ms at first and backs off up to 30 seconds between tries, and a readiness check or a paid call tries the write itself at most once every 2 seconds. A row that could not be written at all is counted as lost, in usage and /metrics. Paid calls are refused and /readyz answers 503 until one marker row with tool ledger, status error:ownserp.rows_lost, and the lost credits is written; the retry writes it with no restart, then paid calls resume, and the chain keeps counting those credits. When a queued row has waited 60 seconds, the log says so once a minute while the retry goes on. A ledger file that someone shortened in place, or rewrote in place past the part a process had read, is read again from the start. A ledger file failure during a call reports ownserp.ledger_fault.

session_budget_credits counts every credit in the current ledger chain, whichever process wrote it and across restarts, so the budget is per chain. ownserp audit rotate starts a fresh chain and so starts the count again. The budget also holds across processes that share one ledger directory. Each process writes the credits it has reserved but not yet recorded to calls.reservations.jsonl beside the ledger, under the same lock, and a new reservation counts the chain total plus every claim of the other processes, live or expired. While a process holds credits, it renews its claim every 60 seconds, so a long call stays in the count. A claim not renewed for 600 seconds, or dated that far ahead of the clock, is written into the chain once as one row with tool abandoned and status error:ownserp.abandoned for its credits, so a killed process cannot lower the count; ownserp audit rotate records such claims into the chain it archives. A budget refusal names its cause right after budget refused: (per-call ceiling: , ledger chain spent: , held by this process: , or held by other processes: ), splits the count into credits recorded or expired, credits held here, and credits held by other processes, and gives the seconds until the soonest claim of another process expires. For a spent chain it names the credits in abandoned rows, expired claims, and marker rows, and its remedy says that only ownserp audit rotate clears abandoned rows. usage and /metrics report the budget left after the claims of other processes too, and usage, audit verify, and doctor name the credits in abandoned rows. The calls count leaves out abandoned and marker rows. A damaged reservation file refuses paid calls with ownserp.ledger_fault until you run ownserp audit clear-reservations --yes. The response cache stays per process: each process keeps its own cache. OWNSERP_LEDGER_DIR gives a client its own separate ledger when that is what you want.

To close a ledger without losing it, run ownserp audit rotate. It trims a partial last line, verifies the chain, and archives the file beside the original with a timestamp. Every running server on Linux or macOS opens a fresh chain on its next write. When the chain is already damaged, ownserp audit rotate --archive-damaged archives the file up to the last row that verified, so a fresh chain can start and the spend history stays readable; it refuses a file written by a newer ownserp and leaves it in place. Both forms leave calls.reservations.jsonl in place, so calls still in flight count against the fresh chain. ownserp audit remove lists the live ledger, its archives, the reservation file, and the arguments key, and deletes them only with --yes, under the ledger lock, printing each path it removed; while a running process holds the lock it removes nothing. ownserp audit verify names the state of the ledger and of the reservation file, and the exact next step.

Dollar figures come from the pack tier: starter (default), standard, scale, ultimate, or custom, which has no rate of its own. OWNSERP_USD_PER_1K or the usd_per_1k profile key replaces the rate of any pack.

Configuration

Each setting is resolved in this order: the command line flag, then the environment, then the profile, then the default. SERPER_API_KEY wins over the keychain. A bearer token file, from --bearer-token-file or OWNSERP_BEARER_TOKEN_FILE, replaces OWNSERP_BEARER_TOKENS, and doctor and config show note when the variable is ignored. ownserp doctor shows every value and where it came from. docs/configuration.md holds the full reference.

Environment variables:

  • SERPER_API_KEY: the Serper API key.
  • OWNSERP_PROFILE: the profile file path.
  • OWNSERP_BIND: the HTTP bind address, default 127.0.0.1:8777.
  • OWNSERP_BEARER_TOKENS: comma-separated name:token entries.
  • OWNSERP_BEARER_TOKEN_FILE: an owner-only file of name:token entries.
  • OWNSERP_REQUIRE_TOKEN: default true, which refuses to serve HTTP without a usable token on any bind; false lets a loopback server run open on purpose.
  • OWNSERP_TOKEN_STORE: the token store file, an absolute path, default tokens.json in the config folder.
  • OWNSERP_ALLOWED_HOSTS: comma-separated Host names HTTP mode accepts.
  • OWNSERP_RATE_LIMIT_PER_MINUTE: the requests one HTTP caller may send a minute, 0 to 100000, default 600; 0 turns the limit off.
  • OWNSERP_PACK: the credit pack tier.
  • OWNSERP_USD_PER_1K: the dollar rate per 1,000 credits, which replaces the rate of any pack.
  • OWNSERP_CACHE_TTL_SECS: the response cache lifetime; 0 keeps the cache off.
  • OWNSERP_CACHE_MAX_BYTES: the cache size cap, default 16 MiB, at most 1 GiB.
  • OWNSERP_LEDGER_DIR: the ledger directory, an absolute path.
  • OWNSERP_PER_CALL_CREDIT_CEILING: the most credits one call may reserve.
  • OWNSERP_SESSION_BUDGET_CREDITS: the most credits the ledger chain may hold.
  • OWNSERP_ENABLE_BATCH: true turns on the batch tool.
  • OWNSERP_ALLOWED_TOOLS: a comma list of the only tools to serve, such as search,usage.
  • OWNSERP_REQUEST_TIMEOUT_SECS: the upstream timeout per attempt, 1 to 600, default 30.
  • OWNSERP_DEFAULT_FRESHNESS: the default search window.
  • OWNSERP_AUTO_RESOLVE_LINKS: false leaves Google redirect links as sent.
  • OWNSERP_LOG_FORMAT: json for one JSON object per log line, or text.
  • OWNSERP_IN_CONTAINER: 1 makes ownserp update print the container pull; the image sets it.

RUST_LOG sets the log filter and wins over the log flags. Text logs use color when standard error is a terminal. A non-empty NO_COLOR turns color off and wins over everything; an empty one counts as unset. CLICOLOR_FORCE turns color on off a terminal, unless it is empty or 0. The older OWN_SERPER_* names, SERPER_USD_PER_1K, and every other removed variable are not read, and a warning names each one still set, with its new name when it has one; see UPGRADING.md.

OwnSERP always connects straight to Serper and, for ownserp update, to GitHub. It never uses a proxy: HTTP_PROXY, HTTPS_PROXY, ALL_PROXY, NO_PROXY, their lowercase forms, and the system proxy settings are ignored.

Profile file at $XDG_CONFIG_HOME/ownserp/profile.toml, or ~/.config/ownserp/profile.toml. On Windows it is %APPDATA%\ownserp\profile.toml when HOME is unset:

version = 1
pack = "starter"
cache_ttl_secs = 0
cache_max_bytes = 16777216
ledger_dir = "/absolute/path/to/ownserp-ledger"
per_call_credit_ceiling = 10
session_budget_credits = 500
enable_batch = false
http = false
bind = "127.0.0.1:8777"
require_token = true
token_store = "/absolute/path/to/tokens.json"
allowed_hosts = ["search.example.com"]
rate_limit_per_minute = 600
request_timeout_secs = 30
default_freshness = "year"
auto_resolve_links = true

version is the profile schema version. It is 1 today, and a profile that names a newer version is refused by name. An unknown key is refused. Bearer tokens are never read from the profile; token_store names only the file that holds their hashes. On Linux and macOS the profile is refused when the group or other users can write it, or when its owner is neither the user that runs ownserp nor root; a symbolic link is judged by the file it points at.

ledger_dir takes an absolute path. The file is a TOML document, so a ~ or a variable is stored literally rather than expanded.

allowed_hosts lists the Host names HTTP mode accepts, which are the names and addresses clients use to reach the server directly; leave it unset to derive them from the bind address. An allowed host that is not a loopback name makes serve --http need a bearer token and session_budget_credits. The profile above sets the budget; the token comes from the token store, the environment, or a token file.

A custom pack with no usd_per_1k reports credits with no dollar figure, because the rate is unknown.

The cache is off by default. cache_ttl_secs above zero turns it on; a hit answers with cacheHit: true and charges nothing. A call that sets tbs itself skips the cache, and the default freshness window does not.

HTTP deployment

The HTTP server requires a bearer token by default, on every bind, loopback included. Create one with ownserp token create:

ownserp token create laptop
ownserp serve --http

ownserp token create <name> prints a token of the form ownserp_<id>_<secret> once on standard output, where <id> is 8 hex characters and <secret> is 32 random bytes from the OS random source in base64url. A line on standard error names the token's id and expiry and says the token cannot be shown again, because the store keeps only its SHA-256 hash. --expires-in-days <DAYS>, from 1 to 3650, makes it expire; without it the token never expires. The store is tokens.json in the config folder, ~/.config/ownserp/tokens.json on Linux and macOS, or the path in OWNSERP_TOKEN_STORE, the token_store profile key, or --token-store.

ownserp token list shows each token's id, name, status (active, expired, or revoked), creation time, and expiry, and never the token or its hash. ownserp token revoke <id-or-name> marks a token revoked, and ownserp token remove <id-or-name> --yes deletes its entry. A running server checks the store file at most once a second and reloads it when it changed, so a new token works and a revoked one stops working within about one second, with no restart. A store that fails to reload leaves the last good copy in use for up to 60 seconds and logs a warning at most once a minute; after that every store token is refused until the store loads again, /metrics shows it under auth.tokenStore, and /readyz answers 503 with ownserp.token_store_unreadable. An expired or revoked token gets the same 401 answer as a wrong one; the log and /metrics count it under expiredTokens or revokedTokens, by token id, never by token.

The store file is owner-only (mode 0600) in a folder that token create makes owner-only (0700). The server and every token command refuse a store that is a symbolic link, open to the group or other users, owned by another user, or kept in a folder the group or other users can write. Each write takes a lock file beside the store, writes a temporary file, syncs it, and renames it over the store.

Static tokens remain for an orchestrator that injects secrets. Every bearer token has a name, written as name:token. The name is 1 to 32 characters of a-z, 0-9, _, and -, and it labels the caller in logs and metrics. The token is at least 32 printable ASCII characters, with at least 10 distinct characters. A token that repeats one block, or that holds a run of 8 or more consecutive characters such as abcdefgh or 87654321, is refused as easy to guess. Two entries may not share a name or a token, and no store token may use a static token's name: token create refuses such a name, and serve --http refuses to start when the store and a static source share one. A client sends only the token part, as Authorization: Bearer <token>.

export OWNSERP_BEARER_TOKENS="ci:$(openssl rand -base64 48)"
ownserp serve --http --bind 127.0.0.1:8777

To keep tokens out of the environment, put them in a file, one entry per line or comma separated, with blank lines and # lines skipped. The file must be a regular file, not a link, owned by the user that runs ownserp, not readable or writable by the group or other users, and at most 64 KiB.

umask 077
printf 'ci:%s\n' "$(openssl rand -base64 48)" > ~/.config/ownserp/tokens
export OWNSERP_SESSION_BUDGET_CREDITS=5000 OWNSERP_PER_CALL_CREDIT_CEILING=100
ownserp serve --http --bind 0.0.0.0:8777 --bearer-token-file ~/.config/ownserp/tokens

A bind beyond loopback needs a bearer token and a session budget. So does a loopback bind with an OWNSERP_ALLOWED_HOSTS entry that is not a loopback name, because callers beyond this machine reach it by that name. Without either, the server refuses to start with ownserp.config_error, and the message names the setting that brought outside callers and every missing setting at once. per_call_credit_ceiling stays optional there, but set it too, so one call cannot spend the whole budget. With no usable token, no active store token and no static token, serve --http refuses to start on a loopback bind too, and the message names ownserp token create <name>. To run a loopback server without a token on purpose, set OWNSERP_REQUIRE_TOKEN=false or require_token = false; the server then logs a warning that it runs open, and ownserp doctor warns too. That setting never opens a bind beyond loopback or an outside allowed host. The stdio transport never needs a token. ownserp doctor --http --bind 0.0.0.0:8777 lists the same refusals before you start, and warns when that bind has a budget but no per-call ceiling. A plain loopback bind may run without a session budget; it then logs a warning, and a per-call ceiling alone does not silence it.

Routes:

  • /healthz and /startupz are open and answer ok while the process runs.
  • /readyz is open and answers ready, or 503 with a minimal problem body that carries only the code: ownserp.auth_missing, ownserp.ledger_fault, ownserp.token_store_unreadable, or ownserp.shutting_down. The detail goes to the log, at most once a minute, and to /metrics.
  • /metrics needs a token and reports calls per tool, routes, status classes, refused connections, authentication failures, rate-limit refusals, per-caller counts, readiness with its detail, and the ledger. Every token can read every caller's counts.
  • /v1/... is the REST API, and needs a token.
  • An answer under the rate limit carries RateLimit-Limit and RateLimit-Remaining, and every retryable 429 or 503 under /v1 carries Retry-After.
  • Every other path is the MCP endpoint, and needs a token.

Limits:

  • Client address: the TCP peer address of the connection, IPv6 masked to its /64. Request headers never change it, so the lockout, the rate limit, the connection cap, and the audit log all key on the peer that connected.
  • Lockout: 5 failed attempts that send a wrong token within 60 seconds lock that client address for 30 seconds, answered with ownserp.auth_rate_limited and Retry-After. IPv6 clients are counted per /64. While the lock lasts, a correct token is admitted at once; only a wrong or missing token gets the 429. Wrong guesses are counted, logged at most once a minute, and do not extend the lock. A token with the store shape that ownserp token create prints is always checked, also from a locked address, and a wrong one never counts toward the lock, so callers that share one NAT or Docker bridge gateway address keep working with store tokens.
  • Rate: each caller, named by its token or by its client address when no token is set, may send rate_limit_per_minute requests a minute (default 600, with a burst of one tenth of that, at least 10) over REST and MCP. A request over it gets 429 with ownserp.rate_limited and Retry-After. 0 turns it off.
  • Connections: at most 256 open, and 16 per client address, counted per /64 for IPv6. Loopback peers are exempt from the per-address cap. Clients behind one NAT gateway, or arriving through Docker's bridge gateway, share one address and so share those 16. A refused connection gets 503 with ownserp.busy.
  • Requests: at most 128 in flight, health and metrics routes not counted. With a token store or more than one static token, each caller may hold at most 112 of them, so one caller cannot take every slot.
  • Time: 10 seconds for the request header, 30 seconds for the body, and 30 seconds for a client that stops reading the response. On a keep-alive connection the header clock starts again when an answer is flushed, so an idle connection closes 10 seconds after its last answer. The header clock does not apply while a request is in flight. A connection older than 10 minutes is closed after its next answer, which carries Connection: close. A call's deadline comes from request_timeout_secs and the retry count, and a call past it reports ownserp.deadline_exceeded.
  • Size: 1 MiB per request body.

The server checks the Host header against the allowlist on every protected route, rejects a request that carries an Origin header, echoes or assigns x-request-id, and marks every response x-content-type-options: nosniff, cache-control: no-store, x-frame-options: DENY, and referrer-policy: no-referrer. Every bearer token on one server shares that server's ledger, session budget, and cache.

callers.json, beside the token store, can give each bearer token name its own tools list and its own callsPerMinute, callsPerDay, and creditsPerDay limits. A caller sees and calls only its tools, gets ownserp.caller_refused for another, and gets ownserp.caller_rate_limited with Retry-After past a limit. Each server process counts the windows in memory. A broken file stops serve --http at startup, and a running server reads a changed file within about one second. docs/operations.md describes the file.

On SIGTERM, SIGINT, or SIGHUP the server drains: /readyz answers ownserp.shutting_down at once, new connections are still accepted for 3 seconds so a load balancer can move away, then running calls get up to 10 seconds to finish before they are cancelled and recorded. Ledger rows still queued in memory are written before the process exits.

Every tool call writes one audit line to standard error at info level, with target ownserp::audit: the surface (stdio, http, rest, or cli), the caller's token name, the tool, the outcome code, the duration, the argument names but never their values, the request id, and the W3C trace and span ids when the caller sent traceparent. OWNSERP_LOG_FORMAT=json makes each line one JSON object.

Clients reach the server directly at host:port. It speaks plain HTTP and has no TLS, so bearer tokens and results cross the network in clear text. Bind it to loopback when every client runs on the same machine. For clients on other machines, bind it to a private network address that only trusted clients can reach, such as a LAN or VPN interface, and keep the port off the public internet. The allowlist derived from that bind accepts the address itself; add any hostname clients use to OWNSERP_ALLOWED_HOSTS.

OWNSERP_BEARER_TOKEN_FILE=~/.config/ownserp/tokens \
OWNSERP_SESSION_BUDGET_CREDITS=5000 \
OWNSERP_PER_CALL_CREDIT_CEILING=100 \
  ownserp serve --http --bind 10.0.0.5:8777

tools/smoke.sh http://127.0.0.1:8777 checks a running server on this machine; it sends a bearer token over plain HTTP to a loopback address or a private IP literal, such as http://10.0.0.5:8777, and to no other host. docs/operations.md covers deployment, metrics, and shutdown in more detail.

REST API

The HTTP server also answers plain JSON under /v1, behind the same token, Host check, and limits:

  • GET /v1/tools answers {"data": [...], "meta": {"count": N}}: every enabled tool with its REST path, methods, input schema, output schema, and annotations. GET /v1/tools/<tool> returns one of them.
  • GET /v1/capabilities returns the price of each tool, the budget and rate limits, the argument bounds, and the routes. The version is in GET /v1/openapi.json as info.version.
  • GET /v1/skill returns the agent skill as Markdown.
  • GET /v1/openapi.json returns an OpenAPI document for the routes, with an example body for each tool.
  • POST /v1/<tool> runs one tool with a JSON object of arguments as the body, sent with Content-Type: application/json; an empty body means no arguments. status and usage also answer GET, and locations and resolve answer GET with query parameters, such as /v1/locations?q=dhaka.
  • Accept: text/markdown or text/plain returns the one-line summary instead of the JSON result.
curl -sS -H "Authorization: Bearer $TOKEN" -H 'content-type: application/json' \
  -d '{"q":"rust async"}' http://127.0.0.1:8777/v1/search

A success answers 200 with the structuredContent of the tool. A failure answers application/problem+json (RFC 9457) with type, title, status, detail, instance set to urn:uuid:<request id>, and the same code, remedy, and other members a tool error carries; Retry-After is set when a wait helps. The request id is a UUIDv7 in the X-Request-Id header, and a client's own id is kept only when it is a UUID. The status follows the code:

  • 400: ownserp.bad_request. An argument the tool refuses in a POST body answers 422 with an errors array of detail and pointer, and a bad query parameter answers 400 with errors entries of detail and parameter. A wrong method answers 405, an Accept header that allows no JSON or text answers 406, a body that misses its 30 second deadline answers 408, a body above 1 MiB answers 413, and a body without Content-Type: application/json or with a Content-Encoding answers 415, all with this code.
  • 401: ownserp.unauthorized.
  • 403: ownserp.tool_disabled, ownserp.caller_refused, ownserp.origin_refused, ownserp.host_refused.
  • 404: ownserp.tool_not_found, also for a path that matches no route.
  • 429: ownserp.budget_refused, ownserp.rate_limited, ownserp.auth_rate_limited, ownserp.caller_rate_limited, ownserp.update_rate_limited.
  • 500: ownserp.config_error, ownserp.keychain_error, ownserp.internal_error.
  • 502: ownserp.auth_failed, ownserp.credits_exhausted, ownserp.upstream_failed.
  • 503: ownserp.busy, ownserp.shutting_down, ownserp.auth_missing, ownserp.ledger_fault, ownserp.token_store_unreadable, ownserp.cancelled.
  • 504: ownserp.deadline_exceeded.

Security

The server holds one API key, sends queries only to Serper over TLS, and sends no telemetry. The TLS root set is bundled into the binary, so a container without ca-certificates still verifies Serper; platform roots are added when they load. Results are treated as untrusted text. SECURITY.md states the reporting process, and the threat model states the assets, trust boundaries, controls, and residual risks.

Troubleshooting

Each error carries a stable code, a message, a remedy, isRetryable, and, for a network failure, up to three sanitized causes that name a DNS, TLS, or connection problem. An HTTP refusal carries the same object. ownserp doctor is the first step for any setup problem. docs/troubleshooting.md has the longer guide. The codes and their fixes:

  • ownserp.auth_missing. No key is configured, or the OS keychain could not be read; the cause names which. Set SERPER_API_KEY or run ownserp config set-api-key, then restart the server.
  • ownserp.auth_failed. Serper rejected the key. Check it at https://serper.dev/api-keys.
  • ownserp.credits_exhausted. The Serper account is out of credits. Top up at https://serper.dev/dashboard, then call again.
  • ownserp.rate_limited. The upstream rate limit stopped the call. Serper publishes no retry header, and the server does not retry a 429.
  • ownserp.budget_refused. The per-call ceiling or the session budget would be passed. The message names the cause right after budget refused: , and the remedy follows it. For per-call ceiling: , lower num or pick a cheaper tool; a scrape is checked at 10 credits. For held by this process: or held by other processes: , wait for the calls in flight, or the seconds the message names, and call again. For ledger chain spent: , the operator raises session_budget_credits and restarts the server, or runs ownserp audit rotate, which also starts the count again at zero. Abandoned rows count like any other row, and only ownserp audit rotate clears them.
  • ownserp.bad_request. An argument failed validation. The message names the field.
  • ownserp.tool_not_found. The tool is not in this configuration's list. Call tools/list and use only the names it returns.
  • ownserp.tool_disabled. The tool exists but a setting keeps it off. Set the key the message names, such as enable_batch or allowed_tools, and restart the server.
  • ownserp.caller_refused. The caller policy in callers.json does not let this bearer token call the tool. Call only the tools tools/list shows for it, or ask the operator to add the tool.
  • ownserp.caller_rate_limited. This bearer token used up a caller policy window. Wait retryAfterSecs, or ask the operator to raise the limit in callers.json.
  • ownserp.deadline_exceeded. The call passed the server's deadline and may already have been billed, so check usage before you repeat it. Retry with a narrower request, or raise request_timeout_secs.
  • ownserp.config_error. A setting is malformed or not UTF-8, HOME or an XDG_*, APPDATA, or LOCALAPPDATA folder variable is not UTF-8, the profile file is writable by the group or other users or owned by another user, a bearer token is short, has fewer than 10 distinct characters, repeats one block, or holds a run of 8 consecutive characters, the profile sets a removed key, the token store is a link, open to other users, malformed, or shares a name with a static token, serve --http has no usable bearer token while require_token is on (the default), or a server that callers beyond this machine reach (a bind beyond loopback or an outside allowed host) lacks a bearer token or session_budget_credits. ownserp doctor shows each resolved value and its source, even when the setting that failed is the one it cannot resolve.
  • ownserp.keychain_error. The OS keychain is unavailable. Use SERPER_API_KEY on a headless host.
  • ownserp.ledger_fault. The local call ledger or its reservation file could not be read or written, or another process held it too long. Run ownserp audit verify for the state and the next step. A damaged reservation file clears with ownserp audit clear-reservations --yes.
  • ownserp.token_store_unreadable. Only /readyz and /metrics answer it: the token store has not loaded for over 60 seconds, so store tokens are refused while static tokens still work. Run ownserp doctor on the server host, then check the store file's mode, owner, and folder, its JSON, and that no store token shares a name with a static token. Readiness returns within about one second of the fix.
  • ownserp.upstream_failed. Serper or the network failed. Check https://serper.betteruptime.com.
  • ownserp.cancelled. The call was cancelled, by the client or by a server shutdown, and was recorded at its estimate.
  • ownserp.internal_error. An unexpected local failure outside a call's ledger write, such as a listen address that could not be opened or an answer that could not be shaped. Follow the remedy, retry once, then open an issue with the message.
  • ownserp.unauthorized. The bearer token is missing, wrong, expired, or revoked. Send an active token from ownserp token create, or the token part of a static entry, as Authorization: Bearer <token>; ownserp token list shows which store tokens are active.
  • ownserp.auth_rate_limited. Too many wrong tokens came from this address. Send a correct token, which is admitted at once.
  • ownserp.host_refused. The Host header is not in the allowlist. Add it to OWNSERP_ALLOWED_HOSTS and restart the server.
  • ownserp.origin_refused. The request carried an Origin header, as a browser sends. Call from a non-browser client.
  • ownserp.busy. The connection, in-flight, or per-caller limit is full. Retry after one second.
  • ownserp.shutting_down. The server is draining before it stops. Send new requests to another instance.
  • ownserp.update_rate_limited. GitHub declined the release lookup of ownserp update, usually a rate limit. Wait a few minutes and run it again.

Development

This path needs Rust 1.94 or newer, pinned to 1.100.1 in rust-toolchain.toml.

cargo install --path crates/ownserp --locked
tools/verify.sh

tools/verify.sh runs the whole gate locally: shell syntax, ShellCheck, the bats shell tests, shfmt, ruff, formatting, the version stamps, suppression recheck dates, unused dependencies, a secret scan of the tree and of the git history, advisories, dependency policy, clippy with warnings denied, the tests once under the 80 percent line coverage floor, the MSRV build, a semver check of ownserp-core against its last crates.io release, doc tests, and docs. A slow step that passed within 24 hours with nothing it reads changed is skipped, --fresh runs every step again, and --build-limit-gb <n|off> empties build data above that size first. It needs bash 4.4 or later. It stops at once when bash is older, or when cargo, jq 1.6 or later, python3 3.11 or later, shellcheck, shfmt, cargo-audit, cargo-deny, cargo-machete, or gitleaks 8.19.0 or later is missing, and names the install command for this system. It skips a check and says so when bats, ruff, cargo-llvm-cov, cargo-semver-checks, or the Rust toolchain named by rust-version is missing, and it skips the semver check when crates.io cannot be reached, when there is neither a crates.io release nor a v* tag to compare against, or when cargo semver-checks fails with failed to update dependencies, a dependency resolution failure in the tool's scratch project, not an API break. While the manifest version equals the baseline, the semver check passes --release-type major. It runs the tests with cargo-nextest when installed and with cargo test otherwise. --strict or OWNSERP_STRICT_GATE=1 turns any skip into a failure; the release runs that way.

tools/smoke.sh [base-url] probes a running server: /healthz, /startupz, /readyz, /metrics, the REST tool list, usage, status, OpenAPI, capabilities, and skill routes, the MCP handshake, and tools/list. It sends the bare token in OWNSERP_BEARER_TOKEN, such as one that ownserp token create printed, or else the first entry's token from OWNSERP_BEARER_TOKEN_FILE or OWNSERP_BEARER_TOKENS. Plain http is allowed for a loopback host or a private IP literal only. Run it after a deployment.

The release build itself runs in .github/workflows/release.yml on a matrix of native runners when a v* tag is pushed.

The local lifecycle:

  • tools/install-local.sh builds the dist profile from this checkout with cargo auditable, installs it into ~/.local/bin or --dir, removes a Homebrew ownserp formula unless --keep-brew is given, installs the agent skill with ownserp skill install --to auto --if-enabled, runs tools/set-up-machine.sh unless --skip-setup is given, and runs the installed ownserp doctor, as From a checkout describes. It runs on macOS and Linux, refuses Windows, and never publishes, pushes, or starts a hosted pipeline. --gate runs tools/verify.sh first, --check or --dry-run prints the plan and changes nothing, --prune-only and --stale-days <n> control the build cache, and -V names the commit it would build. When doctor fails, for example with no API key, the script says the binary is installed and exits 1.
  • tools/set-up-machine.sh downloads the passage model, writes the shell completions and the manual page, and adds the MCP entry to Claude Code, Codex, and Command Code where it is missing. --binary <path> names the installed copy, and --check prints the steps and changes nothing.
  • tools/reinstall.sh builds and installs the binary into ~/.local/bin: the release profile, or --debug, or --dist. It checks the install folder first, and the new binary must answer --version within 30 seconds before it replaces the old one. --dry-run prints the plan, and --build-limit-gb <n|off> caps the build data.
  • tools/release.sh --prepare sets the next version; --package builds the archives, checksums, SBOM, and bundle, then signs the checksums when the minisign key is present; --tag creates the annotated tag.
  • tools/publish-npm.sh publishes the npm package from the signed release archive, after it checks the minisign signature and the archive hash; tools/npm-auth-setup.sh stores the token that makes it OTP-free.
  • tools/registry-auth.sh refreshes the GitHub, npm, crates.io, MCP Registry, and ghcr sessions from the environment variables already in your shell, so no registry asks for a login during a release.
  • tools/install-hooks.sh points git at the local hooks: a secret scan before each commit and the full gate before each push.
  • RELEASING.md is the release runbook.

Distribution

  • crates.io: ownserp and ownserp-core.
  • npm: @devops-infinity/ownserp.
  • Homebrew tap: devops-infinity/tap.
  • MCP Registry: io.github.devops-infinity/ownserp.
  • GitHub releases: archives for macOS ARM64 and x86_64, Linux x86_64 and ARM64 with glibc, Linux x86_64 and ARM64 with static musl, and Windows x86_64, each with a checksum, plus a shell installer, a PowerShell installer, a Linux MCPB bundle with its .mcpb.sha256 file, the CycloneDX SBOM ownserp-<version>.cdx.json, sha256.sum with its minisign signature sha256.sum.minisig, and ownserp-npm.sha256 for the npm tarball. Every binary is built with cargo auditable, so cargo audit bin reads its dependency list.
  • Container image: ghcr.io/devops-infinity/ownserp, public.
  • Manifests in this repository: server.json, mcpb/manifest.json, and Dockerfile.

Documentation

Support

SUPPORT.md says where to ask. Open an issue at https://github.com/devops-infinity/ownserp/issues for a question, a bug, or a feature request. Report a security problem through the private channel in SECURITY.md, never in an issue.

Contributing

Issues and pull requests are welcome at https://github.com/devops-infinity/ownserp. CONTRIBUTING.md has the workflow. Run tools/verify.sh before opening a pull request; a change lands only when the gate passes. Read RELEASING.md before cutting a release.

Results come from Google through Serper. Downstream users keep the attribution duty Serper's terms place on them.

License

MIT OR Apache-2.0. See LICENSE-MIT and LICENSE-APACHE.

About

OwnSERP, an MCP server for the Serper.dev search API with per-call credit accounting

Topics

Resources

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Contributors

Languages