@prom.codes/memory-mcp 0.2.1 → 0.3.1
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/dist/bin.js +80 -16
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// dist/bin.js
|
|
4
|
+
import { McpServer as McpServer2 } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
4
5
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
5
6
|
|
|
6
7
|
// dist/composition.js
|
|
@@ -1150,7 +1151,10 @@ function discoverMemoryEmbedder(env) {
|
|
|
1150
1151
|
}
|
|
1151
1152
|
function composeFromEnv(opts) {
|
|
1152
1153
|
const env = opts.env;
|
|
1153
|
-
const
|
|
1154
|
+
const override = (opts.workspaceRootOverride ?? "").trim();
|
|
1155
|
+
const envRoot = (env.PROMETHEUS_WORKSPACE_ROOT ?? "").trim();
|
|
1156
|
+
const claudeRoot = (env.CLAUDE_PROJECT_DIR ?? "").trim();
|
|
1157
|
+
const workspaceRoot = resolve(override !== "" ? override : envRoot !== "" ? envRoot : claudeRoot !== "" ? claudeRoot : process.cwd());
|
|
1154
1158
|
const projectId = projectIdFor(workspaceRoot);
|
|
1155
1159
|
const projectName = basename(workspaceRoot) || workspaceRoot;
|
|
1156
1160
|
const rawDbPath = env.PROMETHEUS_MEMORY_DB_PATH;
|
|
@@ -1169,6 +1173,36 @@ function composeFromEnv(opts) {
|
|
|
1169
1173
|
};
|
|
1170
1174
|
}
|
|
1171
1175
|
|
|
1176
|
+
// dist/roots.js
|
|
1177
|
+
import { fileURLToPath } from "node:url";
|
|
1178
|
+
async function rootFromClient(server, timeoutMs = 2500) {
|
|
1179
|
+
let supportsRoots = false;
|
|
1180
|
+
try {
|
|
1181
|
+
supportsRoots = server.getClientCapabilities()?.roots != null;
|
|
1182
|
+
} catch {
|
|
1183
|
+
return null;
|
|
1184
|
+
}
|
|
1185
|
+
if (!supportsRoots)
|
|
1186
|
+
return null;
|
|
1187
|
+
let res;
|
|
1188
|
+
try {
|
|
1189
|
+
res = await server.listRoots(void 0, { timeout: timeoutMs });
|
|
1190
|
+
} catch {
|
|
1191
|
+
return null;
|
|
1192
|
+
}
|
|
1193
|
+
const roots = res?.roots ?? [];
|
|
1194
|
+
for (const r of roots) {
|
|
1195
|
+
const uri = typeof r?.uri === "string" ? r.uri : "";
|
|
1196
|
+
if (uri.startsWith("file://")) {
|
|
1197
|
+
try {
|
|
1198
|
+
return fileURLToPath(uri);
|
|
1199
|
+
} catch {
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
return null;
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1172
1206
|
// dist/server.js
|
|
1173
1207
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
1174
1208
|
|
|
@@ -1722,37 +1756,67 @@ var SERVER_IDENTITY = {
|
|
|
1722
1756
|
title: "prom.codes Memory"
|
|
1723
1757
|
};
|
|
1724
1758
|
var SERVER_INSTRUCTIONS = "Persistent agent memory for this workspace. At the START of a session or task, call memory_read to recall facts, decisions and procedures from earlier sessions. When the user states a durable preference, decision or correction, store it with memory_write. Use memory_search for keyword recall when memory_read is not specific enough. At the END of a session, consolidate what was learned with memory_capture. Run memory_setup once per workspace to install the memory protocol into runtime rule files. Never store secrets, API keys or credentials \u2014 such writes are rejected.";
|
|
1725
|
-
function createServer(deps, options = {}) {
|
|
1726
|
-
const identity = { ...SERVER_IDENTITY, ...options.identity ?? {} };
|
|
1727
|
-
const capabilities = options.capabilities ?? { tools: {} };
|
|
1728
|
-
const server = new McpServer(identity, {
|
|
1729
|
-
capabilities,
|
|
1730
|
-
instructions: SERVER_INSTRUCTIONS
|
|
1731
|
-
});
|
|
1732
|
-
registerTools(server, deps);
|
|
1733
|
-
return server;
|
|
1734
|
-
}
|
|
1735
1759
|
|
|
1736
1760
|
// dist/bin.js
|
|
1737
1761
|
async function main() {
|
|
1738
|
-
const
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
const
|
|
1762
|
+
const env = process.env;
|
|
1763
|
+
const explicitRoot = (env.PROMETHEUS_WORKSPACE_ROOT ?? "").trim();
|
|
1764
|
+
const claudeRoot = (env.CLAUDE_PROJECT_DIR ?? "").trim();
|
|
1765
|
+
const eagerVia = explicitRoot !== "" ? "PROMETHEUS_WORKSPACE_ROOT" : claudeRoot !== "" ? "CLAUDE_PROJECT_DIR" : null;
|
|
1742
1766
|
const transport = new StdioServerTransport();
|
|
1767
|
+
const server = new McpServer2(SERVER_IDENTITY, {
|
|
1768
|
+
capabilities: { tools: {} },
|
|
1769
|
+
instructions: SERVER_INSTRUCTIONS
|
|
1770
|
+
});
|
|
1771
|
+
let composed = null;
|
|
1743
1772
|
const shutdown = async (signal) => {
|
|
1744
1773
|
process.stderr.write(`prometheus-memory-mcp: received ${signal}, shutting down
|
|
1745
1774
|
`);
|
|
1746
1775
|
try {
|
|
1747
1776
|
await server.close();
|
|
1748
1777
|
} finally {
|
|
1749
|
-
|
|
1778
|
+
if (composed !== null)
|
|
1779
|
+
await composed.close();
|
|
1750
1780
|
process.exit(0);
|
|
1751
1781
|
}
|
|
1752
1782
|
};
|
|
1753
1783
|
process.once("SIGINT", shutdown);
|
|
1754
1784
|
process.once("SIGTERM", shutdown);
|
|
1785
|
+
const boot = (override, via) => {
|
|
1786
|
+
composed = composeFromEnv({
|
|
1787
|
+
env,
|
|
1788
|
+
...override !== void 0 && override !== "" ? { workspaceRootOverride: override } : {}
|
|
1789
|
+
});
|
|
1790
|
+
process.stderr.write(`prometheus-memory-mcp: workspace=${composed.workspaceRoot} (via ${via}) project=${composed.projectName} (${composed.projectId}) db=${composed.dbPath} embed=${composed.embedderId}${composed.embeddingsEnabled ? "" : " (keyword-only)"}
|
|
1791
|
+
`);
|
|
1792
|
+
registerTools(server, composed);
|
|
1793
|
+
};
|
|
1794
|
+
if (eagerVia !== null) {
|
|
1795
|
+
boot(void 0, eagerVia);
|
|
1796
|
+
await server.connect(transport);
|
|
1797
|
+
return;
|
|
1798
|
+
}
|
|
1799
|
+
let booted = false;
|
|
1800
|
+
const resolveAndBoot = async () => {
|
|
1801
|
+
if (booted)
|
|
1802
|
+
return;
|
|
1803
|
+
booted = true;
|
|
1804
|
+
try {
|
|
1805
|
+
const fromRoots = await rootFromClient(server.server);
|
|
1806
|
+
boot(fromRoots ?? process.cwd(), fromRoots !== null ? "MCP roots" : "cwd fallback (client advertised no roots)");
|
|
1807
|
+
} catch (err) {
|
|
1808
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
1809
|
+
process.stderr.write(`prometheus-memory-mcp: fatal during boot: ${message}
|
|
1810
|
+
`);
|
|
1811
|
+
process.exit(1);
|
|
1812
|
+
}
|
|
1813
|
+
};
|
|
1814
|
+
server.server.oninitialized = () => {
|
|
1815
|
+
void resolveAndBoot();
|
|
1816
|
+
};
|
|
1755
1817
|
await server.connect(transport);
|
|
1818
|
+
const t = setTimeout(() => void resolveAndBoot(), 5e3);
|
|
1819
|
+
t.unref?.();
|
|
1756
1820
|
}
|
|
1757
1821
|
main().catch((err) => {
|
|
1758
1822
|
const message = err instanceof Error ? err.message : String(err);
|