▶ CARTRIDGE

MCP Server Cartridge

A working TypeScript MCP server your AI agent can add tools to without opening a security hole.

$29 · one-time

Plus sales tax or VAT where applicable, calculated at checkout.

Need more than one kit? The All-Access Bundle gets all 6 paid cartridges (Rules Mega Pack, Game Prototype, Discord Bot, SaaS Starter, Browser Extension, MCP Server) for $79 one-time, instead of $184 bought separately.

A small, complete MCP (Model Context Protocol) server in TypeScript (strict), built on the official MCP TypeScript SDK v2 (@modelcontextprotocol/server 2.4) and set up for AI-assisted coding. It serves the same tools over stdio, for Cursor, Claude Code and Codex, and over Streamable HTTP on 127.0.0.1 with Host and Origin checks and an optional bearer token. Three example tools with zod input schemas show the main patterns: text_stats (pure, structured output), search_notes (read-only, limited to one folder) and create_note (writes, off unless you turn it on, never overwrites), plus a notes:// resource with path checks. 43 Vitest tests run without an AI client, keys or network, including a tools/list contract test, path-traversal tests and a test that starts the built server over stdio. Cursor, Claude Code and AGENTS.md rules cover the SDK v2 API and how to add a tool safely, and docs give the exact config for Cursor, Claude Code and Codex. One-time purchase (sales tax or VAT added at checkout where applicable), instant download.

Requirements: Needs Node.js 22.12+ (24 LTS recommended) and an MCP client such as Cursor, Claude Code, Codex or the MCP Inspector. No accounts or API keys needed. Tested on Linux with Node 24; the client config snippets follow each tool's official docs as of Nov 30, 2026.

What's inside

FileCovers
src/server.tscreateServer(): the one place tools and resources are registered, used by both transports and the tests
src/tools/text_stats (pure, outputSchema + structuredContent), search_notes (read-only, one folder, plain-text search), create_note (only when ALLOW_WRITES=true, creates, never overwrites), error helpers that keep stack traces out of the chat
src/resources/notes.tsnotes://{name} resource template with a list callback; names validated and real paths checked so symlinks can't escape the folder
src/stdio.ts + src/http.tsstdio entry (what clients run) and Streamable HTTP on 127.0.0.1: Host/Origin checks against DNS rebinding, /mcp only, optional bearer token compared in constant time
src/lib/Config from environment variables with zod (secrets never logged), stderr logger that redacts secret-looking fields, safe path resolution, notes and text logic
tests/43 Vitest tests through a real MCP client: tools/list contract, every tool and the resource, schema rejections, traversal and symlink attempts, HTTP Host/Origin/token checks, the built server over stdio, and source guardrails (no stdout writes, no shell, no network in tools)
.cursor/rules/*.mdc4 Cursor rules: MCP workflow (always on), SDK v2 API (and the v1 patterns to avoid), tool safety, transports
CLAUDE.md + AGENTS.mdThe same rules for Claude Code, Codex, OpenCode and other agents
docs/ + examples/clients/SETUP.md, CLIENTS.md (Cursor .cursor/mcp.json, Claude Code claude mcp add and .mcp.json, Codex config.toml), SECURITY.md, AGENT-PLAYBOOK.md (copy-paste prompts), plus ready-to-copy config files
README.md + LICENSE.mdQuick start, scripts, and the license: use it for any number of your own MCP servers, free or commercial

Peek inside

.cursor/rules/20-tool-safety.mdc · One of the 4 Cursor rules, shown in full.

---
description: Safety rules for adding or changing MCP tools and resources (validation, secrets, least privilege, no shell, no network by default)
globs: src/tools/**/*.ts, src/resources/**/*.ts, src/lib/**/*.ts, src/server.ts
alwaysApply: false
---
# Adding a tool safely

The model calling your tool may be steered by untrusted text (a web page, an issue, an email). Treat every argument and URI variable as hostile.

1. **Validate inputs with zod, with limits.** Lengths (`.max()`), ranges, `.int()`, enums or regexes for names. Never accept "any object". Don't build regexes from user input (ReDoS); use plain substring matching.
2. **No secrets in logs, results or errors.** Secrets come from env via `src/lib/config.ts` only, never from tool arguments. Log with `log()` (stderr, redacts secret-looking keys); log names, counts and sizes, not arguments or file contents. Never return a token, env dump or stack trace to the model.
3. **Least privilege.** Prefer read-only tools. A tool that writes, sends or deletes must be off unless an env flag enables it (see `ALLOW_WRITES` in `server.ts`), must do the narrowest thing (create, not overwrite; one folder, not the disk), and must carry `annotations` (`readOnlyHint: false`, `destructiveHint` when it deletes or overwrites).
4. **Never shell out with user input.** No `child_process`, `exec`, `eval`, `new Function`, and no building commands, SQL or file paths by string concatenation of arguments. Use parameterized APIs. `tests/source-guard.test.ts` enforces the shell/eval part.
5. **Paths stay inside a root.** Validate the name, join with a fixed root, `realpath()` it and check it's still inside (see `src/lib/paths.ts`). No absolute paths or `..` from clients.
6. **No network by default.** If a tool must call out: host allowlist from env, `https:` only, timeout, response size cap, `openWorldHint: true`, and treat the response as untrusted. Follow docs/SECURITY.md and say so in your report.
7. **Bounded work.** Cap result counts, file sizes and loops so one call can't hang the server or flood the context.
8. **Errors.** Expected problems return `isError: true` with a clear message; unexpected ones go through `guarded()` so details stay in the log.
9. **Tests.** Every new tool gets: a happy-path call through the client, a schema rejection, and a test for each safety rule it relies on (traversal, size limit, flag off = tool absent).

Stripe emails your receipt. Lost your download link? Email us with the receipt and we'll sort it out. Questions: support@agentcartridge.com