← Back to Margin

Margin MCP Server

Margin exposes your documents, annotations, corrections, writing rules, and voice signals through a Model Context Protocol server. 20+ tools, 4 resources, and 3 prompts — available to any MCP-compatible AI client.

Quick Setup

Claude Desktop

{
  "mcpServers": {
    "margin": {
      "command": "/Applications/Margin.app/Contents/Resources/mcp-server",
      "args": ["--stdio"]
    }
  }
}

Claude Code

{
  "mcpServers": {
    "margin": {
      "command": "/Applications/Margin.app/Contents/Resources/mcp-server",
      "args": ["--stdio"]
    }
  }
}

Add to ~/Library/Application Support/Claude/claude_desktop_config.json for Claude Desktop, or .claude/settings.json / ~/.claude/settings.json for Claude Code.

When connected, Margin's title bar shows an MCP badge.

Documents

ToolDescriptionKey Parameters
margin_list_documentsList recent documents ordered by last openedlimit (default 20, max 100)
margin_get_documentGet full metadata for a single documentdocument_id (required)
margin_read_documentRead the file content of a documentdocument_id (required)
margin_search_documentsFull-text search with BM25 ranking and frecency boostingquery (required), limit (default 20, max 50)

Annotations

ToolDescriptionKey Parameters
margin_get_annotationsGet all highlights and margin notes for a document, grouped by highlightdocument_id (required)
margin_create_highlightCreate a new text highlight at specific positionsdocument_id, color (yellow/green/blue/pink/purple/orange), text_content, from_pos, to_pos (all required)
margin_highlight_by_textHighlight by exact text match — no position math neededdocument_id, text_to_highlight, color (required); note (optional)
margin_update_highlight_colorChange the color of an existing highlighthighlight_id, color (required)
margin_create_margin_noteAttach a note to an existing highlighthighlight_id, content (required)
margin_update_margin_noteUpdate the content of an existing margin notenote_id, content (required)
margin_delete_highlightDelete a highlight and its attached notes (cascading)highlight_id (required)
margin_delete_margin_noteDelete a single margin note without deleting its parent highlightnote_id (required)

Corrections

ToolDescriptionKey Parameters
margin_get_correctionsGet writing corrections with contextdocument_id (optional filter), limit (default 200, max 2000)
margin_get_corrections_summaryAggregate statistics: total count, by writing type, by document(none)
margin_create_correctionFind text, create highlight, and record correction with notesdocument_id, original_text, notes[] (required); writing_type, color (optional)
margin_delete_correctionDelete a correction and its associated highlighthighlight_id (required)
margin_update_correction_writing_typeUpdate the writing type of a correctionhighlight_id, writing_type (required)
margin_set_correction_polaritySet voice signal polarity: positive (emulate) or corrective (avoid)highlight_id, polarity (positive/corrective) (required)
margin_get_voice_signalsGet corrections tagged with voice signal polaritypolarity (optional: positive/corrective), limit (default 500, max 2000)
Valid writing types:generalemailprdblogcover-letterresumeslackpitchoutreach

Writing Rules

ToolDescriptionKey Parameters
margin_get_writing_rulesGet writing rules from the databasewriting_type (optional filter)
margin_get_writing_rules_markdownGet rules formatted as markdown, grouped by type — suitable for promptswriting_type (optional filter)
margin_update_writing_ruleUpdate fields of an existing ruleid (required); rule_text, severity, writing_type, example_before, example_after, notes, why, when_to_apply (optional)
margin_delete_writing_ruleDelete a writing rule by IDid (required)

Export

ToolDescriptionKey Parameters
margin_wait_for_exportBlock until user exports annotations from Margin. Returns formatted markdown.timeout_seconds (default 300, max 600)

This tool uses long-polling. Call it, then ask the user to press ⌘⇧E in Margin. The tool returns when the export arrives or the timeout elapses.

Resources

URIDescription
margin://documentsList of 20 most recent documents
margin://writing-rulesWriting rules formatted as markdown
margin://corrections/summaryAggregate statistics about writing corrections
margin://latest-exportMost recent annotation export, updated in real-time via notifications

Prompts

Three built-in prompts that structure common workflows.

PromptDescriptionArguments
review-writingReview a document against writing rulesdocument_id (required)
analyze-correctionsAnalyze correction patterns across documentswriting_type (optional)
export-and-reviewWait for export, then analyze annotationstimeout_seconds (optional)

Writing Guard Hook

When writing rules are exported, Margin auto-generates a Claude Code hook at ~/.claude/hooks/margin-writing-guard.sh. The hook runs on every Edit and Write tool call, checking for kill words defined in your rules. If a banned word appears, the hook blocks the edit with an explanation.

# Auto-generated by Margin — do not edit manually
# Regenerated on every rules export

KILL_WORDS=("leverage" "utilize" "furthermore" "moreover" "additionally")

for word in "${KILL_WORDS[@]}"; do
  if grep -qi "$word" "$1"; then
    echo "BLOCKED: '$word' violates your writing rules"
    exit 1
  fi
done

The hook is regenerated each time you export rules from Margin. To customize kill words, add corrections in Margin — the hook updates automatically.