@heuresis/mcp 1.0.0-rc.7 → 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.
@@ -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}`);
@@ -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.7",
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": {