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

@cubicecho/mcp-daemon

v0.1.1

Published

One bin, three run modes for an MCP app: serve over HTTP, run as a local daemon, or act as a stdio MCP server that bridges to the daemon.

Downloads

463

Readme

@cubicecho/mcp-daemon

One bin, three run modes for an MCP app that keeps its own store (a database, a data dir):

| Command | Does | | --- | --- | | (none) or stdio | An MCP server on stdin/stdout that forwards to the local daemon, starting it if none runs | | serve | The app's HTTP server in the foreground (--host, --port) | | daemon start / stop / status | The same server, detached, on 127.0.0.1 and a free port |

Every stdio session, in every MCP client, shares one daemon, so only one process ever opens the store. That makes an in-process database such as PGlite or SQLite safe behind a stdio MCP server, which would otherwise be started once per session.

MCP client A ─stdio─► bridge ─┐
MCP client B ─stdio─► bridge ─┼─ HTTP /mcp ─► daemon (the app's server) ─► the store
MCP client C ─stdio─► bridge ─┘

Using it

The app's bin hands runCli its version, its own flags, where to keep the daemon's files, and how to start its HTTP server:

#!/usr/bin/env node
import { defaultStateDir, runCli } from '@cubicecho/mcp-daemon';

const code = await runCli({
  name: 'my-app',
  version: VERSION,
  options: { 'data-dir': { type: 'string' } },
  stateDir: (values) => defaultStateDir('my-app', dataDirOf(values)),
  serve: ({ mode, host, port, bridgeToken }, values) => startServer({ dataDir: dataDirOf(values), host, port, bridgeToken }),
});
process.exit(code);

serve must:

  • listen on host and port when given (the daemon passes 127.0.0.1 and 0), and resolve with the port it took and a close();
  • accept Authorization: Bearer <bridgeToken> on its MCP endpoint, beside whatever auth it already has.

An MCP client config then runs the bin with no command:

{ "mcpServers": { "my-app": { "command": "my-app", "args": ["--data-dir", "/path/to/data"] } } }

--url <endpoint> --key <key> makes the bridge forward to a server elsewhere instead, starting nothing.

How it works

  • A lock per state dir. serve and the daemon both take daemon.lock (a file holding the pid, hard-linked into place) before starting the app, so a foreground serve and a daemon cannot both open the store. A dead owner's lock is taken over, by one process at a time.
  • A state file. Once the server listens, daemon.json records its pid, URL, version, mode and a random bridge token. It is written owner-only (0600) in an owner-only dir.
  • Finding or starting the daemon. A bridge reads the state file and checks the process is alive and its server answers HTTP (any status). If not, it spawns daemon run detached, its output appended to daemon.log, and waits for the state file. Two bridges starting at once both spawn; the lock lets one run and the other exit. An owner that is shutting down is waited for, and a start that fails is reported at once with the end of the log.
  • Upgrades. A new session whose version differs from a running daemon's stops it and starts its own. Sessions already running move to the new daemon and never replace one. A foreground serve is used as it is.
  • The bridge passes JSON-RPC messages unchanged between the SDK's stdio server transport and its streamable HTTP client transport, setting the negotiated protocol version on the HTTP side. Server-to-client notifications reach the client through the HTTP side's SSE stream when the app serves live sessions.
  • Reconnecting. When the daemon crashes, stops or is replaced, the bridge connects to the next one and repeats the client's handshake, resource subscriptions and log level, then sends list_changed and resource updates so the client fetches again. It looks at the state file every second, and an idle bridge starts nothing: after daemon stop, the next request does. Requests under way are sent again once, except a tool call the daemon may have taken: the client gets an error, because the call may have had its effect. With --url, a bridge reconnects when a send fails.

defaultStateDir(app, key) puts the state dir under $XDG_STATE_HOME (else ~/.local/state), named by a hash of the key. Keep it out of the data dir: that may be a network share, where a pid in a lock file means nothing.

The timeouts and paths are in DAEMON_DEFAULTS; override any of them with settings.

Not yet

  • The daemon runs until daemon stop; it does not exit when idle.
  • With --url, a server lost while a request is under way is not noticed until the next send.
  • After a crash, whichever session sends first starts its own version of the daemon, which may be the older one.
  • Windows is untested (detached spawn and signals differ).