@heuresis/mcp 1.0.0-rc.6 → 1.0.0-rc.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,152 +1,148 @@
1
- # @heuresis/mcp
2
-
3
- A Model Context Protocol (MCP) server that turns the user's Heuresis
4
- workspace into a thinking substrate any MCP-capable agent (Claude
5
- Desktop, Claude Code, Cursor, Windsurf, custom agents) can read and
6
- write the webapp and the MCP become two front-ends to one cloud
7
- workspace. The MCP logs into the user's Heuresis account, talks to the
8
- same Supabase project the webapp talks to, and respects the same RLS.
9
-
10
- ## Install
11
-
12
- ```bash
13
- npm install -g @heuresis/mcp
14
- # or run on demand without installing:
15
- npx -y @heuresis/mcp@latest
16
- ```
17
-
18
- > Not yet published. While in alpha you can run it locally:
19
- >
20
- > ```bash
21
- > cd mcp-server
22
- > npm install
23
- > npm run build
24
- > node dist/index.js --help
25
- > ```
26
-
27
- ## Quickstart
28
-
29
- ### 1. Link this machine to your Heuresis account
30
-
31
- ```bash
32
- npx @heuresis/mcp login
33
- ```
34
-
35
- The CLI prints a short device code (`XXXX-XXXX`) and a URL. Open the URL in your browser, sign into Heuresis if you aren't already, paste the code, and confirm the device. The CLI polls in the background and writes your credentials to `~/.heuresis/credentials.json` (chmod 600 on POSIX) the moment you confirm. Subsequent runs of the MCP are silent.
36
-
37
- To unlink a machine, run `npx @heuresis/mcp logout` locally, or open Settings ▸ Connected devices in the webapp to revoke remotely.
38
-
39
- `npx @heuresis/mcp whoami` confirms which account a machine is currently linked to.
40
-
41
- ### 2. Point your MCP client at it
42
-
43
- **Claude Desktop** — edit `~/Library/Application Support/Claude/claude_desktop_config.json`
44
- on macOS, or `%APPDATA%/Claude/claude_desktop_config.json` on Windows:
45
-
46
- ```json
47
- {
48
- "mcpServers": {
49
- "heuresis": { "command": "npx", "args": ["-y", "@heuresis/mcp"] }
50
- }
51
- }
52
- ```
53
-
54
- **Claude Code / Cursor / Windsurf** — drop a `.mcp.json` in the
55
- workspace root:
56
-
57
- ```json
58
- {
59
- "mcpServers": {
60
- "heuresis": { "command": "npx", "args": ["-y", "@heuresis/mcp"] }
61
- }
62
- }
63
- ```
64
-
65
- Restart the client. The Heuresis tools appear in the tool menu.
66
-
67
- ### 3. Optional CLI subcommands
68
-
69
- ```bash
70
- npx @heuresis/mcp whoami # show the linked account + device
71
- npx @heuresis/mcp logout # delete the credentials file
72
- npx @heuresis/mcp --help # all options
73
- npx @heuresis/mcp --no-realtime # boot once with live sync turned off (persisted)
74
- npx @heuresis/mcp --realtime # re-enable live sync
75
- ```
76
-
77
- ## Live sync
78
-
79
- When the MCP boots in cloud mode it subscribes to your workspace over
80
- Supabase Realtime and notifies the client whenever a `nodes`, `edges`,
81
- `projects`, or `ideas` row changes. Edits you make in the webapp show
82
- up in your agent's view without a manual refresh, and writes from one
83
- MCP-connected client reach any other connected client the same way.
84
- Pass `--no-realtime` to disable the subscription (useful if the chatter
85
- is noisy or your client logs every notification). The preference is
86
- saved to `~/.heuresis/config.json` so you only have to pass the flag
87
- once.
88
-
89
- ## Tools
90
-
91
- This is the **Phase 19.1** tool surface. The remaining tools from
92
- `docs/mcp-cloud.md` §4 ship in rolling waves under Phase 19.4.
93
-
94
- ### Reads
95
-
96
- | Tool | Input |
97
- | ------------------- | --------------------------------------------------------------------------------------------------------------------------- |
98
- | `list_projects` | `{}` — every project in the workspace with brief, direction, lifecycle, and node count. |
99
- | `get_project_graph` | `{ projectId, includeArchived?, detail? }` — every node + edge inside one project. |
100
- | `get_subtree` | `{ rootId, depth?, detail? }` — a node and its descendants up to `depth` generations. |
101
- | `get_concept` | `{ id, includeAncestry?, includeChildren?, includeIdeaMemberships? }` — one concept with full detail. |
102
- | `search_concepts` | `{ query, limit?, projectId?, status?, detail? }` — substring search across label / description / partition / tags. Text-only; semantic search lands in 19.4. |
103
-
104
- ### Writes
105
-
106
- | Tool | Input |
107
- | ---------------- | -------------------------------------------------------------------------------------------------------------------- |
108
- | `add_concept` | `{ label, description?, parentId?, projectId?, tags? }` — create a node; partition edge auto-created if parented. |
109
- | `update_concept` | `{ id, label?, description?, tags?, partitionAttribute?, rationale?, status? }` — patch a node. |
110
- | `link_concepts` | `{ fromId, toId, kind }` where `kind ∈ { 'k-ref', 'derived-from', 'semantic-adjacency' }` — create a non-partition edge. |
111
-
112
- Each tool's input shape mirrors its counterpart in the webapp's
113
- `src/agent/tools.ts`, so an agent that uses both surfaces sees a
114
- uniform contract.
115
-
116
- ## Status
117
-
118
- **Cloud-authenticated alpha (v0.2.0-alpha, Phase 19.1).**
119
-
120
- - The 8 tools above hit Supabase live, against the same workspace your
121
- webapp sees, under the same RLS.
122
- - Full tool parity (the other 19 tools — operators, k-ref bulk ops,
123
- validation, standing, ideas, projects-as-targets) ships in waves
124
- under Phase 19.4 and is **not** included in this build.
125
- - The `mcp-device-poll` / `mcp-device-grant` Edge Functions that make
126
- `login` automatic ship in Phase 19.3. Until then the `login`
127
- subcommand uses the manual paste workaround described above.
128
- - The Settings ▸ Account ▸ Connected devices UI (where you'd revoke
129
- this device) ships in Phase 19.6. Until then, revoke at the database
130
- level.
131
-
132
- ## Legacy snapshot mode (deprecated)
133
-
134
- The v0 read-only snapshot reader still works as a fallback while users
135
- migrate. With no `~/.heuresis/credentials.json` and the
136
- `HEURESIS_SNAPSHOT` env var set, the server reads a JSON export from
137
- disk and exposes the v0 read-only tool set (`get_workspace_summary`,
138
- `list_projects`, `search_concepts`, `get_concept`, `get_subtree`,
139
- `get_project_graph`, `list_recent_decisions`).
140
-
141
- ```bash
142
- export HEURESIS_SNAPSHOT="/absolute/path/to/your-export.json"
143
- npx @heuresis/mcp
144
- ```
145
-
146
- This path is **deprecated** and will be removed after Phase 19.7
147
- (cloud-auth mandatory). It's here so the current install path keeps
148
- working through the migration.
149
-
150
- ## License
151
-
152
- AGPL-3.0-or-later.
1
+ # @heuresis/mcp
2
+
3
+ A Model Context Protocol (MCP) server that exposes a Heuresis workspace
4
+ to any MCP-capable client (Claude Desktop, Claude Code, Cursor,
5
+ Windsurf, custom agents). The server logs into the user's Heuresis
6
+ account, talks to the same Supabase project the webapp talks to, and
7
+ respects the same RLS. Webapp and MCP are two front-ends to one cloud
8
+ workspace.
9
+
10
+ Current version: `1.0.0-rc.7`.
11
+
12
+ ## Install
13
+
14
+ ```bash
15
+ npm install -g @heuresis/mcp
16
+ # or on demand without installing:
17
+ npx -y @heuresis/mcp
18
+ ```
19
+
20
+ ## Quickstart
21
+
22
+ ### 1. Link this machine to your Heuresis account
23
+
24
+ ```bash
25
+ npx -y @heuresis/mcp login
26
+ ```
27
+
28
+ The CLI prints a device code and a one-click URL of the form
29
+ `https://heuresis.app/device?code=XXXX-XXXX`. Open it in your browser,
30
+ sign in if you aren't already, and confirm the device. The CLI polls
31
+ in the background and writes credentials to
32
+ `~/.heuresis/credentials.json` (chmod 600 on POSIX) the moment you
33
+ confirm. Subsequent runs of the MCP are silent.
34
+
35
+ The login flow rides three Supabase Edge Functions:
36
+ `mcp-device-start`, `mcp-device-grant`, and `mcp-device-poll`.
37
+
38
+ To unlink a machine: `npx @heuresis/mcp logout`, or open
39
+ Settings Connected devices in the webapp to revoke remotely.
40
+
41
+ `npx @heuresis/mcp whoami` confirms which account a machine is
42
+ currently linked to.
43
+
44
+ ### 2. Point your MCP client at it
45
+
46
+ **Claude Desktop.** Edit
47
+ `~/Library/Application Support/Claude/claude_desktop_config.json` on
48
+ macOS, or `%APPDATA%/Claude/claude_desktop_config.json` on Windows:
49
+
50
+ ```json
51
+ {
52
+ "mcpServers": {
53
+ "heuresis": { "command": "npx", "args": ["-y", "@heuresis/mcp"] }
54
+ }
55
+ }
56
+ ```
57
+
58
+ **Claude Code / Cursor / Windsurf.** Drop a `.mcp.json` in the
59
+ workspace root:
60
+
61
+ ```json
62
+ {
63
+ "mcpServers": {
64
+ "heuresis": { "command": "npx", "args": ["-y", "@heuresis/mcp"] }
65
+ }
66
+ }
67
+ ```
68
+
69
+ Restart the client. The Heuresis tools appear in the tool menu.
70
+
71
+ ### 3. CLI subcommands
72
+
73
+ ```bash
74
+ npx @heuresis/mcp whoami # show the linked account + device
75
+ npx @heuresis/mcp logout # delete the credentials file
76
+ npx @heuresis/mcp --help # all options
77
+ npx @heuresis/mcp --no-realtime # boot once with live sync turned off (persisted)
78
+ npx @heuresis/mcp --realtime # re-enable live sync
79
+ ```
80
+
81
+ ## Live sync
82
+
83
+ When the MCP boots in cloud mode it subscribes to the workspace over
84
+ Supabase Realtime and notifies the client whenever a `nodes`, `edges`,
85
+ `projects`, or `ideas` row changes. Edits made in the webapp show up
86
+ in the agent's view without a manual refresh, and writes from one
87
+ MCP-connected client reach any other connected client the same way.
88
+ Pass `--no-realtime` to disable the subscription (useful if the
89
+ chatter is noisy or the client logs every notification). The
90
+ preference is saved to `~/.heuresis/config.json` so the flag only
91
+ needs to be passed once.
92
+
93
+ ## Tools
94
+
95
+ 34 tools total: 31 data tools against the cloud workspace, plus 3
96
+ operator tools that drive the same ideation operators the webapp uses.
97
+
98
+ **Reads (10).** `get_workspace_summary`, `list_projects`,
99
+ `get_project_graph`, `list_concepts`, `list_edges`, `get_subtree`,
100
+ `get_concept`, `search_concepts`, `find_concepts`,
101
+ `list_recent_decisions`. Most agent sessions start with
102
+ `get_workspace_summary` or `list_projects`.
103
+
104
+ **Writes (21).** Concepts: `add_concept`, `update_concept`,
105
+ `bulk_add_concepts`, `set_parent`, `validate_concept`, `set_standing`,
106
+ `archive_concept`, `unarchive_concept`, `star_concept`,
107
+ `remove_concept`. Edges: `link_concepts`, `add_kref`. Ideas:
108
+ `create_idea`, `rename_idea`, `recolor_idea`, `set_idea_members`,
109
+ `add_to_idea`, `delete_idea`. Projects: `create_project`,
110
+ `update_project`, `delete_project`. Every write stamps a row in
111
+ `public.provenance` with `origin='mcp'` so the webapp's session log
112
+ shows which surface made the change.
113
+
114
+ **Operator runs (3).** `run_operator` (generate candidates with
115
+ Branch / Matrix / ASIT / TRIZ / Combine / Free / Contradiction),
116
+ `run_operator_and_commit` (same, plus commit the result in one
117
+ round-trip), and `expand_concept` (recursive Branch, capped at depth ×
118
+ breadth 60).
119
+
120
+ Tool input shapes mirror their counterparts in the webapp's
121
+ `src/agent/tools.ts`, so an agent that uses both surfaces sees a
122
+ uniform contract.
123
+
124
+ Wave-shipping: `find_in_files` (in-browser embedding search) is in the
125
+ webapp but not yet on the MCP.
126
+
127
+ ## Legacy snapshot mode (deprecated)
128
+
129
+ The original read-only snapshot reader still works as a fallback while
130
+ users migrate to cloud auth. With no `~/.heuresis/credentials.json`
131
+ and the `HEURESIS_SNAPSHOT` env var set, the server reads a JSON
132
+ export from disk and exposes the original read-only tool set
133
+ (`get_workspace_summary`, `list_projects`, `search_concepts`,
134
+ `get_concept`, `get_subtree`, `get_project_graph`,
135
+ `list_recent_decisions`).
136
+
137
+ ```bash
138
+ export HEURESIS_SNAPSHOT="/absolute/path/to/your-export.json"
139
+ npx @heuresis/mcp
140
+ ```
141
+
142
+ This path is deprecated and will be removed in a later release. It is
143
+ here so existing setups keep working through the migration to cloud
144
+ auth.
145
+
146
+ ## License
147
+
148
+ AGPL-3.0-or-later.
@@ -37,6 +37,7 @@ import { COMBINE_OPERATOR } from './operators/combine.js';
37
37
  import { EXPLORE_OPERATOR } from './operators/explore.js';
38
38
  import { TRIZ_PARAMETERS, TRIZ_PRINCIPLES, lookupPrinciples, } from './operators/triz-matrix.js';
39
39
  import { composePrompt } from './prompt/compose.js';
40
+ import { composeOperatorSystemPrefix } from './llm/operatorFraming.js';
40
41
  import { parseLlmResponse } from './prompt/parse.js';
41
42
  import { defaultModelFor, runLlm, } from './llm/client.js';
42
43
  import { estimateCost } from './llm/cost.js';
@@ -293,7 +294,14 @@ export async function runOperator(client, args) {
293
294
  model: config.model,
294
295
  promptChars: prompt.length,
295
296
  });
296
- const llmResult = await runLlm(config, { prompt });
297
+ // Prompt-caching Step 2 mirror pass a stable operator-framing system
298
+ // prefix so the Anthropic prompt cache catches every repeat operator
299
+ // call within the 5-minute TTL. The MCP `runLlm` already wraps
300
+ // systemPrefix with `cache_control: ephemeral` for the Anthropic path.
301
+ const llmResult = await runLlm(config, {
302
+ prompt,
303
+ systemPrefix: composeOperatorSystemPrefix(),
304
+ });
297
305
  const parsed = parseLlmResponse(llmResult.text);
298
306
  if (!parsed.ok) {
299
307
  throw new Error(`Operator run produced output the parser rejected: ${parsed.error}`);
@@ -853,17 +853,14 @@ export async function listEdges(client, args) {
853
853
  // ---------------------------------------------------------------------------
854
854
  // find_concepts
855
855
  // ---------------------------------------------------------------------------
856
- // Mirrors the webapp `find_concepts` tool. Webapp version supports
857
- // by='meaning' (in-browser embeddings) and by='label'. The MCP runs server-
858
- // side without a local embedding model, so by='meaning' transparently falls
859
- // back to the same substring search as by='label' and the response carries a
860
- // `note` explaining the degradation. Phase 19.5 swaps in pgvector when the
861
- // schema picks it up.
856
+ // Mirrors the webapp `find_concepts` tool, label/substring path only. The
857
+ // webapp's by='meaning' variant relies on in-browser embeddings; that path is
858
+ // not wired on the MCP side, so this tool accepts by='label' only.
862
859
  export const findConceptsInput = z
863
860
  .object({
864
861
  query: z.string().min(1),
865
862
  k: z.number().int().positive().max(20).default(10),
866
- by: z.enum(['meaning', 'label']).default('meaning'),
863
+ by: z.enum(['label']).default('label'),
867
864
  projectId: z.string().optional(),
868
865
  })
869
866
  .strict();
@@ -885,13 +882,6 @@ export async function findConcepts(client, args) {
885
882
  status: r.status,
886
883
  score: 1,
887
884
  }));
888
- if (args.by === 'meaning') {
889
- return {
890
- hits,
891
- mode: 'label',
892
- note: 'Semantic search not yet wired in MCP (no in-browser embedding model); fell back to label/substring match.',
893
- };
894
- }
895
885
  return { hits, mode: 'label' };
896
886
  }
897
887
  // ===========================================================================
@@ -1591,7 +1581,7 @@ export const CLOUD_TOOLS = [
1591
1581
  },
1592
1582
  {
1593
1583
  name: 'find_concepts',
1594
- description: "Find concepts by label/substring match. (Webapp parity: by='meaning' is accepted but currently falls back to label match on the MCP — semantic search ships in Phase 19.5.) Returns up to k hits, each with id, label, status.",
1584
+ description: 'Find concepts by label/substring match. Returns up to k hits, each with id, label, status.',
1595
1585
  inputSchema: findConceptsInput,
1596
1586
  handler: async (client, args) => findConcepts(client, findConceptsInput.parse(args)),
1597
1587
  },
@@ -0,0 +1,53 @@
1
+ // VENDORED MIRROR of src/llm/operatorFraming.ts — keep in sync with the
2
+ // webapp. The mcp-server is independently buildable (its own tsconfig,
3
+ // its own deps), so we vendor the framing block here rather than reaching
4
+ // across the repo boundary.
5
+ //
6
+ // Heuresis's smaller operator doctrines (ASIT ~500-800 tok, Branch ~600-1200
7
+ // tok) sit right around or below Sonnet's 1,024-token minimum-cacheable-size
8
+ // threshold. Below that floor the Anthropic API silently does NOT cache the
9
+ // prefix — `cache_creation_input_tokens` comes back as 0 and the next call
10
+ // re-tokenizes everything at full price.
11
+ //
12
+ // IMPORTANT: this block is the cache prefix for the ENTIRE MCP operator
13
+ // path. Editing it invalidates every operator's cache. Keep BYTE-IDENTICAL
14
+ // with the webapp copy at src/llm/operatorFraming.ts.
15
+ export const OPERATOR_FRAMING_PREAMBLE = [
16
+ 'You are Heuresis\'s operator engine — a stateless transform that takes a parent CONCEPT plus structured context, applies one named OPERATOR (an ASIT tool, a TRIZ inventive principle, a C-K partition rule, a free-form lab prompt, etc.), and emits a JSON object proposing 1–8 child concepts.',
17
+ '',
18
+ 'CONTRACT.',
19
+ ' • You receive: the project brief, the concept-path from root to target, the target concept, a pool of validated knowledge (K), an operator definition (family / key / name / doctrine / prompt fragment), an optional graph-awareness <context> block (ancestry, sibling axes, existing labels), and optionally COMBINE inputs, an EXPLORE <branch>, or a free-form <angle>.',
20
+ ' • You return: ONE JSON object matching the requested schema. NEVER prose before or after, NEVER markdown fences, NEVER trailing commas, NEVER comments inside the JSON. The caller parses with strict-mode zod and rejects anything that does not match.',
21
+ ' • If the schema asks for partitions[], emit between 3 and 5 top-level partitions unless the operator explicitly says otherwise (EXPLORE allows 4–8). Each partition is a STANDALONE concept title (2–5 words, ≤60 chars, no parent-prefix, no trailing period), a 1–2 sentence description, a ≤5-word partitionAttribute naming the distinguishing AXIS, a 1–3 sentence rationale citing the operator and any K used, and a kReferences[] of K-ids you actually used.',
22
+ '',
23
+ 'DOCTRINE.',
24
+ ' • Stay faithful to the operator. ASIT operators MUST stay inside the closed world — never introduce alien components. TRIZ operators MUST honor the named inventive principle. C-K operators MUST treat C-nodes as undecidable noun-phrases (never solutions in disguise — verbs like "build", "add", "use", "implement", "create" at the start of a label belong in the parking lot, not in the C-tree).',
25
+ ' • Be additive, not redundant. The <context> block (when present) lists existing canvas labels and sibling axes — do not propose paraphrases of either. Where possible, partition on an axis NOT yet present in <sibling_axes>.',
26
+ ' • Be honest. Use the optional selfCritique field to surface the strongest assumption or risk in each partition. Do not flatter.',
27
+ ' • Cite K. If a knowledge item informed a partition, list its id in kReferences. If you needed a fact you do not have, propose it via newKnowledgeProposed (1–3 items, framed as questions, never invented numbers).',
28
+ '',
29
+ 'VOICE.',
30
+ ' • Plain, sharp, conversational. Active voice, short sentences. No sales hype, no poetry, no exclamation points. Never use an em dash ("—"); use a period, comma, colon, or parentheses instead.',
31
+ ' • Labels are concept titles, not sentences. Put long-form prose in description / rationale, never in label.',
32
+ '',
33
+ 'FAILURE MODES TO AVOID.',
34
+ ' • Restating the parent concept as a child.',
35
+ ' • Two partitions that decompose the same axis (collapse them or pick the stronger).',
36
+ ' • Children whose label contains the immediate parent partition\'s label.',
37
+ ' • Nesting children deeper than one level — a child MUST NOT carry its own children[].',
38
+ ' • Markdown / code fences around the JSON.',
39
+ ].join('\n');
40
+ /**
41
+ * Stable system prefix shared by every operator run on the MCP side.
42
+ * Composed of the framing preamble plus a short prologue paragraph so the
43
+ * cached prefix carries both the framing and the per-call lead-in.
44
+ */
45
+ export function composeOperatorSystemPrefix() {
46
+ return (OPERATOR_FRAMING_PREAMBLE +
47
+ '\n\n' +
48
+ 'You are assisting an inventive design session structured by C-K theory. ' +
49
+ 'The user grows a graph of concepts (C) drawing on a pool of validated ' +
50
+ 'knowledge (K). When asked to apply an operator from ASIT, TRIZ, or a ' +
51
+ 'free-form lab prompt, propose between 3 and 5 partitions of the TARGET ' +
52
+ 'concept (3–8 for EXPLORE) unless the operator instructions say otherwise.');
53
+ }
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@heuresis/mcp",
3
- "version": "1.0.0-rc.6",
3
+ "version": "1.0.0-rc.8",
4
+ "mcpName": "io.github.toremlabs/heuresis",
4
5
  "description": "Cloud-authenticated Model Context Protocol server for a Heuresis workspace. Logs into the user's Heuresis account and lets any MCP client (Claude Desktop, Claude Code, Cursor, custom agents) read and write the same workspace the webapp uses. 31 data tools, 3 operator tools (Branch/Matrix/C-K/ASIT/TRIZ/Free/Combine/Explore), and live Realtime change subscriptions.",
5
6
  "type": "module",
6
7
  "bin": {