npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

shack-semantic-cache

v0.1.0

Published

MCP server that caches tool-call results in a local SQLite database, using argument canonicalization so semantically equivalent inputs collide into the same cache entry.

Downloads

14

Readme

shack-semantic-cache (TypeScript)

An MCP server that caches tool-call results in a local SQLite database, using argument canonicalization so semantically equivalent inputs always collide into the same cache entry.

Speaks JSON-RPC 2.0 over stdio: STDOUT carries only protocol messages; all diagnostic logs go to STDERR.

What it does

  • Stores tool results keyed by (tool_name, canonical_args) in a local SQLite file.
  • Canonicalizes arguments before keying: object keys are sorted recursively, filesystem-path-like strings are normalized (./src/x == src/x, a//b == a/b), and whitespace is collapsed — so equivalent inputs always collide.
  • URL strings (containing ://) are never path-normalized.
  • Optionally computes float embeddings via an external HTTP endpoint and performs cosine-similarity lookup when an exact key is not found.
  • Supports per-entry TTL expiry; expired entries are invisible to lookups.

MCP tools

| Tool | Required arguments | Optional arguments | Description | |------|-------------------|-------------------|-------------| | cache_put | tool_name (string), arguments (object), result (any) | ttl_secs (integer) | Store a tool result in the cache. Arguments are canonicalized before storage. | | cache_lookup | tool_name (string), arguments (object) | — | Look up a cached result. Returns { "hit": true/false, "match_type": "exact"/"similarity", "result": ... }. | | cache_stats | — | — | Return cache statistics: active entry count, total hits, total misses. | | cache_clear | — | tool_name (string) | Delete all cache entries, or only entries for the named tool. |

Usage example

The server reads newline-delimited JSON-RPC 2.0 from stdin and writes responses to stdout. A minimal interaction storing and retrieving a result:

// Request: store a result
{"jsonrpc":"2.0","method":"tools/call","params":{"name":"cache_put","arguments":{"tool_name":"read_file","arguments":{"path":"src/main.rs"},"result":{"lines":100}}},"id":1}

// Response
{"jsonrpc":"2.0","result":{"content":[{"type":"text","text":"stored"}]},"id":1}

// Request: look it up (path variant "./src/main.rs" normalizes to the same key)
{"jsonrpc":"2.0","method":"tools/call","params":{"name":"cache_lookup","arguments":{"tool_name":"read_file","arguments":{"path":"./src/main.rs"}}},"id":2}

// Response — cache hit
{"jsonrpc":"2.0","result":{"content":[{"type":"text","text":"{\"hit\":true,\"match_type\":\"exact\",\"result\":{\"lines\":100}}"}]},"id":2}

Install and build

npm install
npm run build

Run

# Minimal — uses shack-cache.db in the current directory
node dist/main.js

# Or via the bin entry
npx shack-semantic-cache

# Explicit database path
node dist/main.js --db /path/to/cache.db

# With optional embedding similarity
node dist/main.js --db /path/to/cache.db \
    --embed-url http://localhost:11434/api/embeddings \
    --embed-model nomic-embed-text \
    --embed-threshold 0.95

CLI flags

| Flag | Env var | Default | Description | |------|---------|---------|-------------| | --db | SHACK_CACHE_DB | shack-cache.db | Path to the SQLite database file. | | --embed-url | SHACK_EMBED_URL | (absent) | HTTP endpoint for embeddings; enables similarity lookup when set. | | --embed-model | SHACK_EMBED_MODEL | nomic-embed-text | Model name passed to the embeddings endpoint. | | --embed-threshold | — | 0.95 | Cosine similarity threshold for embedding-based lookup. |

Tests

npm test

Covers canonicalization (key sorting, path normalization, whitespace collapsing, URL exclusion), TTL expiry (past, future, null), cache put/lookup/clear/count operations, embedding row filtering, cosine-similarity helpers, and similarity-match selection including invalid-embedding resilience.