@skedulo/memory-hub-mcp 0.1.0
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/README.md +92 -0
- package/dist/client.js +78 -0
- package/dist/embeddings.js +44 -0
- package/dist/git-remote.js +62 -0
- package/dist/index.js +208 -0
- package/dist/list-repos.js +23 -0
- package/dist/recall.js +32 -0
- package/dist/repo-context.js +94 -0
- package/dist/save.js +62 -0
- package/dist/session-context.js +77 -0
- package/dist/skedulo-package-hint.js +31 -0
- package/dist/task-context.js +26 -0
- package/package.json +43 -0
package/README.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# memory-hub-mcp
|
|
2
|
+
|
|
3
|
+
Local stdio MCP server wrapping `memory-hub`.
|
|
4
|
+
|
|
5
|
+
`memory_getSkillGuide` serves `skill-guide.md` (this package's own file, read fresh on every
|
|
6
|
+
call) as the current usage guide for the `se-ai-memory-hub` skill. The skill's own
|
|
7
|
+
`SKILL.md` is a thin stub that just tells Claude to call this tool — the actual guidance
|
|
8
|
+
lives here so it updates on the next `yarn build`, not via a manual `cp` into
|
|
9
|
+
`~/.claude/skills/`. Edit `skill-guide.md` directly; never hand-copy its content elsewhere.
|
|
10
|
+
|
|
11
|
+
## Setup
|
|
12
|
+
|
|
13
|
+
1. Generate a personal Skedulo API token in Pulse Web.
|
|
14
|
+
2. Put your token in this project's `.claude/settings.local.json` (gitignored — never commit
|
|
15
|
+
it), under `env`:
|
|
16
|
+
```json
|
|
17
|
+
{ "env": { "MEMORY_HUB_MCP_TOKEN": "<your personal token>" } }
|
|
18
|
+
```
|
|
19
|
+
`.mcp.json` (committed) intentionally does NOT reference this token — Claude Code does not
|
|
20
|
+
substitute arbitrary `${VAR}` placeholders inside a project-scoped `.mcp.json`'s `env` block
|
|
21
|
+
(it only substitutes `${CLAUDE_PLUGIN_ROOT}`/`${CLAUDE_PLUGIN_DATA}`/`${CLAUDE_PROJECT_DIR}`);
|
|
22
|
+
an earlier version of this config tried `"MEMORY_HUB_MCP_TOKEN": "${MEMORY_HUB_TOKEN}"` and it
|
|
23
|
+
was passed through as that literal, unresolved string, causing every call to 401. The MCP
|
|
24
|
+
server process inherits `MEMORY_HUB_MCP_TOKEN` from Claude Code's own ambient environment
|
|
25
|
+
instead — which is exactly what `settings.local.json`'s `env` block populates.
|
|
26
|
+
`MEMORY_HUB_FUNCTION_URL` defaults to the team's one deployed tenant
|
|
27
|
+
(`https://dev-api.test.skl.io/function/memory-hub/memory-hub`, hardcoded in `src/index.ts`)
|
|
28
|
+
and does not need to be set. It's not a secret either way — only set it in `.mcp.json`'s
|
|
29
|
+
`env` block if you need to point at a different tenant (e.g. a local `sked function dev`
|
|
30
|
+
instance).
|
|
31
|
+
3. `yarn install && yarn build`
|
|
32
|
+
4. The server is already registered for this project via the repo's committed `.mcp.json`
|
|
33
|
+
(pointed at `node dist/index.js`) — nothing to add there. After editing
|
|
34
|
+
`settings.local.json`, restart the MCP server (or the whole session) so it picks up the
|
|
35
|
+
token — a running server process keeps whatever environment it was spawned with; editing
|
|
36
|
+
the file doesn't hot-reload it.
|
|
37
|
+
5. To use `memory-hub` from any project (not just this one), it's also registered globally in
|
|
38
|
+
`~/.claude.json` under `mcpServers`, pointed at this repo's built
|
|
39
|
+
`memory-hub-mcp/dist/index.js` by absolute path. Keep the two in sync manually — the global
|
|
40
|
+
entry isn't generated from `.mcp.json` and won't pick up changes to it. Either way, a stale
|
|
41
|
+
`dist/` means a stale server: run `yarn build` here after pulling source changes, then
|
|
42
|
+
restart the MCP connection (both entries run the same built file, so one rebuild covers
|
|
43
|
+
both).
|
|
44
|
+
|
|
45
|
+
## Claude Desktop
|
|
46
|
+
|
|
47
|
+
The MCP server is plain stdio, so Claude Desktop can run it. The `memory-hub-hook` package
|
|
48
|
+
cannot — Claude Desktop has no hook system — so startup recall and end-of-session auto-save
|
|
49
|
+
have no equivalent there. Two consequences, both permanent until Desktop grows hooks:
|
|
50
|
+
|
|
51
|
+
- **Recall** is covered by the `memory_sessionContext` tool plus the server's `instructions`,
|
|
52
|
+
which ask Claude to call it once at the start of a conversation. Nothing fires it
|
|
53
|
+
automatically; if a conversation starts cold, ask for it.
|
|
54
|
+
- **Auto-save has no substitute.** Desktop emits no end-of-conversation event, and
|
|
55
|
+
`session-stop.sh` shells out to `claude -p --resume`, which is CLI-only. Anything worth
|
|
56
|
+
keeping must be saved with `memory_save` before the conversation ends.
|
|
57
|
+
|
|
58
|
+
Add to `claude_desktop_config.json` (Settings → Developer → Edit Config):
|
|
59
|
+
|
|
60
|
+
```json
|
|
61
|
+
{
|
|
62
|
+
"mcpServers": {
|
|
63
|
+
"memory-hub": {
|
|
64
|
+
"command": "/absolute/path/to/node",
|
|
65
|
+
"args": ["/absolute/path/to/se-ai-memory-hub/memory-hub-mcp/dist/index.js"],
|
|
66
|
+
"env": { "MEMORY_HUB_MCP_TOKEN": "<your personal token>" }
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Both paths must be absolute. Desktop launches the server with a minimal `PATH` and does not
|
|
73
|
+
source your shell profile, so a bare `"command": "node"` fails under nvm or Homebrew — use
|
|
74
|
+
`which node`. For the same reason the token has to live in the `env` block; Desktop won't
|
|
75
|
+
inherit it from your shell.
|
|
76
|
+
|
|
77
|
+
Desktop starts the server with no project directory, so repo detection returns nothing:
|
|
78
|
+
`memory_sessionContext` comes back with `repoScoped: false` and no repo-scoped facts, wiki or
|
|
79
|
+
skills, and `memory_save` defaults to **Private** visibility. That is a supported shape, not a
|
|
80
|
+
degraded one — it is the right default for work that isn't tied to a Skedulo repo (estimation,
|
|
81
|
+
design, discovery). `memory_linkRepoTeam` and `memory_checkRepoStatus` will not work from
|
|
82
|
+
Desktop.
|
|
83
|
+
|
|
84
|
+
## Tags
|
|
85
|
+
|
|
86
|
+
`memory_save`/`memory_recall`'s `tags` parameter is a fixed picklist
|
|
87
|
+
matching the `AgentFacts`/`AgentSkills` custom objects' `Tags` field exactly: `ConnectedFunction`,
|
|
88
|
+
`HorizonComponent`, `TriggeredAction`, `ObjectModel`, `MobileExtension`, `Deployment`, `Auth`,
|
|
89
|
+
`Testing`, `Other`. The tool's Zod schema enforces this — any other value fails validation
|
|
90
|
+
before the request reaches the connected function (which otherwise 400s with no indication of
|
|
91
|
+
what went wrong). If the underlying Picklist's `allowedValues` ever changes, update `TAG_VALUES`
|
|
92
|
+
in `src/index.ts` to match.
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.MemoryHubClient = void 0;
|
|
7
|
+
// memory-hub-mcp/src/client.ts
|
|
8
|
+
const axios_1 = __importDefault(require("axios"));
|
|
9
|
+
class MemoryHubClient {
|
|
10
|
+
config;
|
|
11
|
+
constructor(config) {
|
|
12
|
+
this.config = config;
|
|
13
|
+
}
|
|
14
|
+
async post(path, body) {
|
|
15
|
+
const res = await axios_1.default.post(`${this.config.baseUrl}${path}`, body, {
|
|
16
|
+
headers: { Authorization: `Bearer ${this.config.apiToken}`, 'Content-Type': 'application/json' },
|
|
17
|
+
});
|
|
18
|
+
return res.data;
|
|
19
|
+
}
|
|
20
|
+
recall(input) {
|
|
21
|
+
return this.post('/memory/recall', input);
|
|
22
|
+
}
|
|
23
|
+
saveFact(input) {
|
|
24
|
+
return this.post('/memory/save-fact', input);
|
|
25
|
+
}
|
|
26
|
+
saveSkill(input) {
|
|
27
|
+
return this.post('/memory/save-skill', input);
|
|
28
|
+
}
|
|
29
|
+
listSkills(input) {
|
|
30
|
+
return this.post('/memory/list-skills', input);
|
|
31
|
+
}
|
|
32
|
+
saveScenario(input) {
|
|
33
|
+
return this.post('/memory/save-scenario', input);
|
|
34
|
+
}
|
|
35
|
+
recallScenarios(input) {
|
|
36
|
+
return this.post('/memory/recall-scenarios', input);
|
|
37
|
+
}
|
|
38
|
+
upsertPersona(input) {
|
|
39
|
+
return this.post('/memory/upsert-persona', input);
|
|
40
|
+
}
|
|
41
|
+
getPersona() {
|
|
42
|
+
return this.post('/memory/get-persona', {});
|
|
43
|
+
}
|
|
44
|
+
promoteVisibility(input) {
|
|
45
|
+
return this.post('/memory/promote-visibility', input);
|
|
46
|
+
}
|
|
47
|
+
bulkPromoteRepoScoped() {
|
|
48
|
+
return this.post('/memory/bulk-promote-repo-scoped', {});
|
|
49
|
+
}
|
|
50
|
+
grantAccess(input) {
|
|
51
|
+
return this.post('/memory/grant-access', input);
|
|
52
|
+
}
|
|
53
|
+
listTeams() {
|
|
54
|
+
return this.post('/memory/list-teams', {});
|
|
55
|
+
}
|
|
56
|
+
listRepos(input) {
|
|
57
|
+
return this.post('/memory/list-repos', input);
|
|
58
|
+
}
|
|
59
|
+
moveResourceRepo(input) {
|
|
60
|
+
return this.post('/memory/move-resource-repo', input);
|
|
61
|
+
}
|
|
62
|
+
resolveRepo(input) {
|
|
63
|
+
return this.post('/memory/resolve-repo', input);
|
|
64
|
+
}
|
|
65
|
+
resolveTask(input) {
|
|
66
|
+
return this.post('/memory/resolve-task', input);
|
|
67
|
+
}
|
|
68
|
+
linkRepoTeam(input) {
|
|
69
|
+
return this.post('/memory/link-repo-team', input);
|
|
70
|
+
}
|
|
71
|
+
saveWikiPage(input) {
|
|
72
|
+
return this.post('/memory/save-wiki-page', input);
|
|
73
|
+
}
|
|
74
|
+
recallWiki(input) {
|
|
75
|
+
return this.post('/memory/recall-wiki', input);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.MemoryHubClient = MemoryHubClient;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.embed = void 0;
|
|
4
|
+
const transformers_1 = require("@xenova/transformers");
|
|
5
|
+
// Loaded lazily, once per process, on the first embed() call — a session that
|
|
6
|
+
// never saves or recalls anything pays zero cost, and every call after the
|
|
7
|
+
// first reuses the same loaded model instead of reloading it. The model's
|
|
8
|
+
// weights (~90MB) are cached to disk by transformers.js after the first
|
|
9
|
+
// download, so only the very first call on a fresh machine pays that cost.
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
11
|
+
let extractorPromise;
|
|
12
|
+
const EXTRACTOR_LOAD_TIMEOUT_MS = 15_000;
|
|
13
|
+
function loadExtractor() {
|
|
14
|
+
let timer;
|
|
15
|
+
const timeout = new Promise((_, reject) => {
|
|
16
|
+
timer = setTimeout(() => reject(new Error('Embedding model load timed out')), EXTRACTOR_LOAD_TIMEOUT_MS);
|
|
17
|
+
});
|
|
18
|
+
return Promise.race([(0, transformers_1.pipeline)('feature-extraction', 'Xenova/all-MiniLM-L6-v2'), timeout]).finally(() => clearTimeout(timer));
|
|
19
|
+
}
|
|
20
|
+
function getExtractor() {
|
|
21
|
+
if (!extractorPromise) {
|
|
22
|
+
extractorPromise = loadExtractor().catch((err) => {
|
|
23
|
+
// Don't cache the failure — a transient issue (network blip, disk
|
|
24
|
+
// permission race) shouldn't permanently disable embeddings for the
|
|
25
|
+
// rest of the process's life. Log to stderr since every caller of
|
|
26
|
+
// embed() swallows this into "no embedding" silently.
|
|
27
|
+
extractorPromise = undefined;
|
|
28
|
+
console.error('Failed to load embedding model:', err);
|
|
29
|
+
throw err;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return extractorPromise;
|
|
33
|
+
}
|
|
34
|
+
// 384-dimension vector (all-MiniLM-L6-v2's fixed output size), mean-pooled and
|
|
35
|
+
// L2-normalized so cosine similarity on the connected function side reduces to
|
|
36
|
+
// a plain dot product in effect. Throws on model load or inference failure —
|
|
37
|
+
// every caller in index.ts wraps this in .catch() and degrades to "no
|
|
38
|
+
// embedding" rather than blocking the save/recall it's attached to.
|
|
39
|
+
async function embed(text) {
|
|
40
|
+
const extractor = await getExtractor();
|
|
41
|
+
const output = await extractor(text, { pooling: 'mean', normalize: true });
|
|
42
|
+
return Array.from(output.data);
|
|
43
|
+
}
|
|
44
|
+
exports.embed = embed;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.detectRepoName = exports.canonicalizeRemoteUrl = void 0;
|
|
4
|
+
// memory-hub-mcp/src/git-remote.ts
|
|
5
|
+
const child_process_1 = require("child_process");
|
|
6
|
+
/**
|
|
7
|
+
* Normalize a git remote URL to the canonical `owner/name` form, per the
|
|
8
|
+
* repo/team grouping spec §3. The host is deliberately dropped — this project
|
|
9
|
+
* is single-org, single-host today.
|
|
10
|
+
*
|
|
11
|
+
* Returns null for anything unrecognized. Never throws: a session that can't be
|
|
12
|
+
* identified must degrade to no repo scoping, not to an error.
|
|
13
|
+
*
|
|
14
|
+
* This logic is duplicated, on purpose, in memory-hub-hook/session-start.sh —
|
|
15
|
+
* a bash hook cannot import a TypeScript module. Change both together.
|
|
16
|
+
*/
|
|
17
|
+
function canonicalizeRemoteUrl(remoteUrl) {
|
|
18
|
+
const trimmed = (remoteUrl ?? '').trim();
|
|
19
|
+
if (!trimmed) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
const withoutGitSuffix = trimmed.replace(/\.git$/, '');
|
|
23
|
+
const scpForm = /^git@[^:]+:(.+)$/.exec(withoutGitSuffix);
|
|
24
|
+
if (scpForm) {
|
|
25
|
+
return scpForm[1] || null;
|
|
26
|
+
}
|
|
27
|
+
const urlForm = /^(?:https?|ssh):\/\/(?:[^@]+@)?[^/]+\/(.+)$/.exec(withoutGitSuffix);
|
|
28
|
+
if (urlForm) {
|
|
29
|
+
return urlForm[1] || null;
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
exports.canonicalizeRemoteUrl = canonicalizeRemoteUrl;
|
|
34
|
+
function runGit(args, cwd) {
|
|
35
|
+
try {
|
|
36
|
+
const stdout = (0, child_process_1.execFileSync)('git', args, {
|
|
37
|
+
cwd,
|
|
38
|
+
encoding: 'utf8',
|
|
39
|
+
// stderr is swallowed: "not a git repository" is an expected, silent outcome.
|
|
40
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
41
|
+
});
|
|
42
|
+
return stdout.trim() || null;
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The canonical `owner/name` of the repo this process is running in, or null if
|
|
50
|
+
* it isn't in a git checkout, has no remotes, or the remote isn't a recognized form.
|
|
51
|
+
*/
|
|
52
|
+
function detectRepoName(cwd = process.cwd()) {
|
|
53
|
+
let remoteUrl = runGit(['remote', 'get-url', 'origin'], cwd);
|
|
54
|
+
if (!remoteUrl) {
|
|
55
|
+
const firstRemote = runGit(['remote'], cwd)?.split('\n')[0]?.trim();
|
|
56
|
+
if (firstRemote) {
|
|
57
|
+
remoteUrl = runGit(['remote', 'get-url', firstRemote], cwd);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return remoteUrl ? canonicalizeRemoteUrl(remoteUrl) : null;
|
|
61
|
+
}
|
|
62
|
+
exports.detectRepoName = detectRepoName;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
7
|
+
const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
8
|
+
const zod_1 = require("zod");
|
|
9
|
+
const client_1 = require("./client");
|
|
10
|
+
const list_repos_1 = require("./list-repos");
|
|
11
|
+
const repo_context_1 = require("./repo-context");
|
|
12
|
+
const task_context_1 = require("./task-context");
|
|
13
|
+
const git_remote_1 = require("./git-remote");
|
|
14
|
+
const embeddings_1 = require("./embeddings");
|
|
15
|
+
const save_1 = require("./save");
|
|
16
|
+
const recall_1 = require("./recall");
|
|
17
|
+
const session_context_1 = require("./session-context");
|
|
18
|
+
// Must match the AgentFacts/AgentSkills/AgentWikiPages Tags custom field's Picklist
|
|
19
|
+
// allowedValues (src/object-model/custom-fields/{AgentFacts,AgentSkills,AgentWikiPages}/*-Tags.custom-field.json)
|
|
20
|
+
// exactly — the connected function 400s on any value outside this set, with
|
|
21
|
+
// no indication of what the valid values are. Validating here instead
|
|
22
|
+
// turns that into a clear Zod error at the tool-call boundary.
|
|
23
|
+
const TAG_VALUES = [
|
|
24
|
+
'ConnectedFunction',
|
|
25
|
+
'HorizonComponent',
|
|
26
|
+
'TriggeredAction',
|
|
27
|
+
'ObjectModel',
|
|
28
|
+
'MobileExtension',
|
|
29
|
+
'Deployment',
|
|
30
|
+
'Auth',
|
|
31
|
+
'Testing',
|
|
32
|
+
'BreezeUI',
|
|
33
|
+
'PSS',
|
|
34
|
+
'PSF',
|
|
35
|
+
'Optimization',
|
|
36
|
+
'Webhooks',
|
|
37
|
+
'Salesforce',
|
|
38
|
+
'Other',
|
|
39
|
+
'ArchitectureMap',
|
|
40
|
+
'SOW',
|
|
41
|
+
'TDD',
|
|
42
|
+
];
|
|
43
|
+
// The team's one deployed memory-hub function. MEMORY_HUB_FUNCTION_URL only needs to
|
|
44
|
+
// be set to override this (e.g. pointing at a local `sked function dev` instance).
|
|
45
|
+
const DEFAULT_FUNCTION_URL = 'https://dev-api.test.skl.io/function/memory-hub/memory-hub';
|
|
46
|
+
const baseUrl = process.env.MEMORY_HUB_FUNCTION_URL || DEFAULT_FUNCTION_URL;
|
|
47
|
+
// This developer's personal identity token, forwarded as the caller's own
|
|
48
|
+
// Authorization header — the connected function now runs under this same
|
|
49
|
+
// forwarded token rather than a separate service-account ConfigVariable.
|
|
50
|
+
const apiToken = process.env.MEMORY_HUB_MCP_TOKEN;
|
|
51
|
+
if (!apiToken) {
|
|
52
|
+
throw new Error('MEMORY_HUB_MCP_TOKEN must be set');
|
|
53
|
+
}
|
|
54
|
+
const client = new client_1.MemoryHubClient({ baseUrl, apiToken });
|
|
55
|
+
// Claude Code gets its startup recall from memory-hub-hook's SessionStart hook. Claude
|
|
56
|
+
// Desktop has no hook system, so these instructions (surfaced by the host at connect
|
|
57
|
+
// time) plus memory_sessionContext are the only equivalent available there.
|
|
58
|
+
const INSTRUCTIONS = [
|
|
59
|
+
'Call memory_sessionContext once at the start of a conversation to load this',
|
|
60
|
+
"developer's persona, facts, skills and wiki pages before answering from scratch.",
|
|
61
|
+
'Before wrapping up a task, save anything durable with memory_save — on hosts',
|
|
62
|
+
'without a session-end hook (e.g. Claude Desktop) nothing else will capture it.',
|
|
63
|
+
].join(' ');
|
|
64
|
+
const server = new mcp_js_1.McpServer({ name: 'memory-hub-mcp', version: '0.1.0' }, { instructions: INSTRUCTIONS });
|
|
65
|
+
// Detected from this process's own working directory, not from anything the model
|
|
66
|
+
// types. Resolved lazily on the first save so startup never blocks on git or the
|
|
67
|
+
// network, and degrades to undefined (an unscoped save) on any failure.
|
|
68
|
+
const repoContext = (0, repo_context_1.createRepoContext)(client);
|
|
69
|
+
const taskContext = (0, task_context_1.createTaskContext)(client);
|
|
70
|
+
// resolveRepo's auto-join (opening an already-linked repo joins its team, no
|
|
71
|
+
// confirmation prompt) is otherwise silent — this is the one chance a human hears
|
|
72
|
+
// about it, surfaced as a plain-text content block ahead of the tool's normal JSON
|
|
73
|
+
// result so Claude sees it and can mention it once, not on every single save.
|
|
74
|
+
async function joinNoticeBlocks() {
|
|
75
|
+
const teamName = await repoContext.takeJoinNotice();
|
|
76
|
+
if (!teamName) {
|
|
77
|
+
return [];
|
|
78
|
+
}
|
|
79
|
+
return [
|
|
80
|
+
{
|
|
81
|
+
type: 'text',
|
|
82
|
+
text: `Note: this repo is linked to the ${teamName} team, so you've been added to it — your saves here (and its other Team-visibility content) are now shared with that team.`,
|
|
83
|
+
},
|
|
84
|
+
];
|
|
85
|
+
}
|
|
86
|
+
// saveFact/saveScenario's dedup check warns rather than blocks (see saveFact.ts's
|
|
87
|
+
// comment for why), so the save above already happened by the time this runs — this
|
|
88
|
+
// only makes the match legible to Claude instead of it being buried in the raw JSON
|
|
89
|
+
// result, the same visibility upgrade joinNoticeBlocks gives the auto-join case.
|
|
90
|
+
function duplicateNoticeBlocks(result) {
|
|
91
|
+
const match = result.possibleDuplicate;
|
|
92
|
+
if (!match) {
|
|
93
|
+
return [];
|
|
94
|
+
}
|
|
95
|
+
const when = match.lastModifiedDate ? ` on ${match.lastModifiedDate.slice(0, 10)}` : '';
|
|
96
|
+
return [
|
|
97
|
+
{
|
|
98
|
+
type: 'text',
|
|
99
|
+
text: `Note: this looks similar to something already saved${when}: "${match.content}". Saved as new anyway — consider recalling and updating that one instead next time.`,
|
|
100
|
+
},
|
|
101
|
+
];
|
|
102
|
+
}
|
|
103
|
+
server.tool('memory_getSkillGuide', 'Get the current SE AI Memory Hub usage guide — when to recall, what to save where, sharing rules, repo linking. Call this first when the se-ai-memory-hub skill triggers.', {}, async () => {
|
|
104
|
+
// Read from disk on every call, not cached at module load — this is the whole point:
|
|
105
|
+
// a developer's local skills/ copy is a thin stub now (see skills/se-ai-memory-hub/SKILL.md),
|
|
106
|
+
// so the guide can only go stale here, in the one file that ships with memory-hub-mcp
|
|
107
|
+
// itself and updates on every `yarn build`, not via a separate manual `cp` step.
|
|
108
|
+
const guidePath = (0, path_1.join)(__dirname, '..', 'skill-guide.md');
|
|
109
|
+
const guide = (0, fs_1.readFileSync)(guidePath, 'utf-8');
|
|
110
|
+
return { content: [{ type: 'text', text: guide }] };
|
|
111
|
+
});
|
|
112
|
+
server.tool('memory_recall', "Recall this developer's (or their team's) Facts, Skills, Scenarios, or Wiki pages. See memory_getSkillGuide for when to use each type.", {
|
|
113
|
+
type: zod_1.z.enum(['Fact', 'Skill', 'Scenario', 'Wiki']),
|
|
114
|
+
scope: zod_1.z.enum(['self', 'team']),
|
|
115
|
+
query: zod_1.z.string().optional(),
|
|
116
|
+
tags: zod_1.z.array(zod_1.z.enum(TAG_VALUES)).optional().describe('Fact only.'),
|
|
117
|
+
externalRef: zod_1.z.string().optional().describe("Fact, Scenario only — filter to items linked to this Linear/Jira ticket ref, e.g. 'SOL-1234'. Does not create a task if the ref doesn't resolve to one — returns no results instead."),
|
|
118
|
+
}, async (input) => {
|
|
119
|
+
const result = await (0, recall_1.performRecall)({ client, embed: embeddings_1.embed }, input);
|
|
120
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
121
|
+
});
|
|
122
|
+
server.tool('memory_save', 'Save a Fact, Skill, Scenario, or Wiki page to the SE AI Memory Hub. Written Team visibility automatically if the attached repo is already linked to a team, otherwise Private. See memory_getSkillGuide for which type to use and which fields it needs. The current repo is detected automatically unless you pass an explicit repo (from memory_listRepos) to target a different one.', {
|
|
123
|
+
type: zod_1.z.enum(['Fact', 'Skill', 'Scenario', 'Wiki']),
|
|
124
|
+
content: zod_1.z.string().optional().describe('Required for Fact, Skill, Wiki.'),
|
|
125
|
+
title: zod_1.z.string().optional().describe('Required for Skill, Wiki.'),
|
|
126
|
+
summary: zod_1.z.string().optional().describe('Required for Scenario.'),
|
|
127
|
+
factIds: zod_1.z.array(zod_1.z.string()).optional().describe('Scenario only — UIDs of facts already saved this session that belong together.'),
|
|
128
|
+
links: zod_1.z.array(zod_1.z.string()).optional().describe('Wiki only — UIDs of other wiki pages this one depends on.'),
|
|
129
|
+
tags: zod_1.z.array(zod_1.z.enum(TAG_VALUES)).optional().describe('Fact, Skill, Wiki only.'),
|
|
130
|
+
externalRef: zod_1.z.string().optional().describe("Fact, Scenario, Wiki only — the Linear/Jira ticket this relates to, e.g. 'SOL-1234' — pass it when the user mentions a ticket."),
|
|
131
|
+
repo: zod_1.z.string().min(1).optional().describe('An explicit DevRepos uid from memory_listRepos, overriding the current-directory auto-detected repo.'),
|
|
132
|
+
}, async (input) => {
|
|
133
|
+
const result = await (0, save_1.performSave)({
|
|
134
|
+
client,
|
|
135
|
+
embed: embeddings_1.embed,
|
|
136
|
+
currentRepoUid: () => repoContext.currentRepoUid(),
|
|
137
|
+
resolveTaskUid: (ref, repoUid) => taskContext.resolveTaskUid(ref, repoUid),
|
|
138
|
+
}, input);
|
|
139
|
+
return {
|
|
140
|
+
content: [
|
|
141
|
+
...(await joinNoticeBlocks()),
|
|
142
|
+
...duplicateNoticeBlocks(result),
|
|
143
|
+
{ type: 'text', text: JSON.stringify(result) },
|
|
144
|
+
],
|
|
145
|
+
};
|
|
146
|
+
});
|
|
147
|
+
server.tool('memory_upsertPersona', "Update this developer's durable persona profile (preferences/decisions/patterns) — each provided field replaces its prior value, not appends.", {
|
|
148
|
+
preferences: zod_1.z.string().optional(),
|
|
149
|
+
decisions: zod_1.z.string().optional(),
|
|
150
|
+
patterns: zod_1.z.string().optional(),
|
|
151
|
+
}, async (input) => {
|
|
152
|
+
const result = await client.upsertPersona(input);
|
|
153
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
154
|
+
});
|
|
155
|
+
server.tool('memory_setVisibility', "Change who can see a Fact/Scenario/Skill/Wiki page — promote to Team or Restricted, or demote back to Private. Only call this when a human in the conversation explicitly asks to share, promote, or un-share something — never autonomously.", {
|
|
156
|
+
resourceType: zod_1.z.enum(['Fact', 'Scenario', 'Skill', 'Wiki']),
|
|
157
|
+
resourceId: zod_1.z.string(),
|
|
158
|
+
newVisibility: zod_1.z.enum(['Private', 'Team', 'Restricted']),
|
|
159
|
+
}, async (input) => {
|
|
160
|
+
const result = await client.promoteVisibility(input);
|
|
161
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
162
|
+
});
|
|
163
|
+
server.tool('memory_bulkPromoteRepoScoped', "Bulk catch-up: promotes all of this developer's existing Private Facts/Scenarios/Skills/Wiki pages whose repo is already linked to a team, to Team visibility — for content saved before repo-scoped saves started defaulting to Team automatically. Only touches your own items. Only call this when a human in the conversation explicitly asks for it — never autonomously. Re-running it will also re-promote any item you've since deliberately demoted with memory_setVisibility, so don't call it more than once without the human asking again.", {}, async () => {
|
|
164
|
+
const result = await client.bulkPromoteRepoScoped();
|
|
165
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
166
|
+
});
|
|
167
|
+
server.tool('memory_grantAccess', 'Grant a specific teammate access to one of your Fact/Scenario/Skill/Wiki items (promotes it to Restricted visibility if needed). Only call this when a human in the conversation explicitly asks to share something with a specific person — never autonomously.', {
|
|
168
|
+
resourceType: zod_1.z.enum(['Fact', 'Scenario', 'Skill', 'Wiki']),
|
|
169
|
+
resourceId: zod_1.z.string(),
|
|
170
|
+
toAgentId: zod_1.z.string(),
|
|
171
|
+
}, async (input) => {
|
|
172
|
+
const result = await client.grantAccess(input);
|
|
173
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
174
|
+
});
|
|
175
|
+
server.tool('memory_moveResourceRepo', "Reassign an already-saved Fact/Scenario/Skill/Wiki page to a different repo, or clear its repo association with repo: null. Look up the target repo's uid with memory_listRepos first.", {
|
|
176
|
+
resourceType: zod_1.z.enum(['Fact', 'Scenario', 'Skill', 'Wiki']),
|
|
177
|
+
resourceId: zod_1.z.string(),
|
|
178
|
+
repo: zod_1.z.string().nullable(),
|
|
179
|
+
}, async (input) => {
|
|
180
|
+
const result = await client.moveResourceRepo(input);
|
|
181
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
182
|
+
});
|
|
183
|
+
server.tool('memory_checkRepoStatus', "Check whether the current repo is linked to a memory team yet. See memory_getSkillGuide for what to do if it isn't.", {}, async () => {
|
|
184
|
+
const status = await repoContext.checkRepoStatus();
|
|
185
|
+
return { content: [...(await joinNoticeBlocks()), { type: 'text', text: JSON.stringify(status) }] };
|
|
186
|
+
});
|
|
187
|
+
server.tool('memory_listRepos', "List repos across this developer's teams, with an optional substring query filter, for targeting memory_save or memory_moveResourceRepo at a repo other than the current directory.", {
|
|
188
|
+
query: zod_1.z.string().optional().describe('Case-insensitive substring filter on repo name.'),
|
|
189
|
+
}, async (input) => {
|
|
190
|
+
const repos = await (0, list_repos_1.listReposForTools)(client, input.query);
|
|
191
|
+
return { content: [{ type: 'text', text: JSON.stringify({ repos }) }] };
|
|
192
|
+
});
|
|
193
|
+
server.tool('memory_linkRepoTeam', 'Link the current repo to a team by name (existing or new) after the user has confirmed which team it belongs to.', {
|
|
194
|
+
teamName: zod_1.z.string(),
|
|
195
|
+
}, async (input) => {
|
|
196
|
+
const repoName = (0, git_remote_1.detectRepoName)();
|
|
197
|
+
if (!repoName) {
|
|
198
|
+
return { content: [{ type: 'text', text: JSON.stringify({ error: 'No repo detected in this session.' }) }] };
|
|
199
|
+
}
|
|
200
|
+
const result = await client.linkRepoTeam({ repoName, teamName: input.teamName });
|
|
201
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
202
|
+
});
|
|
203
|
+
server.tool('memory_sessionContext', "Load this developer's saved memory-hub context: their persona profile, facts, skills, and — when the session has a repo — its wiki pages. Call once at the start of a conversation. If the result has persona.configured false, offer once to set up their persona with memory_upsertPersona, then drop it for the rest of the conversation. On Claude Code the SessionStart hook already covers facts and skills; call this there for the persona, or if that context is missing.", {}, async () => {
|
|
204
|
+
const context = await (0, session_context_1.buildSessionContext)({ client, currentRepoUid: repoContext.currentRepoUid });
|
|
205
|
+
return { content: [{ type: 'text', text: JSON.stringify(context) }] };
|
|
206
|
+
});
|
|
207
|
+
const transport = new stdio_js_1.StdioServerTransport();
|
|
208
|
+
server.connect(transport);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.listReposForTools = void 0;
|
|
4
|
+
// Fans out listTeams() -> listRepos() per team and flattens into one list
|
|
5
|
+
// labeled with each repo's team name — the small, infrequent list a caller
|
|
6
|
+
// picks a target repo uid from (for memory_saveX's repo param or
|
|
7
|
+
// memory_moveResourceRepo). A single team's listRepos failing degrades that
|
|
8
|
+
// team's repos out of the result rather than failing the whole call, since
|
|
9
|
+
// a partial list is still useful for picking a repo and a total failure
|
|
10
|
+
// isn't warranted by one team's transient error.
|
|
11
|
+
async function listReposForTools(client, query) {
|
|
12
|
+
const { teams } = await client.listTeams();
|
|
13
|
+
const perTeam = await Promise.allSettled(teams.map((team) => client.listRepos({ teamId: team.uid }).then((result) => result.repos.map((repo) => ({ uid: repo.uid, name: repo.name, teamName: team.name })))));
|
|
14
|
+
const allRepos = perTeam
|
|
15
|
+
.filter((result) => result.status === 'fulfilled')
|
|
16
|
+
.flatMap((result) => result.value);
|
|
17
|
+
if (!query) {
|
|
18
|
+
return allRepos;
|
|
19
|
+
}
|
|
20
|
+
const normalizedQuery = query.toLowerCase();
|
|
21
|
+
return allRepos.filter((repo) => repo.name.toLowerCase().includes(normalizedQuery));
|
|
22
|
+
}
|
|
23
|
+
exports.listReposForTools = listReposForTools;
|
package/dist/recall.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.performRecall = void 0;
|
|
4
|
+
// Extracted from four near-identical memory_recall/listSkills/recallScenarios/
|
|
5
|
+
// recallWiki tool handlers — see save.ts's comment for why (index.ts's module-scope
|
|
6
|
+
// side effects make it untestable directly).
|
|
7
|
+
async function performRecall(deps, input) {
|
|
8
|
+
const { client, embed } = deps;
|
|
9
|
+
const queryEmbedding = input.query ? await embed(input.query).catch(() => undefined) : undefined;
|
|
10
|
+
switch (input.type) {
|
|
11
|
+
case 'Fact':
|
|
12
|
+
return client.recall({
|
|
13
|
+
scope: input.scope,
|
|
14
|
+
query: input.query,
|
|
15
|
+
tags: input.tags,
|
|
16
|
+
externalRef: input.externalRef,
|
|
17
|
+
queryEmbedding,
|
|
18
|
+
});
|
|
19
|
+
case 'Skill':
|
|
20
|
+
return client.listSkills({ scope: input.scope, query: input.query, queryEmbedding });
|
|
21
|
+
case 'Scenario':
|
|
22
|
+
return client.recallScenarios({
|
|
23
|
+
scope: input.scope,
|
|
24
|
+
query: input.query,
|
|
25
|
+
externalRef: input.externalRef,
|
|
26
|
+
queryEmbedding,
|
|
27
|
+
});
|
|
28
|
+
case 'Wiki':
|
|
29
|
+
return client.recallWiki({ scope: input.scope, query: input.query, queryEmbedding });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.performRecall = performRecall;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createRepoContext = exports.humanizeRepoSlug = void 0;
|
|
4
|
+
const git_remote_1 = require("./git-remote");
|
|
5
|
+
const skedulo_package_hint_1 = require("./skedulo-package-hint");
|
|
6
|
+
const NO_REPO = {};
|
|
7
|
+
/**
|
|
8
|
+
* Turns a canonical "owner/repo" name into a humanized team-name guess
|
|
9
|
+
* (universal-group -> Universal Group) — used only when no config file gives
|
|
10
|
+
* a real hint (e.g. a repo using the newer sked.pkg.json/sked.proj.json
|
|
11
|
+
* convention instead of skeduloPackage.json has no file our reader looks at
|
|
12
|
+
* at all). Confirmed live: a repo's own name has been a decent signal for
|
|
13
|
+
* its client in every case seen so far (CX-Welbe_Transporation,
|
|
14
|
+
* cx-welbehealth, universal-group all self-name) — an imperfect guess beats
|
|
15
|
+
* offering the caller no hint whatsoever.
|
|
16
|
+
*/
|
|
17
|
+
function humanizeRepoSlug(canonicalRepoName) {
|
|
18
|
+
const slug = canonicalRepoName.split('/').pop() ?? canonicalRepoName;
|
|
19
|
+
return slug
|
|
20
|
+
.replace(/[-_]+/g, ' ')
|
|
21
|
+
.trim()
|
|
22
|
+
.split(/\s+/)
|
|
23
|
+
.filter(Boolean)
|
|
24
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
25
|
+
.join(' ');
|
|
26
|
+
}
|
|
27
|
+
exports.humanizeRepoSlug = humanizeRepoSlug;
|
|
28
|
+
/**
|
|
29
|
+
* Resolves this process's repo once and caches the answer for the process's
|
|
30
|
+
* lifetime — an MCP server's working directory doesn't change mid-session,
|
|
31
|
+
* and a failed or pending resolution must not be retried on every tool call.
|
|
32
|
+
*
|
|
33
|
+
* A `needsTeamSelection` result is a distinct cached status, not a failure —
|
|
34
|
+
* `checkRepoStatus()` surfaces it so a skill can act on it, while
|
|
35
|
+
* `currentRepoUid()` (used by the plain save tools) still degrades it to
|
|
36
|
+
* `undefined`: an unresolved team must not block an otherwise-unrelated save.
|
|
37
|
+
*/
|
|
38
|
+
function createRepoContext(client, detectName = git_remote_1.detectRepoName, detectHint = skedulo_package_hint_1.detectTeamNameHint) {
|
|
39
|
+
let cached;
|
|
40
|
+
let inFlight;
|
|
41
|
+
let joinNoticeTaken = false;
|
|
42
|
+
const resolve = () => {
|
|
43
|
+
if (cached !== undefined) {
|
|
44
|
+
return Promise.resolve(cached);
|
|
45
|
+
}
|
|
46
|
+
if (!inFlight) {
|
|
47
|
+
inFlight = (async () => {
|
|
48
|
+
const name = detectName();
|
|
49
|
+
if (!name) {
|
|
50
|
+
return NO_REPO;
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
const teamNameHint = detectHint() ?? humanizeRepoSlug(name);
|
|
54
|
+
const result = await client.resolveRepo({ name, teamNameHint });
|
|
55
|
+
if ('needsTeamSelection' in result) {
|
|
56
|
+
return {
|
|
57
|
+
needsTeamSelection: true,
|
|
58
|
+
teamNameHint: result.teamNameHint,
|
|
59
|
+
agentTeams: result.agentTeams,
|
|
60
|
+
name,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return { uid: result.uid, name: result.name, justJoinedTeamName: result.justJoinedTeamName };
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return NO_REPO;
|
|
67
|
+
}
|
|
68
|
+
})();
|
|
69
|
+
}
|
|
70
|
+
return inFlight.then((status) => {
|
|
71
|
+
cached = status;
|
|
72
|
+
inFlight = undefined;
|
|
73
|
+
return status;
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
return {
|
|
77
|
+
async currentRepoUid() {
|
|
78
|
+
const status = await resolve();
|
|
79
|
+
return status.uid;
|
|
80
|
+
},
|
|
81
|
+
checkRepoStatus() {
|
|
82
|
+
return resolve();
|
|
83
|
+
},
|
|
84
|
+
async takeJoinNotice() {
|
|
85
|
+
const status = await resolve();
|
|
86
|
+
if (status.justJoinedTeamName && !joinNoticeTaken) {
|
|
87
|
+
joinNoticeTaken = true;
|
|
88
|
+
return status.justJoinedTeamName;
|
|
89
|
+
}
|
|
90
|
+
return undefined;
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
exports.createRepoContext = createRepoContext;
|
package/dist/save.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.performSave = void 0;
|
|
4
|
+
// Extracted from four near-identical memory_saveX tool handlers so the per-type
|
|
5
|
+
// dispatch logic — which fields are required, what gets embedded, which client
|
|
6
|
+
// method is called — is unit-testable. index.ts's module-scope side effects
|
|
7
|
+
// (throwing on a missing token, connecting a stdio transport) make the file
|
|
8
|
+
// itself untestable, the same reason list-repos.ts was extracted earlier.
|
|
9
|
+
async function performSave(deps, input) {
|
|
10
|
+
const { client, embed, currentRepoUid, resolveTaskUid } = deps;
|
|
11
|
+
// Required-field checks run BEFORE any repo resolution/network call — the old
|
|
12
|
+
// per-type tools got this for free from Zod (`content: z.string()`, not
|
|
13
|
+
// `.optional()`), which the consolidated schema can't do since requiredness is
|
|
14
|
+
// now type-dependent. Validating first avoids an unnecessary currentRepoUid()
|
|
15
|
+
// call (a git-remote read) on a request that's about to fail anyway.
|
|
16
|
+
switch (input.type) {
|
|
17
|
+
case 'Fact': {
|
|
18
|
+
if (!input.content) {
|
|
19
|
+
throw new Error("content is required when type is 'Fact'");
|
|
20
|
+
}
|
|
21
|
+
const repo = input.repo ?? (await currentRepoUid());
|
|
22
|
+
const devTaskId = input.externalRef ? await resolveTaskUid(input.externalRef, repo ?? null) : undefined;
|
|
23
|
+
const embedding = await embed(input.content).catch(() => undefined);
|
|
24
|
+
return client.saveFact({ content: input.content, tags: input.tags, devTaskId, repo, embedding });
|
|
25
|
+
}
|
|
26
|
+
case 'Skill': {
|
|
27
|
+
if (!input.title || !input.content) {
|
|
28
|
+
throw new Error("title and content are required when type is 'Skill'");
|
|
29
|
+
}
|
|
30
|
+
const repo = input.repo ?? (await currentRepoUid());
|
|
31
|
+
const embedding = await embed(`${input.title}\n\n${input.content}`).catch(() => undefined);
|
|
32
|
+
return client.saveSkill({ title: input.title, content: input.content, tags: input.tags, repo, embedding });
|
|
33
|
+
}
|
|
34
|
+
case 'Scenario': {
|
|
35
|
+
if (!input.summary) {
|
|
36
|
+
throw new Error("summary is required when type is 'Scenario'");
|
|
37
|
+
}
|
|
38
|
+
const repo = input.repo ?? (await currentRepoUid());
|
|
39
|
+
const devTaskId = input.externalRef ? await resolveTaskUid(input.externalRef, repo ?? null) : undefined;
|
|
40
|
+
const embedding = await embed(input.summary).catch(() => undefined);
|
|
41
|
+
return client.saveScenario({ summary: input.summary, factIds: input.factIds, devTaskId, repo, embedding });
|
|
42
|
+
}
|
|
43
|
+
case 'Wiki': {
|
|
44
|
+
if (!input.title || !input.content) {
|
|
45
|
+
throw new Error("title and content are required when type is 'Wiki'");
|
|
46
|
+
}
|
|
47
|
+
const repo = input.repo ?? (await currentRepoUid());
|
|
48
|
+
const devTaskId = input.externalRef ? await resolveTaskUid(input.externalRef, repo ?? null) : undefined;
|
|
49
|
+
const embedding = await embed(`${input.title}\n\n${input.content}`).catch(() => undefined);
|
|
50
|
+
return client.saveWikiPage({
|
|
51
|
+
title: input.title,
|
|
52
|
+
content: input.content,
|
|
53
|
+
tags: input.tags,
|
|
54
|
+
links: input.links,
|
|
55
|
+
devTaskId,
|
|
56
|
+
repo,
|
|
57
|
+
embedding,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.performSave = performSave;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildSessionContext = void 0;
|
|
4
|
+
// Matches session-start.sh's --max-time 5 per call. Promise.race does not cancel the
|
|
5
|
+
// losing fetch, so a hung backend still holds its socket — but the tool answers instead
|
|
6
|
+
// of hanging the conversation, which is the property that matters here.
|
|
7
|
+
const CALL_TIMEOUT_MS = 5000;
|
|
8
|
+
// Every leg degrades to empty rather than rejecting: this is startup context, and a
|
|
9
|
+
// half-populated recall is worth more to the model than a failed tool call. Mirrors
|
|
10
|
+
// session-start.sh, which tolerates any individual endpoint failing behind its cap.
|
|
11
|
+
function soft(p, fallback) {
|
|
12
|
+
// Attached before the race, not after: a rejection arriving once the timeout has
|
|
13
|
+
// already won would otherwise surface as an unhandled rejection and kill the process.
|
|
14
|
+
const handled = p.catch(() => fallback);
|
|
15
|
+
let timer;
|
|
16
|
+
const capped = new Promise((resolve) => {
|
|
17
|
+
timer = setTimeout(() => resolve(fallback), CALL_TIMEOUT_MS);
|
|
18
|
+
});
|
|
19
|
+
return Promise.race([handled, capped]).finally(() => clearTimeout(timer));
|
|
20
|
+
}
|
|
21
|
+
async function buildSessionContext(deps) {
|
|
22
|
+
const { client, currentRepoUid } = deps;
|
|
23
|
+
const [persona, factsSelf, factsTeam, skillsSelf, skillsTeam, repoUid] = await Promise.all([
|
|
24
|
+
// The one piece of context that does not depend on a repo, which makes it the most
|
|
25
|
+
// valuable leg for a host with no project directory. `configured: false` is the cue
|
|
26
|
+
// to offer setup once — without it Claude would have to nag every conversation.
|
|
27
|
+
soft(client.getPersona(), { configured: false }),
|
|
28
|
+
soft(client.recall({ scope: 'self' }), { facts: [] }),
|
|
29
|
+
soft(client.recall({ scope: 'team' }), { facts: [] }),
|
|
30
|
+
soft(client.listSkills({ scope: 'self' }), { skills: [] }),
|
|
31
|
+
soft(client.listSkills({ scope: 'team' }), { skills: [] }),
|
|
32
|
+
soft(currentRepoUid(), undefined),
|
|
33
|
+
]);
|
|
34
|
+
// The team query matches "mine OR visibility=Team", so it re-returns everything self
|
|
35
|
+
// already has; subtract it so the model isn't shown the same fact twice and weighing
|
|
36
|
+
// it as two independent sources.
|
|
37
|
+
const selfFacts = factsSelf.facts;
|
|
38
|
+
const teamFacts = without(factsTeam.facts, selfFacts);
|
|
39
|
+
const selfSkills = skillsSelf.skills;
|
|
40
|
+
const teamSkills = without(skillsTeam.skills, selfSkills);
|
|
41
|
+
// Second round, not part of the batch above: the repo-scoped calls can only be made
|
|
42
|
+
// once resolve-repo has returned a uid. Absent on Claude Desktop, which starts the
|
|
43
|
+
// server with no project directory — that is a supported shape, not a failure.
|
|
44
|
+
let repoFacts = [];
|
|
45
|
+
let repoSkills = [];
|
|
46
|
+
let wiki = [];
|
|
47
|
+
if (repoUid) {
|
|
48
|
+
const [f, s, w] = await Promise.all([
|
|
49
|
+
soft(client.recall({ scope: 'team', repo: repoUid }), { facts: [] }),
|
|
50
|
+
soft(client.listSkills({ scope: 'team', repo: repoUid }), { skills: [] }),
|
|
51
|
+
soft(client.recallWiki({ scope: 'team', repo: repoUid }), { pages: [] }),
|
|
52
|
+
]);
|
|
53
|
+
// {scope:team, repo} is a narrowing filter over the same set the two queries above
|
|
54
|
+
// already returned, so it overlaps both — subtract both. Wiki is fetched only here,
|
|
55
|
+
// so it has nothing to subtract against.
|
|
56
|
+
repoFacts = without(f.facts, selfFacts, teamFacts);
|
|
57
|
+
repoSkills = without(s.skills, selfSkills, teamSkills);
|
|
58
|
+
wiki = w.pages;
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
persona,
|
|
62
|
+
facts: { self: selfFacts.map(item), team: teamFacts.map(item), repo: repoFacts.map(item) },
|
|
63
|
+
skills: { self: selfSkills.map(item), team: teamSkills.map(item), repo: repoSkills.map(item) },
|
|
64
|
+
wiki: wiki.map(item),
|
|
65
|
+
repoScoped: Boolean(repoUid),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
exports.buildSessionContext = buildSessionContext;
|
|
69
|
+
function without(items, ...seen) {
|
|
70
|
+
const taken = new Set(seen.flat().map((x) => x.uid));
|
|
71
|
+
return items.filter((x) => !taken.has(x.uid));
|
|
72
|
+
}
|
|
73
|
+
function item(x) {
|
|
74
|
+
const content = x.title ? `${x.title}: ${x.content}` : x.content;
|
|
75
|
+
// Date only, no time: the model needs "is this stale", not an ordering key.
|
|
76
|
+
return x.lastModifiedDate ? { content, updated: x.lastModifiedDate.slice(0, 10) } : { content };
|
|
77
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.detectTeamNameHint = void 0;
|
|
4
|
+
// memory-hub-mcp/src/skedulo-package-hint.ts
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
/**
|
|
8
|
+
* Reads this process's own skeduloPackage.json (present at the root of every
|
|
9
|
+
* Skedulo solutions/CX repo) for an unauthoritative team-name hint. This is
|
|
10
|
+
* never a source of truth on its own — resolveRepo matches it against the
|
|
11
|
+
* calling agent's actual team memberships server-side; it only needs to be
|
|
12
|
+
* good enough to disambiguate the common case.
|
|
13
|
+
*/
|
|
14
|
+
function detectTeamNameHint(cwd = process.cwd()) {
|
|
15
|
+
try {
|
|
16
|
+
const raw = (0, fs_1.readFileSync)((0, path_1.join)(cwd, 'skeduloPackage.json'), 'utf8');
|
|
17
|
+
const pkg = JSON.parse(raw);
|
|
18
|
+
if (pkg.description && pkg.description.trim()) {
|
|
19
|
+
return pkg.description.trim();
|
|
20
|
+
}
|
|
21
|
+
if (pkg.name) {
|
|
22
|
+
const slug = pkg.name.split('/').pop();
|
|
23
|
+
return slug && slug.trim() ? slug.trim() : undefined;
|
|
24
|
+
}
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.detectTeamNameHint = detectTeamNameHint;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTaskContext = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Lazy per-process cache of resolved task uids, keyed by external ref —
|
|
6
|
+
* mirrors repo-context.ts's shape, but as a Map instead of a single cached
|
|
7
|
+
* value, since a session can reference several different tickets. A
|
|
8
|
+
* rejected resolution is evicted from the cache so a later call retries
|
|
9
|
+
* instead of permanently failing on a transient error.
|
|
10
|
+
*/
|
|
11
|
+
function createTaskContext(client) {
|
|
12
|
+
const cache = new Map();
|
|
13
|
+
return {
|
|
14
|
+
resolveTaskUid(externalRef, repoUid) {
|
|
15
|
+
const cached = cache.get(externalRef);
|
|
16
|
+
if (cached) {
|
|
17
|
+
return cached;
|
|
18
|
+
}
|
|
19
|
+
const pending = client.resolveTask({ externalRef, repoUid }).then((result) => result.uid);
|
|
20
|
+
pending.catch(() => cache.delete(externalRef));
|
|
21
|
+
cache.set(externalRef, pending);
|
|
22
|
+
return pending;
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
exports.createTaskContext = createTaskContext;
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@skedulo/memory-hub-mcp",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "MCP server for the SE AI Memory Hub: recall and save developer memory from Claude Code and Claude Desktop.",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+ssh://git@github.com/Skedulo/se-ai-memory-hub.git",
|
|
9
|
+
"directory": "memory-hub-mcp"
|
|
10
|
+
},
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=18"
|
|
13
|
+
},
|
|
14
|
+
"main": "dist/index.js",
|
|
15
|
+
"bin": {
|
|
16
|
+
"memory-hub-mcp": "dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist/**/*.js",
|
|
20
|
+
"!dist/**/*.test.js"
|
|
21
|
+
],
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "restricted"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsc",
|
|
27
|
+
"start": "node dist/index.js",
|
|
28
|
+
"test": "jest"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
32
|
+
"@xenova/transformers": "^2.17.2",
|
|
33
|
+
"axios": "^1.7.0",
|
|
34
|
+
"zod": "^3.25.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/jest": "^29.5.0",
|
|
38
|
+
"@types/node": "^20.0.0",
|
|
39
|
+
"jest": "^29.5.0",
|
|
40
|
+
"ts-jest": "^29.1.0",
|
|
41
|
+
"typescript": "5.4.5"
|
|
42
|
+
}
|
|
43
|
+
}
|