Skip to content
Open
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
5 changes: 4 additions & 1 deletion .cursor/mcp.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
"mcpServers": {
"supermemory": {
"command": "bunx",
"args": [ "cursor-supermemory@latest", "mcp"]
"args": ["cursor-supermemory@latest", "mcp"],
"env": {
"SUPERMEMORY_WORKSPACE_ROOT": "${workspaceFolder}"
}
}
}
}
5 changes: 4 additions & 1 deletion .mcp.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
"mcpServers": {
"supermemory": {
"command": "bunx",
"args": ["--bun", "cursor-supermemory@latest", "mcp"]
"args": ["--bun", "cursor-supermemory@latest", "mcp"],
"env": {
"SUPERMEMORY_WORKSPACE_ROOT": "${workspaceFolder}"
}
}
}
}
24 changes: 16 additions & 8 deletions src/mcp-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,23 @@ import { loadConfig, getApiKey, writeConfig, getProjectConfigPath, GLOBAL_CONFIG
import { getUserTag, getProjectTag } from "./tags.ts";
import { createClient } from "./client.ts";

function getWorkspaceRoot() {
const workspaceRoot = process.env.SUPERMEMORY_WORKSPACE_ROOT?.trim();
if (workspaceRoot && !workspaceRoot.includes("${")) return workspaceRoot;
return process.cwd();
}

function getAuth() {
const config = loadConfig();
const workspaceRoot = getWorkspaceRoot();
const config = loadConfig(workspaceRoot);
const apiKey = getApiKey(config);
if (!apiKey) throw new Error("Not authenticated. Run `cursor-supermemory login` to connect.");
return {
apiKey,
userTag: getUserTag(config),
projectTag: getProjectTag(process.cwd(), config),
projectTag: getProjectTag(workspaceRoot, config),
workspaceRoot,
config,
};
}

Expand All @@ -39,9 +48,8 @@ export async function startMcpServer() {
inputSchema: {},
},
async () => {
const cwd = process.cwd();
const config = loadConfig(cwd);
const auth = getAuth();
const { config, workspaceRoot } = auth;
return {
content: [
{
Expand All @@ -61,7 +69,7 @@ export async function startMcpServer() {
project: auth.projectTag,
},
configFiles: {
project: getProjectConfigPath(cwd),
project: getProjectConfigPath(workspaceRoot),
global: GLOBAL_CONFIG_PATH,
},
},
Expand Down Expand Up @@ -92,9 +100,9 @@ export async function startMcpServer() {
async ({ scope, ...updates }) => {
const filtered = Object.fromEntries(Object.entries(updates).filter(([, v]) => v !== undefined));
if (Object.keys(filtered).length === 0) throw new Error("No config values provided.");
writeConfig(filtered as any, scope);
const cwd = process.cwd();
const filePath = scope === "project" ? getProjectConfigPath(cwd) : GLOBAL_CONFIG_PATH;
const workspaceRoot = getWorkspaceRoot();
writeConfig(filtered as any, scope, workspaceRoot);
const filePath = scope === "project" ? getProjectConfigPath(workspaceRoot) : GLOBAL_CONFIG_PATH;
return {
content: [{ type: "text", text: `Config updated (${scope}): ${filePath}\n${JSON.stringify(filtered, null, 2)}` }],
};
Expand Down