typescript

Coding rules for building TypeScript MCP servers with test-driven development, meaning tests are written before the code they check.

In plain words
What is it for?
Use it when writing or reviewing TypeScript MCP server code, organizing files, adding Jest tests, and maintaining test coverage.
Why use it?
It gives a project a consistent structure, naming style, type-safety practices, and testing process.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/zenjoy/realtime-register-mcp/typescript
Clone the repo
git clone --depth 1 https://github.com/zenjoy/realtime-register-mcp

Made for: Cursor.

Per session 630 This file is loaded in full into every session.
When invoked 630 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00630 $0.00630
Opus 5 $0.00315 $0.00315
Sonnet 5 $0.00126 $0.00126
Haiku 4.5 $0.00063 $0.00063

Measured 2d ago against content hash c8a08609f48d, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

typescript scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/typescript.mdc · 77 lines

How it starts

The opening of the file, as written. The whole thing — 77 lines — stays where its author put it; the contents beside it link to each section on GitHub.

You are an expert in building MCP servers in TypeScript using a test-driven design methodology.

TypeScript Guidelines

  • Use TypeScript for all source files. Enable strict mode in tsconfig.json for full type safety.
  • Prefer interfaces over types for defining object shapes.
  • Avoid any; instead, use unknown or appropriate custom types.
  • Use PascalCase for types/interfaces, camelCase for variables/functions.
  • Use readonly modifiers where applicable to ensure immutability.

Project Structure and Code Style

  • Organize by feature-based folders (e.g., src/modules/user, src/core, src/utils).
  • Use function keyword for pure functions, but prefer arrow functions. Avoid unnecessary classes.
  • Structure files consistently: implementation first, then exports, then helpers, then types.
  • Favor named exports for maintainability.
  • Use lower-case dash-separated folder names.

Testing and TDD Practices

  • Write all code in response to failing tests.
  • Use Jest for all unit and integration testing.
  • Use .test.ts suffix for test files and colocate them with the code being tested.
  • Ensure 100% test coverage; enforce via Jest configuration.
  • Use mocks and spies to isolate units during testing.
  • Write tests for edge cases, invalid inputs, and error states.
  • Maintain clear separation between test setup, execution, and assertions.

Dependency Management

  • Use Yarn as the package manager.
  • Use yarn workspaces if part of a monorepo.
  • Lock dependency versions with yarn.lock.
  • Use scripts in package.json for common tasks like yarn test, yarn lint, and yarn build.

Linting and Formatting

  • Use ESLint with the TypeScript plugin for consistent style enforcement.
  • Use Prettier for code formatting.
  • Configure linting to run on pre-commit using Husky or similar.

Error Handling and Logging

  • Always use typed error objects.
  • Favor early returns for error conditions.
  • Log meaningful errors at the point of failure.
  • Avoid using try-catch for expected conditions—use validation and guards.

Read the full file on GitHub · 77 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 77 lines · 630 tokens per session scan A c8a08609f48d

Subscribe to this mod's changes

typescript is a cursor rule published in the GitHub repository zenjoy/realtime-register-mcp (1 stars, last pushed 8mo ago), licensed MIT. It adds 630 tokens to every session, about $0.0032 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.