Skip to content

Turbocharge Claude Code, Cursor, Codex, Gemini & every coding agent: faster, cheaper, with contextual understanding specific to your codebase.

feat(init): register the MCP server for selected agents (--no-mcp to skip)

Shrish Dwivediecc528b37049
diff --git a/README.md b/README.md
index b733e8ed..d48cc0f7 100644
--- a/README.md
+++ b/README.md
@@ -73,6 +73,17 @@ npx @nanonets/graft init
| `--no-agents` | Claude Code wiring only; skip other agents |
| `--list-agents` | print the known agent ids and exit |
+### MCP server
+
+`graft init` also registers Graft's MCP server with agents that support it, so
+`graft_ask`, `graft_check`, and `graft_blast_radius` appear as native tools —
+no shell required. Skip with `--no-mcp`. Run it manually with `graft mcp [dir]`,
+or register it by hand:
+
+```json
+{ "mcpServers": { "graft": { "command": "npx", "args": ["-y", "@nanonets/graft", "mcp"] } } }
+```
+
### Claude Code (deep integration)
`graft init` always wires up Claude Code, and Claude Code gets more than an instruction file. From then on, any Claude Code session opened in the repo gets:
diff --git a/src/cli.ts b/src/cli.ts
index 107e10eb..156977c6 100644
--- a/src/cli.ts
+++ b/src/cli.ts
@@ -206,7 +206,8 @@ program
.option("--all-agents", "write instruction files for every known agent, detected or not")
.option("--no-agents", "Claude Code wiring only; skip other agents")
.option("--list-agents", "list known agent ids and exit")
- .action((dir: string, opts: { build?: boolean; agents?: string[]; allAgents?: boolean; listAgents?: boolean }) => {
+ .option("--no-mcp", "skip MCP server registration for other agents")
+ .action((dir: string, opts: { build?: boolean; agents?: string[]; allAgents?: boolean; listAgents?: boolean; mcp?: boolean }) => {
if (opts.listAgents) {
for (const id of [...hostIds(), "claude"]) console.log(id);
return;
@@ -240,11 +241,13 @@ program
const r = runHostsInit(repo, {
agents: explicit?.filter((id) => id !== "claude"),
all: opts.allAgents,
+ mcp: opts.mcp,
});
for (const w of r.written) console.error(`✓ ${w.id}: ${w.path} (${w.action})`);
if (!explicit && !opts.allAgents && r.written.length === 0)
console.error("· no other agents detected (see --list-agents / --all-agents)");
// r.unknown is always empty here — ids are validated above, before any writes.
+ for (const m of r.mcp) console.error(`✓ mcp ${m.id}: ${m.path} (${m.action})`);
}
console.error("\nDone. Claude Code gets live hooks + statusline; other agents read their instruction files.");
console.error("For LLM summaries: set OPENROUTER_API_KEY and run `graft build --deep`.");
diff --git a/src/hosts/init.ts b/src/hosts/init.ts
index fd950a72..63a81a09 100644
--- a/src/hosts/init.ts
+++ b/src/hosts/init.ts
@@ -8,11 +8,13 @@ import { dirname, join } from 'node:path';
import { homedir } from 'node:os';
import { HOSTS, detectHosts, type DetectProbe, type HostTarget } from './registry.js';
import { upsertSection } from './sections.js';
+import { registerMcpConfigs, type McpWrite } from './mcp-config.js';
export interface HostsInitResult {
written: { id: string; path: string; action: string }[];
skipped: string[];
unknown: string[];
+ mcp: McpWrite[];
}
function probeFor(home: string, repo: string): DetectProbe {
@@ -32,7 +34,7 @@ function writeOwned(path: string, content: string): string {
export function runHostsInit(
repo: string,
- opts: { agents?: string[]; all?: boolean; home?: string } = {},
+ opts: { agents?: string[]; all?: boolean; home?: string; mcp?: boolean } = {},
): HostsInitResult {
const home = opts.home ?? homedir();
const probe = probeFor(home, repo);
@@ -59,5 +61,6 @@ export function runHostsInit(
written.push({ id: host.id, path, action });
}
const skipped = HOSTS.filter((h) => !selected.includes(h)).map((h) => h.id);
- return { written, skipped, unknown };
+ const mcp = opts.mcp === false ? [] : registerMcpConfigs(repo, selected.map((h) => h.id), { home });
+ return { written, skipped, unknown, mcp };
}
diff --git a/test/hosts-init.test.ts b/test/hosts-init.test.ts
index 25586616..d68b6b27 100644
--- a/test/hosts-init.test.ts
+++ b/test/hosts-init.test.ts
@@ -97,3 +97,26 @@ test('CLI: --agents claude gemini nope exits non-zero and leaves repo untouched
assert.ok(!existsSync(join(repo, 'GEMINI.md')));
assert.ok(!existsSync(join(repo, 'AGENTS.md')));
});
+
+test('runHostsInit registers MCP configs for selected hosts', () => {
+ const home = fresh(); const repo = fresh();
+ const r = runHostsInit(repo, { home, agents: ['cursor'] });
+ assert.equal(r.mcp.length, 1);
+ assert.match(r.mcp[0].path, /\.cursor\/mcp\.json$/);
+ const cfg = JSON.parse(readFileSync(join(repo, '.cursor', 'mcp.json'), 'utf8'));
+ assert.equal(cfg.mcpServers.graft.command, 'npx');
+});
+
+test('mcp: false skips MCP registration', () => {
+ const home = fresh(); const repo = fresh();
+ const r = runHostsInit(repo, { home, agents: ['cursor'], mcp: false });
+ assert.deepEqual(r.mcp, []);
+ assert.ok(!existsSync(join(repo, '.cursor', 'mcp.json')));
+});
+
+test('CLI: --no-mcp writes the rule file but no MCP config', () => {
+ const repo = fresh();
+ execFileSync(process.execPath, ['--import', 'tsx', 'src/cli.ts', 'init', repo, '--no-build', '--agents', 'cursor', '--no-mcp'], { encoding: 'utf8' });
+ assert.ok(existsSync(join(repo, '.cursor', 'rules', 'graft.mdc')));
+ assert.ok(!existsSync(join(repo, '.cursor', 'mcp.json')));
+});