secondbrainos-mcp-server 1.4.3 → 1.4.4
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/build/index.js +55 -48
- package/package.json +1 -1
package/build/index.js
CHANGED
|
@@ -43,6 +43,7 @@ class SecondBrainOSServer {
|
|
|
43
43
|
this.workflowNameToId = new Map();
|
|
44
44
|
this.agentNameToId = new Map();
|
|
45
45
|
this.cachedAgents = null;
|
|
46
|
+
this.cachedWorkflows = null;
|
|
46
47
|
// Discover service paths from the OpenAPI schema
|
|
47
48
|
this.runPromptChainPath = null;
|
|
48
49
|
this.getAIAgentsSchemaPath = null;
|
|
@@ -205,24 +206,17 @@ class SecondBrainOSServer {
|
|
|
205
206
|
// List available prompts (user's workflows + agents)
|
|
206
207
|
this.server.setRequestHandler(ListPromptsRequestSchema, async () => {
|
|
207
208
|
const prompts = [];
|
|
208
|
-
// Fetch workflows as prompts
|
|
209
|
+
// Fetch workflows as prompts (uses cached enriched data)
|
|
209
210
|
if (this.runPromptChainPath) {
|
|
210
211
|
try {
|
|
211
|
-
const
|
|
212
|
-
const workflows = data.workflows || [];
|
|
212
|
+
const workflows = await this.fetchAndEnrichWorkflows();
|
|
213
213
|
this.workflowNameToId.clear();
|
|
214
214
|
for (const wf of workflows) {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
this.workflowNameToId.set(snakeName, wf.workflow_id);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
for (const wf of workflows) {
|
|
221
|
-
const skillName = wf.name || wf.workflow_id;
|
|
222
|
-
const snakeName = `skill_${toSnakeCase(skillName)}`;
|
|
215
|
+
const snakeName = `skill_${toSnakeCase(wf.name)}`;
|
|
216
|
+
this.workflowNameToId.set(snakeName, wf.workflow_id);
|
|
223
217
|
prompts.push({
|
|
224
218
|
name: snakeName,
|
|
225
|
-
title: `[Skill] ${
|
|
219
|
+
title: `[Skill] ${wf.name}`,
|
|
226
220
|
description: wf.description || wf.name,
|
|
227
221
|
arguments: [
|
|
228
222
|
{
|
|
@@ -570,6 +564,42 @@ class SecondBrainOSServer {
|
|
|
570
564
|
this.cachedAgents = agents;
|
|
571
565
|
return agents;
|
|
572
566
|
}
|
|
567
|
+
async fetchAndEnrichWorkflows() {
|
|
568
|
+
if (this.cachedWorkflows)
|
|
569
|
+
return this.cachedWorkflows;
|
|
570
|
+
const data = await this.callRunPromptChain('', '');
|
|
571
|
+
const workflows = (data.workflows || []).filter((wf) => wf.name && wf.workflow_id);
|
|
572
|
+
const enriched = await Promise.all(workflows.map(async (wf) => {
|
|
573
|
+
try {
|
|
574
|
+
const workflowDetail = await this.callRunPromptChain('workflow', wf.workflow_id);
|
|
575
|
+
const promptIds = workflowDetail.prompt_id || [];
|
|
576
|
+
const promptResults = await Promise.all(promptIds.map(async (promptId) => {
|
|
577
|
+
try {
|
|
578
|
+
const promptData = await this.callRunPromptChain('prompt', promptId);
|
|
579
|
+
return {
|
|
580
|
+
id: promptId,
|
|
581
|
+
name: promptData.name,
|
|
582
|
+
order: promptData.order,
|
|
583
|
+
description: promptData.description || ''
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
catch {
|
|
587
|
+
return { id: promptId, name: '', order: 0, description: '' };
|
|
588
|
+
}
|
|
589
|
+
}));
|
|
590
|
+
return {
|
|
591
|
+
...wf,
|
|
592
|
+
prompts: promptResults.sort((a, b) => (a.order || 0) - (b.order || 0))
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
catch (error) {
|
|
596
|
+
console.error(`Failed to enrich workflow "${wf.name}":`, error);
|
|
597
|
+
return { ...wf, prompts: [] };
|
|
598
|
+
}
|
|
599
|
+
}));
|
|
600
|
+
this.cachedWorkflows = enriched;
|
|
601
|
+
return enriched;
|
|
602
|
+
}
|
|
573
603
|
/**
|
|
574
604
|
* Write Claude Code skill files to ~/.claude/skills/secondbrainos/
|
|
575
605
|
* Called on every server startup so skills stay in sync with SBOS.
|
|
@@ -616,46 +646,23 @@ class SecondBrainOSServer {
|
|
|
616
646
|
console.error('Failed to write agent skill files:', error);
|
|
617
647
|
}
|
|
618
648
|
}
|
|
619
|
-
// 3. workflows (
|
|
649
|
+
// 3. workflows (uses cached enriched data)
|
|
620
650
|
if (this.runPromptChainPath) {
|
|
621
651
|
try {
|
|
622
|
-
const
|
|
623
|
-
const
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
id: promptId,
|
|
634
|
-
name: promptData.name,
|
|
635
|
-
order: promptData.order,
|
|
636
|
-
description: promptData.description || ''
|
|
637
|
-
};
|
|
638
|
-
}
|
|
639
|
-
catch {
|
|
640
|
-
return { id: promptId, name: '', order: 0, description: '' };
|
|
641
|
-
}
|
|
642
|
-
}));
|
|
643
|
-
const sortedPrompts = promptResults.sort((a, b) => (a.order || 0) - (b.order || 0));
|
|
644
|
-
const workflowDocument = {
|
|
645
|
-
skill_id: wf.workflow_id,
|
|
646
|
-
name: wf.name,
|
|
647
|
-
description: wf.description || '',
|
|
648
|
-
prompts: sortedPrompts
|
|
649
|
-
};
|
|
650
|
-
writeSkill(path.join(skillsBase, 'workflows', folderName), `---\nname: secondbrainos_skill_${folderName}\ndescription: "${wf.description || wf.name}"\nuser-invocable: false\n---\n\n${JSON.stringify(workflowDocument, null, 2)}\n`);
|
|
651
|
-
}
|
|
652
|
-
catch (error) {
|
|
653
|
-
console.error(`Failed to write skill file for workflow "${wf.name}":`, error);
|
|
654
|
-
}
|
|
655
|
-
}));
|
|
652
|
+
const workflows = await this.fetchAndEnrichWorkflows();
|
|
653
|
+
for (const wf of workflows) {
|
|
654
|
+
const folderName = toSnakeCase(wf.name);
|
|
655
|
+
const workflowDocument = {
|
|
656
|
+
skill_id: wf.workflow_id,
|
|
657
|
+
name: wf.name,
|
|
658
|
+
description: wf.description || '',
|
|
659
|
+
prompts: wf.prompts
|
|
660
|
+
};
|
|
661
|
+
writeSkill(path.join(skillsBase, 'workflows', folderName), `---\nname: secondbrainos_skill_${folderName}\ndescription: "${wf.description || wf.name}"\nuser-invocable: false\n---\n\n${JSON.stringify(workflowDocument, null, 2)}\n`);
|
|
662
|
+
}
|
|
656
663
|
}
|
|
657
664
|
catch (error) {
|
|
658
|
-
console.error('Failed to
|
|
665
|
+
console.error('Failed to write workflow skill files:', error);
|
|
659
666
|
}
|
|
660
667
|
}
|
|
661
668
|
// 4. knowledgebases
|