underwritten-mcp
v0.0.6
Published
`underwritten-mcp` is the published MCP server package for [Underwritten](https://underwritten.app). It runs as a local process, speaks MCP over `stdio`, exposes a localhost HTTP bridge for the browser app, and routes tool calls into the active Underwritt
Downloads
51
Readme
underwritten-mcp
underwritten-mcp is the published MCP server package for Underwritten. It runs as a local process, speaks MCP over stdio, exposes a localhost HTTP bridge for the browser app, and routes tool calls into the active Underwritten editor session.
The package exists because Underwritten itself is a browser app. External MCP clients need a local companion that can:
- start from a normal MCP command
- bind a localhost API the browser can reach
- pair with a live Underwritten tab
- operate on the real editor and workspace state already open in the app
Install
You can run the published package directly:
npx -y underwritten-mcpThe intended end-user MCP configuration is:
{
"mcpServers": {
"underwritten": {
"command": "npx",
"args": ["-y", "underwritten-mcp"]
}
}
}After the process starts:
underwritten-mcpbinds a free localhost port on127.0.0.1.- The Underwritten web app discovers the bridge with
GET /discover. - The browser pairs with
POST /pair. - The active tab syncs session state and executes queued actions.
What It Does
- Runs an MCP server over
stdio - Exposes a localhost bridge for the browser app
- Routes file and document operations to the most relevant live Underwritten tab
- Shares browser-safe contract types through
underwritten-mcp/contract - Keeps the browser app as the source of truth for workspace and editor state
This is the published bridge package. The website app is not the MCP server.
Tool Surface
Workspace tools:
get_workspace_statuslist_filesread_fileopen_filecreate_filecreate_foldermove_pathdelete_pathsave_document
Document tools:
get_current_documentreplace_current_documentapply_markdown_edits
apply_markdown_edits works on raw markdown text with literal anchored matching. Targets use a literal text value and optional 1-based occurrence. Edits apply sequentially against the updated buffer, and ambiguous or missing matches fail explicitly.
Bridge Behavior
The bridge only listens on 127.0.0.1 and uses a reserved port range of 45261-45271 by default. The browser app pairs first, receives a bearer token, and then uses that token for sync and status requests.
Endpoints:
GET /discoverPOST /pairPOST /session/syncPOST /session/disconnectGET /status
The browser polls every 1000ms, and sessions expire after 15000ms without a fresh heartbeat.
Session Routing
Tool calls target one live browser session at a time. Routing is deterministic:
- Keep only live, non-disconnected sessions.
- Prefer the most recent
lastFocusAt. - Break ties with the most recent
lastHeartbeatAt. - Break any remaining tie lexically by
sessionId.
If no live session is available, the bridge returns an explicit error instead of guessing.
Package Exports
Default package exports:
startUnderwrittenBridgeresolveBridgePortUnderwrittenBridgeServiceUnderwrittenBridgeError
Contract exports are available from underwritten-mcp/contract, including:
underwrittenBridgePortRangeunderwrittenBridgeApiVersion- markdown edit types and helpers
- session, status, and action types shared with the browser app
Example:
import { startUnderwrittenBridge } from "underwritten-mcp";
import { underwrittenBridgePortRange } from "underwritten-mcp/contract";
const bridge = await startUnderwrittenBridge({
connectStdio: true,
portRange: underwrittenBridgePortRange,
});Local Development In This Monorepo
Install dependencies:
vp installRun the website:
vp run website#devRun the bridge from source in another terminal:
vp dlx tsx apps/mcp/src/cli.tsBuild the package:
vp run mcp#buildIf you want to run the built entrypoint directly:
node apps/mcp/dist/cli.jsValidation
Run repo checks:
vp check
vp testRun the package build:
vp run mcp#buildMonorepo Context
apps/mcp: publishable MCP bridge packageapps/mcp/src/contract.ts: shared protocol types and markdown edit helpersapps/website: Underwritten web app that discovers, pairs with, and drives the bridge
License
MIT
