Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

### Fixed

- Restrict the generated MCP configuration to owner read/write permissions on POSIX systems before persisting authentication credentials.
- Include source-backed JSON fact documents in `!storage` profile file counts.
- Refuse to save pending Discord messages through symbolic-link destinations.
- Protect legacy and source-backed user/server memory reads and writes from symbolic links, junctions, and path swaps.
Expand Down
12 changes: 11 additions & 1 deletion src/mcp/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,17 @@ export function writeMcpConfig() {
const config = {
mcpServers,
};
fs.writeFileSync(MCP_CONFIG_PATH, JSON.stringify(config, null, 2), "utf-8");
const fileDescriptor = fs.openSync(MCP_CONFIG_PATH, "w", 0o600);
try {
fs.fchmodSync(fileDescriptor, 0o600);
fs.writeFileSync(
fileDescriptor,
JSON.stringify(config, null, 2),
"utf-8",
);
} finally {
fs.closeSync(fileDescriptor);
}
console.error(`[MCP] Config written to ${MCP_CONFIG_PATH}`);
}

Expand Down
10 changes: 7 additions & 3 deletions tests/mcpHttp.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,11 @@ test("generated MCP config includes authenticated Morpheus HTTP transport", () =
);
const moduleUrl = new URL("../build/mcp/http.js", import.meta.url).href;
const apiKey = "test-morpheus-api-key";
const configPath = path.join(workingDir, ".mcp-config.json");

try {
fs.writeFileSync(configPath, "stale config", { mode: 0o666 });
fs.chmodSync(configPath, 0o666);
const result = spawnSync(
process.execPath,
[
Expand All @@ -128,16 +131,17 @@ test("generated MCP config includes authenticated Morpheus HTTP transport", () =

assert.equal(result.status, 0, result.stderr);
assert.doesNotMatch(result.stderr, new RegExp(apiKey));
const config = JSON.parse(
fs.readFileSync(path.join(workingDir, ".mcp-config.json"), "utf8"),
);
const config = JSON.parse(fs.readFileSync(configPath, "utf8"));
assert.deepEqual(config.mcpServers.morpheus, {
type: "http",
url: "http://morpheus_bot_prod:5268/api/mcp",
headers: {
Authorization: `Bearer ${apiKey}`,
},
});
if (process.platform !== "win32") {
assert.equal(fs.statSync(configPath).mode & 0o777, 0o600);
}
} finally {
fs.rmSync(workingDir, { recursive: true, force: true });
}
Expand Down