JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 48
  • Score
    100M100P100Q83252F
  • License MIT

Risk gate MCP for trading — caps, wash-sale, TLH.

Package Exports

  • traderkit
  • traderkit/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (traderkit) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

traderkit

Risk-gate MCP server for AI-assisted trading. Enforces position caps, wash-sale rules, and forbidden-structure checks before any order hits your broker.

Built for Claude Code + SnapTrade. Works with any MCP client.

Install

npx -y traderkit

Or globally:

npm install -g traderkit

What it does

Ten MCP tools that sit between your AI assistant and your broker:

Tool Purpose
check_trade Gate a proposed trade against caps + wash-sale rules
check_wash_sale Standalone ±30-day wash-sale window check
scan_tlh Find tax-loss harvesting candidates (wash-sale-clean)
check_concentration Portfolio concentration analysis with HEADROOM/NEAR-CAP/AT-CAP/OVER-CAP labels + HHI
regime_gate Market regime sizing gate — adjusts notional, blocks actions by tier
propose_trade Assemble a sized trade proposal with concentration headroom and regime adjustment
track_tax Running STCG/LTCG tax exposure from realized trades with per-trade breakdown
trigger_check Detect events: NAV moves, regime shifts, concentration breaches
list_profiles List configured trading profiles
set_profile Set the active profile for the session

check_trade

The primary gate. Validates:

  • Order size cap — rejects if notional_usd exceeds max_order_notional
  • Concentration cap — rejects if post-trade single-name exposure exceeds max_single_name_pct
  • Forbidden tools — blocks specific broker tools (e.g., margin tools)
  • Forbidden leg shapes — blocks option structures (e.g., naked_put, naked_call)
  • Wash-sale check — flags if same ticker was sold at a loss within ±30 days (same tax_entity)

Returns { pass: boolean, reasons: string[], warnings: string[] }.

check_wash_sale

Standalone wash-sale check. Pulls last 30 days of activity from a sibling snaptrade-mcp-ts server. Pools all accounts under the same tax_entity (e.g., all personal accounts share one wash-sale window; an LLC has its own).

Graceful degradation: if snaptrade-read is unavailable, returns flagged: false with a warning rather than blocking.

scan_tlh

Scans your positions for tax-loss harvesting opportunities. Filters to positions with unrealized loss above a threshold (default $500), then excludes any that would trigger a wash sale. Returns candidates sorted by loss size (largest first).

Requires positions data as input (from snaptrade_get_positions or equivalent).

check_concentration

Analyzes portfolio concentration against profile caps. Returns every position labeled:

  • HEADROOM — well below cap
  • AT-CAP — 75-90% of cap
  • NEAR-CAP — 90-100% of cap
  • OVER-CAP — exceeds cap

Also returns the HHI (Herfindahl-Hirschman Index) as a single-number diversification score, and the top 5 positions.

regime_gate

Checks if a trade should proceed under the current market regime:

Tier Size multiplier Max DTE Blocked actions
CLEAR 1.0x unlimited none
CAUTION 0.75x 45 DTE none
DEFENSIVE 0.5x 30 DTE BUY, BUY_TO_OPEN
HALT 0.25x 14 DTE BUY, BUY_TO_OPEN, SELL_TO_OPEN

Returns adjusted notional, preferred structures for the tier, and whether the proposed structure aligns.

propose_trade

End-to-end trade proposal builder. Takes a ticker, price, portfolio context, and regime tier. Produces a fully sized proposal with:

  • Headroom-based sizing(cap% - current%) × 0.5 × NAV × regime_multiplier
  • Cap enforcement — capped at profile's max_order_notional
  • Regime blocking — rejects BUY in DEFENSIVE/HALT
  • Concentration check — rejects adds when already OVER-CAP
  • Sizing trace — human-readable formula for audit

Optional: attach thesis_ref and signal_summary for proposal context.

track_tax

Computes running tax exposure from an array of realized trades:

  • Separates STCG (<365 days) from LTCG (≥365 days)
  • Computes reserves at configurable rates (defaults: STCG 35.8%, LTCG 18.8%)
  • Tracks gains and losses separately per bucket
  • Flags wash-sale-adjusted trades
  • Returns per-trade breakdown sorted by date

trigger_check

Event detector for portfolio monitoring. Checks three conditions:

  • NAV_MOVE — triggers on ±2% NAV change (configurable). CRITICAL at ±4%.
  • REGIME_SHIFT — fires when regime tier changes. CRITICAL on deterioration, INFO on improvement.
  • CONCENTRATION_BREACH — flags positions exceeding the cap. CRITICAL when 10pp+ over.

Returns events sorted by severity (CRITICAL → WARNING → INFO).

Setup

1. Create profiles

Profiles live in ~/.traderkit/profiles/ as markdown files with YAML frontmatter:

---
name: personal
broker: snaptrade
account_id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
tax_entity: personal
caps:
  max_order_notional: 10000
  max_single_name_pct: 25
  forbidden_tools: []
  forbidden_leg_shapes: [naked_put, naked_call]
---

Get your account_id from snaptrade_list_accounts.

2. Register in Claude Code

Add to .claude/settings.json:

{
  "mcpServers": {
    "trade-guard": { "command": "npx", "args": ["-y", "traderkit"] }
  }
}

3. Wire the PreToolUse hook

The companion PreToolUse hook calls check_trade automatically before any destructive broker tool fires. Add to .claude/settings.json:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "mcp__snaptrade-trade__equity_force_place|mcp__snaptrade-trade__mleg_place",
        "command": "node ~/.traderkit/scripts/pre-tool-use.js"
      }
    ]
  }
}

4. Verify

traderkit  # starts MCP server on stdio

In Claude Code: ask "list profiles" to confirm the server is connected.

Environment variables

Variable Required Description
TRADERKIT_ROOT No Config root (default: ~/.traderkit)
TRADERKIT_FAIL_OPEN No Set true to allow trades when server is unreachable (default: fail closed)
SNAPTRADE_CONSUMER_KEY For wash-sale SnapTrade credentials for activity lookups
SNAPTRADE_USER_SECRET For wash-sale
SNAPTRADE_USER_ID For wash-sale
SNAPTRADE_CLIENT_ID For wash-sale
SNAPTRADE_READ_COMMAND For wash-sale Command to spawn snaptrade-mcp-ts (e.g., npx)
SNAPTRADE_READ_ARGS For wash-sale Args for the command (e.g., -y snaptrade-mcp-ts)

How it works

Claude Code ──PreToolUse hook──► traderkit MCP
                                    │
                                    ├─ caps check (profile YAML)
                                    ├─ wash-sale check (snaptrade-mcp-ts)
                                    │
                                    ▼
                              pass/block decision
  • Fail-closed by default. If traderkit can't evaluate a trade, it blocks.
  • Credential redaction. All tool responses are scrubbed — any env secret substring (8+ chars) is replaced with <REDACTED>.
  • Tax-entity pooling. Wash-sale checks span all accounts with the same tax_entity. Personal brokerage + IRA = one pool. LLC = separate pool.

Supported brokers

Works with any broker connected via SnapTrade:

  • Fidelity (read + write)
  • E-Trade (read + write)
  • IBKR (read + write)
  • Schwab (read + write)
  • Robinhood (read-only)
  • TradeStation (via separate TradeStation MCP)

Full setup

For the complete trading terminal setup (vault templates, profiles, scripts, docs), see the traderkit repo.

License

MIT