|
| 1 | +# substack-mcp |
| 2 | + |
| 3 | +MCP server for Substack — read posts, manage drafts, create notes. Cannot publish or delete posts by design; notes (short-form) publish immediately since Substack has no note-draft state. |
| 4 | + |
| 5 | +## Architecture |
| 6 | +- `src/index.ts` — MCP server bootstrap and entry point |
| 7 | +- `src/server.ts` — Tool registration, request handlers, Zod schema generation |
| 8 | +- `src/api/client.ts` — HTTP client for Substack API (session cookie auth) |
| 9 | +- `src/api/types.ts` — TypeScript interfaces for API responses |
| 10 | +- `src/utils/errors.ts` — Error handling utilities |
| 11 | +- `src/utils/markdown-to-prosemirror.ts` — Markdown to ProseMirror AST converter (Substack editor format) |
| 12 | +- `src/__tests__/` — Vitest tests for client, errors, and markdown conversion |
| 13 | + |
| 14 | +## Key constraints |
| 15 | +- Posts are read/draft only — no publish or delete capabilities by design |
| 16 | +- Notes publish immediately via `create_note` / `create_note_with_link` — Substack has no note-draft state, so there is no preview step |
| 17 | +- Auth sends both `connect.sid` and `substack.sid` cookies set to the same session token (custom domains use `connect.sid`, substack.com uses `substack.sid`) |
| 18 | +- Markdown must be converted to ProseMirror format for Substack's editor |
| 19 | + |
| 20 | +## Development |
| 21 | +```bash |
| 22 | +npm ci |
| 23 | +npm run lint # tsc --noEmit (type-check) |
| 24 | +npm run build # tsc (outputs to dist/) |
| 25 | +npm test # vitest run |
| 26 | +``` |
| 27 | + |
| 28 | +## Testing |
| 29 | +3 test suites: |
| 30 | +- `client.test.ts` — API client auth validation |
| 31 | +- `errors.test.ts` — Error handling and wrapping |
| 32 | +- `markdown-to-prosemirror.test.ts` — Markdown to ProseMirror AST conversion |
| 33 | + |
| 34 | +## Agent workflow |
| 35 | +- Always work on a branch. Never push directly to main. |
| 36 | +- Create PRs targeting main. CI must pass (build + test on Node 20 and 22). `npm run build` runs `tsc` and fails on type errors. |
| 37 | +- Keep changes focused — one feature or fix per PR. |
| 38 | +- Run `npm run lint` (fast no-emit type-check) and `npm test` locally before pushing. |
0 commit comments