yats-toolkit 0.6.3 → 0.7.0
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/connect/copilot/mcp.json +4 -5
- package/connect/vscode/mcp.json +9 -0
- package/package.json +1 -1
- package/src/connect.js +127 -31
- package/src/connect.test.js +86 -0
- package/src/setup.js +4 -4
package/connect/copilot/mcp.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yats-toolkit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "YATS — Yet Another Token Saver. One-command MCP server that indexes your codebase into a knowledge graph so AI agents (Claude, Cursor, Copilot) can search and navigate it without burning tokens.",
|
|
5
5
|
"author": "Franco Vinciarelli <vinciarellifranco@gmail.com>",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
package/src/connect.js
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { writeFileSync, readFileSync, existsSync, mkdirSync } from "node:fs";
|
|
17
17
|
import { join, dirname } from "node:path";
|
|
18
|
+
import { fileURLToPath } from "node:url";
|
|
18
19
|
import { createInterface } from "node:readline";
|
|
19
20
|
import { homedir } from "node:os";
|
|
20
21
|
import { spawnSync } from "node:child_process";
|
|
@@ -54,10 +55,21 @@ const AGENTS = {
|
|
|
54
55
|
transport: "stdio bridge",
|
|
55
56
|
files: [
|
|
56
57
|
{ src: "connect/copilot/instructions.md", dest: ".github/copilot-instructions.md", type: "text" },
|
|
57
|
-
|
|
58
|
+
// VS Code Chat / Copilot Agent Host reads the portable .mcp.json at the
|
|
59
|
+
// repo root (mcpServers format), not .copilot/mcp.json (CLI-only format).
|
|
60
|
+
{ src: "connect/copilot/mcp.json", dest: ".mcp.json", type: "json" },
|
|
58
61
|
],
|
|
59
62
|
url: "https://github.com/fvinciarelli/yats.ai/tree/main/connect/copilot",
|
|
60
63
|
},
|
|
64
|
+
vscode: {
|
|
65
|
+
name: "VS Code (native MCP)",
|
|
66
|
+
transport: "stdio bridge",
|
|
67
|
+
files: [
|
|
68
|
+
// Native VS Code workspace MCP config (servers format).
|
|
69
|
+
{ src: "connect/vscode/mcp.json", dest: ".vscode/mcp.json", type: "json" },
|
|
70
|
+
],
|
|
71
|
+
url: "https://github.com/fvinciarelli/yats.ai/tree/main/connect/vscode",
|
|
72
|
+
},
|
|
61
73
|
gemini: {
|
|
62
74
|
name: "Gemini CLI",
|
|
63
75
|
transport: "stdio bridge",
|
|
@@ -79,17 +91,23 @@ const AGENTS = {
|
|
|
79
91
|
};
|
|
80
92
|
|
|
81
93
|
function getYatsMcpConfig() {
|
|
94
|
+
let cfg = { mcpServers: { yats: { url: "http://localhost:5555/mcp" } } };
|
|
82
95
|
try {
|
|
83
|
-
|
|
84
|
-
} catch {
|
|
85
|
-
|
|
96
|
+
cfg = JSON.parse(readFileSync(MCP_CONFIG_FILE, "utf-8"));
|
|
97
|
+
} catch { /* no config yet — use the default above */ }
|
|
98
|
+
// Normalize legacy /mcp/sse URLs to the Streamable HTTP endpoint.
|
|
99
|
+
const url = cfg?.mcpServers?.yats?.url;
|
|
100
|
+
if (typeof url === "string" && url.endsWith("/mcp/sse")) {
|
|
101
|
+
cfg.mcpServers.yats.url = url.slice(0, -4);
|
|
86
102
|
}
|
|
103
|
+
return cfg;
|
|
87
104
|
}
|
|
88
105
|
|
|
89
106
|
function getFileContent(srcPath) {
|
|
90
|
-
// Templates ship inside the package (connect/ dir) — resolves from src/ → ../connect
|
|
107
|
+
// Templates ship inside the package (connect/ dir) — resolves from src/ → ../connect/.
|
|
108
|
+
// fileURLToPath handles percent-encoded paths (spaces, unicode) and Windows drives.
|
|
91
109
|
try {
|
|
92
|
-
const pkgDir = dirname(
|
|
110
|
+
const pkgDir = dirname(fileURLToPath(import.meta.url));
|
|
93
111
|
const installedPath = join(pkgDir, "..", srcPath);
|
|
94
112
|
if (existsSync(installedPath)) {
|
|
95
113
|
return readFileSync(installedPath, "utf-8");
|
|
@@ -102,7 +120,7 @@ function getFileContent(srcPath) {
|
|
|
102
120
|
// Render / template helpers
|
|
103
121
|
// ============================================================
|
|
104
122
|
|
|
105
|
-
function renderContent(srcPath) {
|
|
123
|
+
export function renderContent(srcPath) {
|
|
106
124
|
const content = getFileContent(srcPath);
|
|
107
125
|
if (content === null) {
|
|
108
126
|
console.log(` ${RED}✗${R} Missing template ${srcPath} — reinstall yats-toolkit`);
|
|
@@ -135,14 +153,84 @@ function appendMarker(agentKey) {
|
|
|
135
153
|
// Install helpers
|
|
136
154
|
// ============================================================
|
|
137
155
|
|
|
138
|
-
|
|
139
|
-
|
|
156
|
+
/** Read an existing JSON config as an object, or null if missing/invalid. */
|
|
157
|
+
function readJsonObject(path) {
|
|
140
158
|
try {
|
|
141
|
-
obj = JSON.parse(readFileSync(
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
159
|
+
const obj = JSON.parse(readFileSync(path, "utf-8"));
|
|
160
|
+
return obj && typeof obj === "object" && !Array.isArray(obj) ? obj : null;
|
|
161
|
+
} catch {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Merge an agent template into an existing JSON config. Templates carry one
|
|
168
|
+
* of two shapes — `mcpServers` (Claude/Copilot/Gemini/Cursor) or `servers`
|
|
169
|
+
* (VS Code native) — both objects keyed by server name. Existing entries are
|
|
170
|
+
* preserved; only the YATS entry is added or updated.
|
|
171
|
+
*/
|
|
172
|
+
export function mergeServerConfig(existing, template) {
|
|
173
|
+
const out = {};
|
|
174
|
+
for (const key of Object.keys(existing)) out[key] = existing[key];
|
|
175
|
+
for (const key of Object.keys(template)) {
|
|
176
|
+
const tpl = template[key];
|
|
177
|
+
if (tpl && typeof tpl === "object" && !Array.isArray(tpl)) {
|
|
178
|
+
const base =
|
|
179
|
+
out[key] && typeof out[key] === "object" && !Array.isArray(out[key])
|
|
180
|
+
? out[key]
|
|
181
|
+
: {};
|
|
182
|
+
out[key] = { ...base, ...tpl };
|
|
183
|
+
} else {
|
|
184
|
+
out[key] = tpl;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return out;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Install one agent's JSON config file from its template.
|
|
192
|
+
* The template is the source of truth (correct format + transport per
|
|
193
|
+
* agent: stdio bridge for copilot/claude/gemini/vscode, HTTP for cursor) —
|
|
194
|
+
* never the global ~/.yats/mcp-config.json, which is HTTP-only and generic.
|
|
195
|
+
* Non-destructive: existing files are merged, other entries preserved.
|
|
196
|
+
*/
|
|
197
|
+
function installJsonFile(file) {
|
|
198
|
+
const templateContent = renderContent(file.src);
|
|
199
|
+
if (templateContent === null) {
|
|
200
|
+
console.log(` ${RED}✗${R} Missing template ${file.src} — reinstall yats-toolkit`);
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
let templateObj;
|
|
205
|
+
try {
|
|
206
|
+
templateObj = JSON.parse(templateContent);
|
|
207
|
+
} catch {
|
|
208
|
+
console.log(` ${RED}✗${R} Invalid template ${file.src}`);
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const destPath = file.dest;
|
|
213
|
+
const exists = existsSync(destPath);
|
|
214
|
+
let merged = templateObj;
|
|
215
|
+
if (exists) {
|
|
216
|
+
const existing = readJsonObject(destPath);
|
|
217
|
+
if (existing === null) {
|
|
218
|
+
console.log(` ${Y}⚠${R} ${destPath} exists but is not valid JSON — left untouched.`);
|
|
219
|
+
return false;
|
|
220
|
+
}
|
|
221
|
+
merged = mergeServerConfig(existing, templateObj);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
mkdirSync(dirname(destPath), { recursive: true });
|
|
225
|
+
writeFileSync(destPath, JSON.stringify(merged, null, 2) + "\n");
|
|
226
|
+
if (exists) {
|
|
227
|
+
console.log(` ${Y}↻${R} Merged YATS into existing ${destPath}`);
|
|
228
|
+
console.log(` ${D} Added/updated: ${JSON.stringify(templateObj)}${R}`);
|
|
229
|
+
console.log(` ${D} Your existing entries are preserved.${R}`);
|
|
230
|
+
} else {
|
|
231
|
+
console.log(` ${G}✓${R} Created ${destPath}`);
|
|
232
|
+
}
|
|
233
|
+
return true;
|
|
146
234
|
}
|
|
147
235
|
|
|
148
236
|
// Single shared readline so piped stdin keeps working across multiple prompts
|
|
@@ -225,22 +313,10 @@ async function installFiles(agentKey, prompter) {
|
|
|
225
313
|
|
|
226
314
|
for (const file of agent.files) {
|
|
227
315
|
const destPath = file.dest;
|
|
228
|
-
const mcpConfig = getYatsMcpConfig();
|
|
229
316
|
|
|
230
317
|
if (file.type === "json") {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
mkdirSync(dirname(destPath), { recursive: true });
|
|
234
|
-
writeFileSync(destPath, merged);
|
|
235
|
-
if (exists) {
|
|
236
|
-
console.log(` ${Y}↻${R} Merged YATS into existing ${destPath}`);
|
|
237
|
-
const entry = mcpConfig.mcpServers.yats;
|
|
238
|
-
console.log(` ${D} Added: mcpServers.yats → ${JSON.stringify(entry)}${R}`);
|
|
239
|
-
console.log(` ${D} Your existing entries are preserved.${R}`);
|
|
240
|
-
} else {
|
|
241
|
-
console.log(` ${G}✓${R} Created ${destPath}`);
|
|
242
|
-
}
|
|
243
|
-
installed++;
|
|
318
|
+
if (installJsonFile(file)) installed++;
|
|
319
|
+
else skipped++;
|
|
244
320
|
} else if (file.type === "toml") {
|
|
245
321
|
const exists = existsSync(destPath);
|
|
246
322
|
mkdirSync(dirname(destPath), { recursive: true });
|
|
@@ -301,6 +377,15 @@ async function installFiles(agentKey, prompter) {
|
|
|
301
377
|
console.log(` Done: ${installed} installed, ${skipped} skipped.`);
|
|
302
378
|
console.log(` Full instructions: ${C}${agent.url}${R}`);
|
|
303
379
|
console.log("");
|
|
380
|
+
|
|
381
|
+
// Copilot switched from .copilot/mcp.json (CLI format) to the portable
|
|
382
|
+
// .mcp.json at the repo root (Agent Host format). Point out the legacy file
|
|
383
|
+
// so the old config doesn't linger unnoticed.
|
|
384
|
+
if (agentKey === "copilot" && existsSync(".copilot/mcp.json")) {
|
|
385
|
+
console.log(` ${Y}⚠${R} Legacy .copilot/mcp.json found — Copilot now reads .mcp.json (Agent Host format).`);
|
|
386
|
+
console.log(` ${D} Remove the old file if unused.${R}`);
|
|
387
|
+
console.log("");
|
|
388
|
+
}
|
|
304
389
|
}
|
|
305
390
|
|
|
306
391
|
// ============================================================
|
|
@@ -365,8 +450,6 @@ function showConfig(agentKey) {
|
|
|
365
450
|
process.exit(1);
|
|
366
451
|
}
|
|
367
452
|
|
|
368
|
-
const mcpConfig = getYatsMcpConfig();
|
|
369
|
-
|
|
370
453
|
console.log("");
|
|
371
454
|
console.log(` ${B}${agent.name}${R} — via ${agent.transport}`);
|
|
372
455
|
console.log("");
|
|
@@ -374,7 +457,19 @@ function showConfig(agentKey) {
|
|
|
374
457
|
for (const file of agent.files) {
|
|
375
458
|
console.log(` ${B}${file.dest}${R}`);
|
|
376
459
|
if (file.type === "json") {
|
|
377
|
-
|
|
460
|
+
const templateContent = renderContent(file.src);
|
|
461
|
+
if (templateContent) {
|
|
462
|
+
try {
|
|
463
|
+
const tpl = JSON.parse(templateContent);
|
|
464
|
+
const existing = existsSync(file.dest) ? readJsonObject(file.dest) : null;
|
|
465
|
+
const preview = existing ? mergeServerConfig(existing, tpl) : tpl;
|
|
466
|
+
console.log(` ${D}${JSON.stringify(preview, null, 2).replace(/\n/g, "\n ")}${R}`);
|
|
467
|
+
} catch {
|
|
468
|
+
console.log(` ${D}${templateContent.replace(/\n/g, "\n ")}${R}`);
|
|
469
|
+
}
|
|
470
|
+
} else {
|
|
471
|
+
console.log(` ${RED}(missing template)${R}`);
|
|
472
|
+
}
|
|
378
473
|
} else {
|
|
379
474
|
const content = renderContent(file.src);
|
|
380
475
|
if (content) {
|
|
@@ -465,6 +560,7 @@ export default async function connect(args) {
|
|
|
465
560
|
{ label: "Claude Code", value: "claude" },
|
|
466
561
|
{ label: "Cursor", value: "cursor" },
|
|
467
562
|
{ label: "GitHub Copilot", value: "copilot" },
|
|
563
|
+
{ label: "VS Code (native MCP)", value: "vscode" },
|
|
468
564
|
{ label: "Gemini CLI", value: "gemini" },
|
|
469
565
|
{ label: "Codex CLI", value: "codex" },
|
|
470
566
|
]);
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests — yats connect: template-based JSON install + non-destructive merge.
|
|
3
|
+
*
|
|
4
|
+
* Covers the regression that shipped wrong MCP configs: the JSON install
|
|
5
|
+
* branch ignored the agent templates and wrote the generic HTTP config from
|
|
6
|
+
* ~/.yats/mcp-config.json (legacy /mcp/sse URL, mcpServers format) — Copilot
|
|
7
|
+
* got that instead of its stdio-bridge template.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { describe, it } from "node:test";
|
|
11
|
+
import assert from "node:assert/strict";
|
|
12
|
+
|
|
13
|
+
import { mergeServerConfig, renderContent } from "./connect.js";
|
|
14
|
+
|
|
15
|
+
describe("mergeServerConfig", () => {
|
|
16
|
+
it("merges mcpServers entries, preserving existing servers", () => {
|
|
17
|
+
const existing = {
|
|
18
|
+
mcpServers: {
|
|
19
|
+
github: { command: "npx", args: ["@github/mcp"] },
|
|
20
|
+
yats: { url: "http://localhost:5555/mcp/sse" },
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
const template = {
|
|
24
|
+
mcpServers: { yats: { type: "stdio", command: "yats", args: ["bridge"] } },
|
|
25
|
+
};
|
|
26
|
+
const merged = mergeServerConfig(existing, template);
|
|
27
|
+
assert.deepEqual(merged.mcpServers.github, existing.mcpServers.github);
|
|
28
|
+
assert.deepEqual(merged.mcpServers.yats, {
|
|
29
|
+
type: "stdio",
|
|
30
|
+
command: "yats",
|
|
31
|
+
args: ["bridge"],
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("merges VS Code native `servers` objects by name", () => {
|
|
36
|
+
const existing = {
|
|
37
|
+
servers: { other: { type: "http", url: "https://example.com/mcp" } },
|
|
38
|
+
};
|
|
39
|
+
const template = {
|
|
40
|
+
servers: { yats: { type: "stdio", command: "yats", args: ["bridge"] } },
|
|
41
|
+
};
|
|
42
|
+
const merged = mergeServerConfig(existing, template);
|
|
43
|
+
assert.deepEqual(merged.servers.other, existing.servers.other);
|
|
44
|
+
assert.deepEqual(merged.servers.yats, template.servers.yats);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("keeps non-object keys from both sides", () => {
|
|
48
|
+
const merged = mergeServerConfig(
|
|
49
|
+
{ comment: "mine" },
|
|
50
|
+
{ note: "template" },
|
|
51
|
+
);
|
|
52
|
+
assert.equal(merged.comment, "mine");
|
|
53
|
+
assert.equal(merged.note, "template");
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe("agent templates (shipped in the package)", () => {
|
|
58
|
+
it("copilot template targets .mcp.json with the stdio bridge (mcpServers)", () => {
|
|
59
|
+
const content = renderContent("connect/copilot/mcp.json");
|
|
60
|
+
assert.ok(content, "template must resolve from the package");
|
|
61
|
+
const tpl = JSON.parse(content);
|
|
62
|
+
assert.deepEqual(tpl, {
|
|
63
|
+
mcpServers: {
|
|
64
|
+
yats: { type: "stdio", command: "yats", args: ["bridge"] },
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("vscode template uses the native `servers` format with the bridge", () => {
|
|
70
|
+
const content = renderContent("connect/vscode/mcp.json");
|
|
71
|
+
assert.ok(content, "vscode template must resolve");
|
|
72
|
+
const tpl = JSON.parse(content);
|
|
73
|
+
assert.equal(tpl.servers.yats.type, "stdio");
|
|
74
|
+
assert.equal(tpl.servers.yats.command, "yats");
|
|
75
|
+
assert.deepEqual(tpl.servers.yats.args, ["bridge"]);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("text templates resolve and replace __REPO_PATH__", () => {
|
|
79
|
+
const content = renderContent("connect/copilot/instructions.md");
|
|
80
|
+
assert.ok(content, "instructions template must resolve");
|
|
81
|
+
assert.ok(!content.includes("__REPO_PATH__"));
|
|
82
|
+
// The replacement is the caller's working directory — must never be
|
|
83
|
+
// hardcoded (CI runs from a different path).
|
|
84
|
+
assert.ok(content.includes(`yats index ${process.cwd()}`));
|
|
85
|
+
});
|
|
86
|
+
});
|
package/src/setup.js
CHANGED
|
@@ -851,7 +851,7 @@ async function main(options = {}) {
|
|
|
851
851
|
mcpPort = suggested;
|
|
852
852
|
}
|
|
853
853
|
rlPort.close();
|
|
854
|
-
console.log(` ${G}✓${R} MCP server on ${C}http://localhost:${mcpPort}/mcp
|
|
854
|
+
console.log(` ${G}✓${R} MCP server on ${C}http://localhost:${mcpPort}/mcp${R}`);
|
|
855
855
|
console.log("");
|
|
856
856
|
}
|
|
857
857
|
|
|
@@ -897,7 +897,7 @@ async function main(options = {}) {
|
|
|
897
897
|
writeFileSync(COMPOSE_FILE, compose);
|
|
898
898
|
|
|
899
899
|
// Write MCP config
|
|
900
|
-
const mcpConfig = { mcpServers: { yats: { url: `http://localhost:${mcpPort}/mcp
|
|
900
|
+
const mcpConfig = { mcpServers: { yats: { url: `http://localhost:${mcpPort}/mcp` } } };
|
|
901
901
|
writeFileSync(MCP_CONFIG_FILE, JSON.stringify(mcpConfig, null, 2));
|
|
902
902
|
|
|
903
903
|
// Persist keys to ~/.yats/.env — canonical source (embedding + benchmark keys).
|
|
@@ -1016,14 +1016,14 @@ async function main(options = {}) {
|
|
|
1016
1016
|
|
|
1017
1017
|
// Done
|
|
1018
1018
|
console.log("");
|
|
1019
|
-
console.log(` ✅ ${G}YATS is ready!${R} → ${C}http://localhost:${mcpPort}/mcp
|
|
1019
|
+
console.log(` ✅ ${G}YATS is ready!${R} → ${C}http://localhost:${mcpPort}/mcp${R}`);
|
|
1020
1020
|
console.log("");
|
|
1021
1021
|
console.log(` Config saved to ${C}~/.yats/.env${R}`);
|
|
1022
1022
|
console.log(` ${D}Benchmark agent keys (ANTHROPIC_API_KEY, OPENAI_API_KEY, GEMINI_API_KEY) go there too.${R}`);
|
|
1023
1023
|
console.log("");
|
|
1024
1024
|
box([
|
|
1025
1025
|
`${B}Copy this URL into your AI agent:${R}`,
|
|
1026
|
-
`{ "url": "http://localhost:${mcpPort}/mcp
|
|
1026
|
+
`{ "url": "http://localhost:${mcpPort}/mcp" }`,
|
|
1027
1027
|
"",
|
|
1028
1028
|
`${B}Copilot / Claude Desktop:${R}`,
|
|
1029
1029
|
`{ "command": "npx", "args": ["yats-bridge"] }`,
|