dist-mcp / mcp / config.test.js
dist-mcp / mcp / config.test.js
import assert from "node:assert/strict";
import test from "node:test";
import { readMcpConfig } from "./config.js";
const ALL_VARS = [
"CHAT_WORKING_DIRECTORIES",
"MCP_MADE_FOR",
"MCP_MADE_FOR_BIONIC",
"DRAW_THINGS_HOST",
"DRAW_THINGS_HTTP_PORT",
"DRAW_THINGS_GRPC_PORT",
"EMBED_PNG_METADATA",
"DRAW_THINGS_CUSTOM_CONFIGS_PATH",
"HTTP_SERVER_PORT",
"CLIENT_DB_LOCATION",
];
/** Isolates a test's env mutations: snapshots every var this module reads, restores afterward. */
function withEnv(overrides, run) {
const before = Object.fromEntries(ALL_VARS.map((key) => [key, process.env[key]]));
try {
for (const key of ALL_VARS)
delete process.env[key];
for (const [key, value] of Object.entries(overrides)) {
if (value === undefined)
delete process.env[key];
else
process.env[key] = value;
}
run();
}
finally {
for (const [key, value] of Object.entries(before)) {
if (value === undefined)
delete process.env[key];
else
process.env[key] = value;
}
}
}
test("readMcpConfig uses its documented defaults when nothing is set", () => {
withEnv({}, () => {
const config = readMcpConfig();
assert.equal(config.drawThingsHost, "127.0.0.1");
assert.equal(config.drawThingsHttpPort, 7860);
assert.equal(config.drawThingsGrpcPort, 7859);
assert.equal(config.embedPngMetadata, true);
assert.match(config.customConfigsPath, /custom_configs\.json$/);
// Same unified scheme as every other bridge: bionic defaults to 54770.
assert.equal(config.httpServerPort, 54770);
assert.equal(config.preset.name, "bionic");
assert.equal(config.previewInChat, false);
});
});
test("readMcpConfig honors explicit env overrides", () => {
withEnv({
DRAW_THINGS_HOST: "10.0.0.1",
DRAW_THINGS_HTTP_PORT: "1111",
DRAW_THINGS_GRPC_PORT: "3333",
EMBED_PNG_METADATA: "false",
DRAW_THINGS_CUSTOM_CONFIGS_PATH: "/custom/custom_configs.json",
HTTP_SERVER_PORT: "9999",
}, () => {
const config = readMcpConfig();
assert.equal(config.drawThingsHost, "10.0.0.1");
assert.equal(config.drawThingsHttpPort, 1111);
assert.equal(config.drawThingsGrpcPort, 3333);
assert.equal(config.embedPngMetadata, false);
assert.equal(config.customConfigsPath, "/custom/custom_configs.json");
assert.equal(config.httpServerPort, 9999);
});
});
test("readMcpConfig prefers MCP_MADE_FOR over the deprecated MCP_MADE_FOR_BIONIC boolean", () => {
withEnv({ MCP_MADE_FOR: "generic", MCP_MADE_FOR_BIONIC: "true" }, () => {
const config = readMcpConfig();
assert.equal(config.preset.name, "generic");
assert.equal(config.previewInChat, true);
});
});
test("readMcpConfig falls back to the deprecated MCP_MADE_FOR_BIONIC boolean when MCP_MADE_FOR is unset", () => {
withEnv({ MCP_MADE_FOR_BIONIC: "false" }, () => {
const config = readMcpConfig();
assert.equal(config.preset.name, "generic");
assert.equal(config.previewInChat, true);
});
});
test("readMcpConfig defaults CHAT_WORKING_DIRECTORIES to ~/.lmstudio/scratchpads (expanded, not a literal tilde) when unset", () => {
withEnv({}, () => {
const config = readMcpConfig();
assert.match(config.chatWorkingDirectories, /^\/.*\/\.lmstudio\/scratchpads$/);
assert.ok(!config.chatWorkingDirectories.includes("~"));
});
});
test("readMcpConfig uses an explicit CHAT_WORKING_DIRECTORIES over the default", () => {
withEnv({ CHAT_WORKING_DIRECTORIES: "/tmp/explicit-scratchpads" }, () => {
const config = readMcpConfig();
assert.equal(config.chatWorkingDirectories, "/tmp/explicit-scratchpads");
});
});
test("readMcpConfig defaults CHAT_WORKING_DIRECTORIES to ~/.unsloth/studio/sandbox for the unsloth preset", () => {
withEnv({ MCP_MADE_FOR: "unsloth" }, () => {
const config = readMcpConfig();
assert.match(config.chatWorkingDirectories, /^\/.*\/\.unsloth\/studio\/sandbox$/);
});
});
test("readMcpConfig defaults CHAT_WORKING_DIRECTORIES to ~/Pictures for the generic preset", () => {
withEnv({ MCP_MADE_FOR: "generic" }, () => {
const config = readMcpConfig();
assert.match(config.chatWorkingDirectories, /^\/.*\/Pictures$/);
});
});
test("readMcpConfig defaults clientDbLocation to ~/.unsloth/studio/studio.db, overridable via CLIENT_DB_LOCATION", () => {
withEnv({}, () => {
const config = readMcpConfig();
assert.match(config.clientDbLocation, /^\/.*\/\.unsloth\/studio\/studio\.db$/);
});
withEnv({ CLIENT_DB_LOCATION: "/tmp/custom-studio.db" }, () => {
const config = readMcpConfig();
assert.equal(config.clientDbLocation, "/tmp/custom-studio.db");
});
});
test("readMcpConfig defaults HTTP_SERVER_PORT per preset (bionic 54770, unsloth 54780, generic 54790)", () => {
withEnv({}, () => {
assert.equal(readMcpConfig().httpServerPort, 54770);
});
withEnv({ MCP_MADE_FOR: "unsloth" }, () => {
assert.equal(readMcpConfig().httpServerPort, 54780);
});
withEnv({ MCP_MADE_FOR: "generic" }, () => {
assert.equal(readMcpConfig().httpServerPort, 54790);
});
withEnv({ MCP_MADE_FOR: "unsloth", HTTP_SERVER_PORT: "9999" }, () => {
assert.equal(readMcpConfig().httpServerPort, 9999);
});
});
import assert from "node:assert/strict";
import test from "node:test";
import { readMcpConfig } from "./config.js";
const ALL_VARS = [
"CHAT_WORKING_DIRECTORIES",
"MCP_MADE_FOR",
"MCP_MADE_FOR_BIONIC",
"DRAW_THINGS_HOST",
"DRAW_THINGS_HTTP_PORT",
"DRAW_THINGS_GRPC_PORT",
"EMBED_PNG_METADATA",
"DRAW_THINGS_CUSTOM_CONFIGS_PATH",
"HTTP_SERVER_PORT",
"CLIENT_DB_LOCATION",
];
/** Isolates a test's env mutations: snapshots every var this module reads, restores afterward. */
function withEnv(overrides, run) {
const before = Object.fromEntries(ALL_VARS.map((key) => [key, process.env[key]]));
try {
for (const key of ALL_VARS)
delete process.env[key];
for (const [key, value] of Object.entries(overrides)) {
if (value === undefined)
delete process.env[key];
else
process.env[key] = value;
}
run();
}
finally {
for (const [key, value] of Object.entries(before)) {
if (value === undefined)
delete process.env[key];
else
process.env[key] = value;
}
}
}
test("readMcpConfig uses its documented defaults when nothing is set", () => {
withEnv({}, () => {
const config = readMcpConfig();
assert.equal(config.drawThingsHost, "127.0.0.1");
assert.equal(config.drawThingsHttpPort, 7860);
assert.equal(config.drawThingsGrpcPort, 7859);
assert.equal(config.embedPngMetadata, true);
assert.match(config.customConfigsPath, /custom_configs\.json$/);
// Same unified scheme as every other bridge: bionic defaults to 54770.
assert.equal(config.httpServerPort, 54770);
assert.equal(config.preset.name, "bionic");
assert.equal(config.previewInChat, false);
});
});
test("readMcpConfig honors explicit env overrides", () => {
withEnv({
DRAW_THINGS_HOST: "10.0.0.1",
DRAW_THINGS_HTTP_PORT: "1111",
DRAW_THINGS_GRPC_PORT: "3333",
EMBED_PNG_METADATA: "false",
DRAW_THINGS_CUSTOM_CONFIGS_PATH: "/custom/custom_configs.json",
HTTP_SERVER_PORT: "9999",
}, () => {
const config = readMcpConfig();
assert.equal(config.drawThingsHost, "10.0.0.1");
assert.equal(config.drawThingsHttpPort, 1111);
assert.equal(config.drawThingsGrpcPort, 3333);
assert.equal(config.embedPngMetadata, false);
assert.equal(config.customConfigsPath, "/custom/custom_configs.json");
assert.equal(config.httpServerPort, 9999);
});
});
test("readMcpConfig prefers MCP_MADE_FOR over the deprecated MCP_MADE_FOR_BIONIC boolean", () => {
withEnv({ MCP_MADE_FOR: "generic", MCP_MADE_FOR_BIONIC: "true" }, () => {
const config = readMcpConfig();
assert.equal(config.preset.name, "generic");
assert.equal(config.previewInChat, true);
});
});
test("readMcpConfig falls back to the deprecated MCP_MADE_FOR_BIONIC boolean when MCP_MADE_FOR is unset", () => {
withEnv({ MCP_MADE_FOR_BIONIC: "false" }, () => {
const config = readMcpConfig();
assert.equal(config.preset.name, "generic");
assert.equal(config.previewInChat, true);
});
});
test("readMcpConfig defaults CHAT_WORKING_DIRECTORIES to ~/.lmstudio/scratchpads (expanded, not a literal tilde) when unset", () => {
withEnv({}, () => {
const config = readMcpConfig();
assert.match(config.chatWorkingDirectories, /^\/.*\/\.lmstudio\/scratchpads$/);
assert.ok(!config.chatWorkingDirectories.includes("~"));
});
});
test("readMcpConfig uses an explicit CHAT_WORKING_DIRECTORIES over the default", () => {
withEnv({ CHAT_WORKING_DIRECTORIES: "/tmp/explicit-scratchpads" }, () => {
const config = readMcpConfig();
assert.equal(config.chatWorkingDirectories, "/tmp/explicit-scratchpads");
});
});
test("readMcpConfig defaults CHAT_WORKING_DIRECTORIES to ~/.unsloth/studio/sandbox for the unsloth preset", () => {
withEnv({ MCP_MADE_FOR: "unsloth" }, () => {
const config = readMcpConfig();
assert.match(config.chatWorkingDirectories, /^\/.*\/\.unsloth\/studio\/sandbox$/);
});
});
test("readMcpConfig defaults CHAT_WORKING_DIRECTORIES to ~/Pictures for the generic preset", () => {
withEnv({ MCP_MADE_FOR: "generic" }, () => {
const config = readMcpConfig();
assert.match(config.chatWorkingDirectories, /^\/.*\/Pictures$/);
});
});
test("readMcpConfig defaults clientDbLocation to ~/.unsloth/studio/studio.db, overridable via CLIENT_DB_LOCATION", () => {
withEnv({}, () => {
const config = readMcpConfig();
assert.match(config.clientDbLocation, /^\/.*\/\.unsloth\/studio\/studio\.db$/);
});
withEnv({ CLIENT_DB_LOCATION: "/tmp/custom-studio.db" }, () => {
const config = readMcpConfig();
assert.equal(config.clientDbLocation, "/tmp/custom-studio.db");
});
});
test("readMcpConfig defaults HTTP_SERVER_PORT per preset (bionic 54770, unsloth 54780, generic 54790)", () => {
withEnv({}, () => {
assert.equal(readMcpConfig().httpServerPort, 54770);
});
withEnv({ MCP_MADE_FOR: "unsloth" }, () => {
assert.equal(readMcpConfig().httpServerPort, 54780);
});
withEnv({ MCP_MADE_FOR: "generic" }, () => {
assert.equal(readMcpConfig().httpServerPort, 54790);
});
withEnv({ MCP_MADE_FOR: "unsloth", HTTP_SERVER_PORT: "9999" }, () => {
assert.equal(readMcpConfig().httpServerPort, 9999);
});
});