|
| 1 | +/** |
| 2 | + * Server-level instructions emitted in the MCP `initialize` response. |
| 3 | + * |
| 4 | + * MCP clients (Claude Code, Cursor, opencode, LangChain, OpenAI Agent |
| 5 | + * SDK, …) surface this text in the agent's system prompt automatically, |
| 6 | + * giving the agent a high-level playbook for the codegraph toolset |
| 7 | + * before it sees individual tool descriptions. |
| 8 | + * |
| 9 | + * Goals when editing this: |
| 10 | + * - Tool selection by intent (which tool for which question) |
| 11 | + * - Common chains (refactor planning = X then Y) |
| 12 | + * - Anti-patterns (don't grep when codegraph_search is faster) |
| 13 | + * |
| 14 | + * Keep it tight. The agent reads this every session — long instructions |
| 15 | + * burn tokens. Reference only tools that exist on `main`; gate any |
| 16 | + * conditional tools behind feature checks if/when they ship. |
| 17 | + */ |
| 18 | +export const SERVER_INSTRUCTIONS = `# Codegraph — code intelligence over an indexed knowledge graph |
| 19 | +
|
| 20 | +Codegraph is a SQLite knowledge graph of every symbol, edge, and file |
| 21 | +in the workspace. Reads are sub-millisecond; the index lags writes by |
| 22 | +about a second through the file watcher. Consult it BEFORE writing or |
| 23 | +editing code, not during. |
| 24 | +
|
| 25 | +## Tool selection by intent |
| 26 | +
|
| 27 | +- **"What is the symbol named X?"** → \`codegraph_search\` |
| 28 | +- **"What's the deal with this task / feature / area?"** → \`codegraph_context\` (PRIMARY — composes search + node + callers + callees in one call) |
| 29 | +- **"What calls this?"** → \`codegraph_callers\` |
| 30 | +- **"What does this call?"** → \`codegraph_callees\` |
| 31 | +- **"What would changing this break?"** → \`codegraph_impact\` |
| 32 | +- **"Show me this symbol's source / signature / docstring."** → \`codegraph_node\` |
| 33 | +- **"Survey an unfamiliar topic / pattern / module."** → \`codegraph_explore\` (heavier; deep dive) |
| 34 | +- **"What's in directory X?"** → \`codegraph_files\` |
| 35 | +- **"Is the index ready / what's its size?"** → \`codegraph_status\` |
| 36 | +
|
| 37 | +## Common chains |
| 38 | +
|
| 39 | +- **Onboarding**: \`codegraph_context\` first. If still unclear, \`codegraph_explore\` for breadth, then \`codegraph_node\` on specific symbols. |
| 40 | +- **Refactor planning**: \`codegraph_search\` → \`codegraph_callers\` → \`codegraph_impact\`. The blast-radius answer comes from impact, not from walking callers manually. |
| 41 | +- **Debugging a regression**: \`codegraph_callers\` of the suspected symbol; widen with \`codegraph_impact\` if an unexpected call appears. |
| 42 | +
|
| 43 | +## Anti-patterns |
| 44 | +
|
| 45 | +- **Don't grep first** when looking up a symbol by name — \`codegraph_search\` is faster and returns kind + location + signature. |
| 46 | +- **Don't chain \`codegraph_search\` + \`codegraph_node\`** when you just want context — \`codegraph_context\` is one round-trip. |
| 47 | +- **Don't use \`codegraph_explore\` for narrow questions** — it's a multi-call deep dive, expensive in tokens. Save it for genuine "I'm new here" surveys. |
| 48 | +- **Don't query the index immediately after editing a file** — the watcher needs ~500ms to debounce + sync. Wait for the next turn. |
| 49 | +
|
| 50 | +## Limitations |
| 51 | +
|
| 52 | +- Index lags file writes by ~1 second. |
| 53 | +- Cross-file resolution is best-effort name matching; ambiguous calls may return multiple candidates. |
| 54 | +- No live correctness validation — that's still the TypeScript compiler / test suite / linter's job. Codegraph supplements those with structural context they don't have. |
| 55 | +`; |
0 commit comments