dist-mcp / mcp / config.test.js
dist-mcp / mcp / config.test.js
import assert from "node:assert/strict";
import test from "node:test";
import { applyMcpConfig, readMcpConfig } from "./config.js";
const ALL_VARS = [
"CHAT_WORKING_DIRECTORIES",
"MCP_MADE_FOR",
"MCP_MADE_FOR_BIONIC",
"VISION_API",
"VISION_API_BASE_URL",
"VISION_API_KEY",
"QWEN3_VL_MODEL",
"LLAMA_SERVER_BINARY",
"LLAMA_SERVER_PORT",
"LLAMA_SERVER_CTX_SIZE",
"LLAMA_SERVER_MODELS_MAX",
"LLAMA_SERVER_IDLE_TTL_MINUTES",
"EMBED_PNG_METADATA",
"INCLUDE_GENERATION_METADATA",
"CLIENT_DB_LOCATION",
"HTTP_SERVER_PORT",
];
/** 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.visionApiBaseUrl, "http://127.0.0.1:1234/v1");
assert.equal(config.visionApiKey, "");
assert.equal(config.qwen3VlModel, "qwen/qwen3-vl-8b");
assert.equal(config.embedPngMetadata, true);
assert.equal(config.includeGenerationMetadata, true);
assert.equal(config.preset.name, "bionic");
});
});
test("readMcpConfig honors explicit env overrides", () => {
withEnv({
VISION_API_BASE_URL: "http://10.0.0.1:1234/v1",
VISION_API_KEY: "secret",
QWEN3_VL_MODEL: "qwen/qwen3-vl-4b",
EMBED_PNG_METADATA: "false",
INCLUDE_GENERATION_METADATA: "false",
}, () => {
const config = readMcpConfig();
assert.equal(config.visionApiBaseUrl, "http://10.0.0.1:1234/v1");
assert.equal(config.visionApiKey, "secret");
assert.equal(config.qwen3VlModel, "qwen/qwen3-vl-4b");
assert.equal(config.embedPngMetadata, false);
assert.equal(config.includeGenerationMetadata, false);
});
});
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");
});
});
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 VISION_API_BASE_URL/QWEN3_VL_MODEL to Unsloth Studio's own server/model for the unsloth preset", () => {
withEnv({ MCP_MADE_FOR: "unsloth" }, () => {
const config = readMcpConfig();
assert.equal(config.visionApiBaseUrl, "http://127.0.0.1:8888/v1");
assert.equal(config.qwen3VlModel, "unsloth/Qwen3-VL-8B-Instruct-GGUF");
});
});
test("readMcpConfig honors explicit VISION_API_BASE_URL/QWEN3_VL_MODEL overrides for the unsloth preset", () => {
withEnv({ MCP_MADE_FOR: "unsloth", VISION_API_BASE_URL: "http://10.0.0.1:8888/v1", QWEN3_VL_MODEL: "Qwen3-VL-4B-Instruct-GGUF" }, () => {
const config = readMcpConfig();
assert.equal(config.visionApiBaseUrl, "http://10.0.0.1:8888/v1");
assert.equal(config.qwen3VlModel, "Qwen3-VL-4B-Instruct-GGUF");
});
});
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("applyMcpConfig sets LMSTUDIO_VISION_API to each preset's default VISION_API strand", () => {
const before = process.env.LMSTUDIO_VISION_API;
try {
withEnv({ MCP_MADE_FOR: "unsloth" }, () => {
applyMcpConfig(readMcpConfig());
assert.equal(process.env.LMSTUDIO_VISION_API, "llama-server");
});
withEnv({}, () => {
applyMcpConfig(readMcpConfig());
assert.equal(process.env.LMSTUDIO_VISION_API, "bionic");
});
}
finally {
if (before === undefined)
delete process.env.LMSTUDIO_VISION_API;
else
process.env.LMSTUDIO_VISION_API = before;
}
});
test("readMcpConfig defaults visionApi per preset (bionic defaults to its own name; generic/unsloth default to llama-server since their native load-then-verify strategies proved unreliable)", () => {
withEnv({}, () => {
assert.equal(readMcpConfig().visionApi, "bionic");
});
withEnv({ MCP_MADE_FOR: "generic" }, () => {
assert.equal(readMcpConfig().visionApi, "llama-server");
});
withEnv({ MCP_MADE_FOR: "unsloth" }, () => {
assert.equal(readMcpConfig().visionApi, "llama-server");
});
});
test("readMcpConfig honors an explicit VISION_API override that disagrees with MCP_MADE_FOR (e.g. a bionic client pointed at a plain OpenAI-compatible server)", () => {
withEnv({ MCP_MADE_FOR: "bionic", VISION_API: "generic" }, () => {
assert.equal(readMcpConfig().visionApi, "generic");
assert.equal(readMcpConfig().preset.name, "bionic");
});
});
test("readMcpConfig falls back to the preset's default VISION_API strand on an unrecognized VISION_API value", () => {
withEnv({ MCP_MADE_FOR: "unsloth", VISION_API: "not-a-real-adapter" }, () => {
assert.equal(readMcpConfig().visionApi, "llama-server");
});
});
test("readMcpConfig honors an explicit VISION_API=llama-server override regardless of preset", () => {
withEnv({ MCP_MADE_FOR: "bionic", VISION_API: "llama-server" }, () => {
assert.equal(readMcpConfig().visionApi, "llama-server");
});
});
test("readMcpConfig defaults LLAMA_SERVER_BINARY per preset", () => {
withEnv({}, () => {
assert.match(readMcpConfig().llamaServerBinary, /\.lmstudio\/extensions\/backends\/llama\.cpp-mac-arm64-apple-metal-advsimd-2\.48\.0\/llama-server$/);
});
withEnv({ MCP_MADE_FOR: "generic" }, () => {
assert.match(readMcpConfig().llamaServerBinary, /\.lmstudio\/extensions\/backends\/qwen3-vl-embedding\/llama-server$/);
});
withEnv({ MCP_MADE_FOR: "unsloth" }, () => {
assert.match(readMcpConfig().llamaServerBinary, /\.unsloth\/llama\.cpp\/llama-server$/);
});
});
test("readMcpConfig honors an explicit LLAMA_SERVER_BINARY override", () => {
withEnv({ LLAMA_SERVER_BINARY: "/tmp/custom-llama-server" }, () => {
assert.equal(readMcpConfig().llamaServerBinary, "/tmp/custom-llama-server");
});
});
test("applyMcpConfig sets LMSTUDIO_LLAMA_SERVER_BINARY to the resolved value", () => {
const before = process.env.LMSTUDIO_LLAMA_SERVER_BINARY;
try {
withEnv({ LLAMA_SERVER_BINARY: "/tmp/custom-llama-server" }, () => {
applyMcpConfig(readMcpConfig());
assert.equal(process.env.LMSTUDIO_LLAMA_SERVER_BINARY, "/tmp/custom-llama-server");
});
}
finally {
if (before === undefined)
delete process.env.LMSTUDIO_LLAMA_SERVER_BINARY;
else
process.env.LMSTUDIO_LLAMA_SERVER_BINARY = before;
}
});
test("readMcpConfig defaults llamaServerCtxSize/llamaServerModelsMax/llamaServerIdleTtlMinutes (no hardcodes -- same defaults src/config.ts documents)", () => {
withEnv({}, () => {
const config = readMcpConfig();
assert.equal(config.llamaServerCtxSize, 8192);
assert.equal(config.llamaServerModelsMax, 1);
assert.equal(config.llamaServerIdleTtlMinutes, 10);
});
});
test("readMcpConfig defaults llamaServerPort to 8099, independent of visionApiBaseUrl", () => {
withEnv({}, () => {
assert.equal(readMcpConfig().llamaServerPort, 8099);
});
withEnv({ MCP_MADE_FOR: "unsloth" }, () => {
assert.equal(readMcpConfig().llamaServerPort, 8099);
assert.equal(readMcpConfig().visionApiBaseUrl, "http://127.0.0.1:8888/v1");
});
});
test("readMcpConfig honors an explicit LLAMA_SERVER_PORT override", () => {
withEnv({ LLAMA_SERVER_PORT: "9100" }, () => {
assert.equal(readMcpConfig().llamaServerPort, 9100);
});
});
test("applyMcpConfig sets LMSTUDIO_LLAMA_SERVER_PORT to the resolved value", () => {
const before = process.env.LMSTUDIO_LLAMA_SERVER_PORT;
try {
withEnv({ LLAMA_SERVER_PORT: "9100" }, () => {
applyMcpConfig(readMcpConfig());
assert.equal(process.env.LMSTUDIO_LLAMA_SERVER_PORT, "9100");
});
}
finally {
if (before === undefined)
delete process.env.LMSTUDIO_LLAMA_SERVER_PORT;
else
process.env.LMSTUDIO_LLAMA_SERVER_PORT = before;
}
});
test("readMcpConfig honors explicit LLAMA_SERVER_CTX_SIZE/LLAMA_SERVER_MODELS_MAX/LLAMA_SERVER_IDLE_TTL_MINUTES overrides", () => {
withEnv({ LLAMA_SERVER_CTX_SIZE: "4096", LLAMA_SERVER_MODELS_MAX: "2", LLAMA_SERVER_IDLE_TTL_MINUTES: "0" }, () => {
const config = readMcpConfig();
assert.equal(config.llamaServerCtxSize, 4096);
assert.equal(config.llamaServerModelsMax, 2);
assert.equal(config.llamaServerIdleTtlMinutes, 0);
});
});
test("applyMcpConfig sets LMSTUDIO_LLAMA_SERVER_CTX_SIZE/MODELS_MAX/IDLE_TTL_MINUTES to the resolved values", () => {
const before = {
ctxSize: process.env.LMSTUDIO_LLAMA_SERVER_CTX_SIZE,
modelsMax: process.env.LMSTUDIO_LLAMA_SERVER_MODELS_MAX,
idleTtlMinutes: process.env.LMSTUDIO_LLAMA_SERVER_IDLE_TTL_MINUTES,
};
try {
withEnv({ LLAMA_SERVER_CTX_SIZE: "4096", LLAMA_SERVER_MODELS_MAX: "2", LLAMA_SERVER_IDLE_TTL_MINUTES: "0" }, () => {
applyMcpConfig(readMcpConfig());
assert.equal(process.env.LMSTUDIO_LLAMA_SERVER_CTX_SIZE, "4096");
assert.equal(process.env.LMSTUDIO_LLAMA_SERVER_MODELS_MAX, "2");
assert.equal(process.env.LMSTUDIO_LLAMA_SERVER_IDLE_TTL_MINUTES, "0");
});
}
finally {
for (const [key, value] of Object.entries({
LMSTUDIO_LLAMA_SERVER_CTX_SIZE: before.ctxSize,
LMSTUDIO_LLAMA_SERVER_MODELS_MAX: before.modelsMax,
LMSTUDIO_LLAMA_SERVER_IDLE_TTL_MINUTES: before.idleTtlMinutes,
})) {
if (value === undefined)
delete process.env[key];
else
process.env[key] = value;
}
}
});
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);
});
});
test("readMcpConfig honors an explicit HTTP_SERVER_PORT override", () => {
withEnv({ HTTP_SERVER_PORT: "9999" }, () => {
assert.equal(readMcpConfig().httpServerPort, 9999);
});
});
test("applyMcpConfig sets process.env.HTTP_SERVER_PORT to the resolved value", () => {
const before = process.env.HTTP_SERVER_PORT;
try {
withEnv({ HTTP_SERVER_PORT: "9999" }, () => {
applyMcpConfig(readMcpConfig());
assert.equal(process.env.HTTP_SERVER_PORT, "9999");
});
}
finally {
if (before === undefined)
delete process.env.HTTP_SERVER_PORT;
else
process.env.HTTP_SERVER_PORT = before;
}
});
import assert from "node:assert/strict";
import test from "node:test";
import { applyMcpConfig, readMcpConfig } from "./config.js";
const ALL_VARS = [
"CHAT_WORKING_DIRECTORIES",
"MCP_MADE_FOR",
"MCP_MADE_FOR_BIONIC",
"VISION_API",
"VISION_API_BASE_URL",
"VISION_API_KEY",
"QWEN3_VL_MODEL",
"LLAMA_SERVER_BINARY",
"LLAMA_SERVER_PORT",
"LLAMA_SERVER_CTX_SIZE",
"LLAMA_SERVER_MODELS_MAX",
"LLAMA_SERVER_IDLE_TTL_MINUTES",
"EMBED_PNG_METADATA",
"INCLUDE_GENERATION_METADATA",
"CLIENT_DB_LOCATION",
"HTTP_SERVER_PORT",
];
/** 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.visionApiBaseUrl, "http://127.0.0.1:1234/v1");
assert.equal(config.visionApiKey, "");
assert.equal(config.qwen3VlModel, "qwen/qwen3-vl-8b");
assert.equal(config.embedPngMetadata, true);
assert.equal(config.includeGenerationMetadata, true);
assert.equal(config.preset.name, "bionic");
});
});
test("readMcpConfig honors explicit env overrides", () => {
withEnv({
VISION_API_BASE_URL: "http://10.0.0.1:1234/v1",
VISION_API_KEY: "secret",
QWEN3_VL_MODEL: "qwen/qwen3-vl-4b",
EMBED_PNG_METADATA: "false",
INCLUDE_GENERATION_METADATA: "false",
}, () => {
const config = readMcpConfig();
assert.equal(config.visionApiBaseUrl, "http://10.0.0.1:1234/v1");
assert.equal(config.visionApiKey, "secret");
assert.equal(config.qwen3VlModel, "qwen/qwen3-vl-4b");
assert.equal(config.embedPngMetadata, false);
assert.equal(config.includeGenerationMetadata, false);
});
});
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");
});
});
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 VISION_API_BASE_URL/QWEN3_VL_MODEL to Unsloth Studio's own server/model for the unsloth preset", () => {
withEnv({ MCP_MADE_FOR: "unsloth" }, () => {
const config = readMcpConfig();
assert.equal(config.visionApiBaseUrl, "http://127.0.0.1:8888/v1");
assert.equal(config.qwen3VlModel, "unsloth/Qwen3-VL-8B-Instruct-GGUF");
});
});
test("readMcpConfig honors explicit VISION_API_BASE_URL/QWEN3_VL_MODEL overrides for the unsloth preset", () => {
withEnv({ MCP_MADE_FOR: "unsloth", VISION_API_BASE_URL: "http://10.0.0.1:8888/v1", QWEN3_VL_MODEL: "Qwen3-VL-4B-Instruct-GGUF" }, () => {
const config = readMcpConfig();
assert.equal(config.visionApiBaseUrl, "http://10.0.0.1:8888/v1");
assert.equal(config.qwen3VlModel, "Qwen3-VL-4B-Instruct-GGUF");
});
});
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("applyMcpConfig sets LMSTUDIO_VISION_API to each preset's default VISION_API strand", () => {
const before = process.env.LMSTUDIO_VISION_API;
try {
withEnv({ MCP_MADE_FOR: "unsloth" }, () => {
applyMcpConfig(readMcpConfig());
assert.equal(process.env.LMSTUDIO_VISION_API, "llama-server");
});
withEnv({}, () => {
applyMcpConfig(readMcpConfig());
assert.equal(process.env.LMSTUDIO_VISION_API, "bionic");
});
}
finally {
if (before === undefined)
delete process.env.LMSTUDIO_VISION_API;
else
process.env.LMSTUDIO_VISION_API = before;
}
});
test("readMcpConfig defaults visionApi per preset (bionic defaults to its own name; generic/unsloth default to llama-server since their native load-then-verify strategies proved unreliable)", () => {
withEnv({}, () => {
assert.equal(readMcpConfig().visionApi, "bionic");
});
withEnv({ MCP_MADE_FOR: "generic" }, () => {
assert.equal(readMcpConfig().visionApi, "llama-server");
});
withEnv({ MCP_MADE_FOR: "unsloth" }, () => {
assert.equal(readMcpConfig().visionApi, "llama-server");
});
});
test("readMcpConfig honors an explicit VISION_API override that disagrees with MCP_MADE_FOR (e.g. a bionic client pointed at a plain OpenAI-compatible server)", () => {
withEnv({ MCP_MADE_FOR: "bionic", VISION_API: "generic" }, () => {
assert.equal(readMcpConfig().visionApi, "generic");
assert.equal(readMcpConfig().preset.name, "bionic");
});
});
test("readMcpConfig falls back to the preset's default VISION_API strand on an unrecognized VISION_API value", () => {
withEnv({ MCP_MADE_FOR: "unsloth", VISION_API: "not-a-real-adapter" }, () => {
assert.equal(readMcpConfig().visionApi, "llama-server");
});
});
test("readMcpConfig honors an explicit VISION_API=llama-server override regardless of preset", () => {
withEnv({ MCP_MADE_FOR: "bionic", VISION_API: "llama-server" }, () => {
assert.equal(readMcpConfig().visionApi, "llama-server");
});
});
test("readMcpConfig defaults LLAMA_SERVER_BINARY per preset", () => {
withEnv({}, () => {
assert.match(readMcpConfig().llamaServerBinary, /\.lmstudio\/extensions\/backends\/llama\.cpp-mac-arm64-apple-metal-advsimd-2\.48\.0\/llama-server$/);
});
withEnv({ MCP_MADE_FOR: "generic" }, () => {
assert.match(readMcpConfig().llamaServerBinary, /\.lmstudio\/extensions\/backends\/qwen3-vl-embedding\/llama-server$/);
});
withEnv({ MCP_MADE_FOR: "unsloth" }, () => {
assert.match(readMcpConfig().llamaServerBinary, /\.unsloth\/llama\.cpp\/llama-server$/);
});
});
test("readMcpConfig honors an explicit LLAMA_SERVER_BINARY override", () => {
withEnv({ LLAMA_SERVER_BINARY: "/tmp/custom-llama-server" }, () => {
assert.equal(readMcpConfig().llamaServerBinary, "/tmp/custom-llama-server");
});
});
test("applyMcpConfig sets LMSTUDIO_LLAMA_SERVER_BINARY to the resolved value", () => {
const before = process.env.LMSTUDIO_LLAMA_SERVER_BINARY;
try {
withEnv({ LLAMA_SERVER_BINARY: "/tmp/custom-llama-server" }, () => {
applyMcpConfig(readMcpConfig());
assert.equal(process.env.LMSTUDIO_LLAMA_SERVER_BINARY, "/tmp/custom-llama-server");
});
}
finally {
if (before === undefined)
delete process.env.LMSTUDIO_LLAMA_SERVER_BINARY;
else
process.env.LMSTUDIO_LLAMA_SERVER_BINARY = before;
}
});
test("readMcpConfig defaults llamaServerCtxSize/llamaServerModelsMax/llamaServerIdleTtlMinutes (no hardcodes -- same defaults src/config.ts documents)", () => {
withEnv({}, () => {
const config = readMcpConfig();
assert.equal(config.llamaServerCtxSize, 8192);
assert.equal(config.llamaServerModelsMax, 1);
assert.equal(config.llamaServerIdleTtlMinutes, 10);
});
});
test("readMcpConfig defaults llamaServerPort to 8099, independent of visionApiBaseUrl", () => {
withEnv({}, () => {
assert.equal(readMcpConfig().llamaServerPort, 8099);
});
withEnv({ MCP_MADE_FOR: "unsloth" }, () => {
assert.equal(readMcpConfig().llamaServerPort, 8099);
assert.equal(readMcpConfig().visionApiBaseUrl, "http://127.0.0.1:8888/v1");
});
});
test("readMcpConfig honors an explicit LLAMA_SERVER_PORT override", () => {
withEnv({ LLAMA_SERVER_PORT: "9100" }, () => {
assert.equal(readMcpConfig().llamaServerPort, 9100);
});
});
test("applyMcpConfig sets LMSTUDIO_LLAMA_SERVER_PORT to the resolved value", () => {
const before = process.env.LMSTUDIO_LLAMA_SERVER_PORT;
try {
withEnv({ LLAMA_SERVER_PORT: "9100" }, () => {
applyMcpConfig(readMcpConfig());
assert.equal(process.env.LMSTUDIO_LLAMA_SERVER_PORT, "9100");
});
}
finally {
if (before === undefined)
delete process.env.LMSTUDIO_LLAMA_SERVER_PORT;
else
process.env.LMSTUDIO_LLAMA_SERVER_PORT = before;
}
});
test("readMcpConfig honors explicit LLAMA_SERVER_CTX_SIZE/LLAMA_SERVER_MODELS_MAX/LLAMA_SERVER_IDLE_TTL_MINUTES overrides", () => {
withEnv({ LLAMA_SERVER_CTX_SIZE: "4096", LLAMA_SERVER_MODELS_MAX: "2", LLAMA_SERVER_IDLE_TTL_MINUTES: "0" }, () => {
const config = readMcpConfig();
assert.equal(config.llamaServerCtxSize, 4096);
assert.equal(config.llamaServerModelsMax, 2);
assert.equal(config.llamaServerIdleTtlMinutes, 0);
});
});
test("applyMcpConfig sets LMSTUDIO_LLAMA_SERVER_CTX_SIZE/MODELS_MAX/IDLE_TTL_MINUTES to the resolved values", () => {
const before = {
ctxSize: process.env.LMSTUDIO_LLAMA_SERVER_CTX_SIZE,
modelsMax: process.env.LMSTUDIO_LLAMA_SERVER_MODELS_MAX,
idleTtlMinutes: process.env.LMSTUDIO_LLAMA_SERVER_IDLE_TTL_MINUTES,
};
try {
withEnv({ LLAMA_SERVER_CTX_SIZE: "4096", LLAMA_SERVER_MODELS_MAX: "2", LLAMA_SERVER_IDLE_TTL_MINUTES: "0" }, () => {
applyMcpConfig(readMcpConfig());
assert.equal(process.env.LMSTUDIO_LLAMA_SERVER_CTX_SIZE, "4096");
assert.equal(process.env.LMSTUDIO_LLAMA_SERVER_MODELS_MAX, "2");
assert.equal(process.env.LMSTUDIO_LLAMA_SERVER_IDLE_TTL_MINUTES, "0");
});
}
finally {
for (const [key, value] of Object.entries({
LMSTUDIO_LLAMA_SERVER_CTX_SIZE: before.ctxSize,
LMSTUDIO_LLAMA_SERVER_MODELS_MAX: before.modelsMax,
LMSTUDIO_LLAMA_SERVER_IDLE_TTL_MINUTES: before.idleTtlMinutes,
})) {
if (value === undefined)
delete process.env[key];
else
process.env[key] = value;
}
}
});
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);
});
});
test("readMcpConfig honors an explicit HTTP_SERVER_PORT override", () => {
withEnv({ HTTP_SERVER_PORT: "9999" }, () => {
assert.equal(readMcpConfig().httpServerPort, 9999);
});
});
test("applyMcpConfig sets process.env.HTTP_SERVER_PORT to the resolved value", () => {
const before = process.env.HTTP_SERVER_PORT;
try {
withEnv({ HTTP_SERVER_PORT: "9999" }, () => {
applyMcpConfig(readMcpConfig());
assert.equal(process.env.HTTP_SERVER_PORT, "9999");
});
}
finally {
if (before === undefined)
delete process.env.HTTP_SERVER_PORT;
else
process.env.HTTP_SERVER_PORT = before;
}
});