Minimal template for building Model Context Protocol (MCP) servers with Bun and TypeScript.
bun install
bun run dev # Development
bun run start # Production{
"mcpServers": {
"my-mcp-server": {
"command": "bun",
"args": ["/path/to/your/project/index.ts"],
"cwd": "/path/to/your/project"
}
}
}├── index.ts # Server entry point
├── schema.ts # State schema (Zod)
├── config.ts # Configuration
├── state.yaml # State file
├── tools/ # Tool handlers
└── utils/ # State & logging utilities
- Schema-based state validation (Zod)
- YAML state persistence
- Tool usage logging
- Deep merge for state updates
- Update
schema.tsto match your state structure - State is automatically validated on read/write
- Create
tools/your-tool.tsfollowingexample-tool.tspattern - Register in
index.ts:registerYourTool(server);
import { getState, updateState, saveState } from "./utils/state.ts";
import { type State } from "./schema.ts";
const state = await getState();
await updateState({ version: "1.0.1" }); // Deep merge
await saveState(newState); // Full replacementimport { log } from "./utils/logger.ts";
await log("info", "tool_name", request, response);See TEMPLATE.md for detailed examples.