secondbrainos-mcp-server 1.4.9 → 1.5.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/build/index.js +47 -61
- package/package.json +1 -1
package/build/index.js
CHANGED
|
@@ -318,25 +318,21 @@ class SecondBrainOSServer {
|
|
|
318
318
|
}
|
|
319
319
|
// Otherwise treat as a workflow prompt
|
|
320
320
|
const workflowId = this.workflowNameToId.get(promptName) || promptName;
|
|
321
|
-
//
|
|
321
|
+
// Single call — list response now includes prompt metadata per workflow
|
|
322
322
|
const workflowsData = await this.callRunPromptChain('', '');
|
|
323
323
|
const workflowMeta = (workflowsData.workflows || []).find((wf) => wf.workflow_id === workflowId);
|
|
324
|
-
const
|
|
325
|
-
|
|
326
|
-
if (promptIds.length === 0) {
|
|
324
|
+
const prompts = workflowMeta?.prompts || [];
|
|
325
|
+
if (prompts.length === 0) {
|
|
327
326
|
throw new McpError(ErrorCode.InvalidRequest, `No prompts found for workflow: ${workflowId}`);
|
|
328
327
|
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
};
|
|
338
|
-
}));
|
|
339
|
-
const sortedPrompts = promptResults.sort((a, b) => (a.order || 0) - (b.order || 0));
|
|
328
|
+
const sortedPrompts = prompts
|
|
329
|
+
.map((p) => ({
|
|
330
|
+
id: p.prompt_id,
|
|
331
|
+
name: p.name || '',
|
|
332
|
+
order: p.order || 0,
|
|
333
|
+
description: p.description || ''
|
|
334
|
+
}))
|
|
335
|
+
.sort((a, b) => (a.order || 0) - (b.order || 0));
|
|
340
336
|
const workflowDocument = {
|
|
341
337
|
skill_id: workflowId,
|
|
342
338
|
name: workflowMeta?.name || promptName,
|
|
@@ -521,31 +517,37 @@ class SecondBrainOSServer {
|
|
|
521
517
|
async fetchAndEnrichAgents() {
|
|
522
518
|
if (this.cachedAgents)
|
|
523
519
|
return this.cachedAgents;
|
|
524
|
-
|
|
525
|
-
const
|
|
526
|
-
|
|
520
|
+
// Fetch agents and all workflows in parallel
|
|
521
|
+
const [agentData, workflows] = await Promise.all([
|
|
522
|
+
this.callGetAIAgentsSchema(),
|
|
523
|
+
this.fetchAndEnrichWorkflows()
|
|
524
|
+
]);
|
|
525
|
+
const agents = agentData.agents || [];
|
|
526
|
+
// Build a prompt lookup from the already-fetched workflows
|
|
527
|
+
const promptLookup = new Map();
|
|
528
|
+
for (const wf of workflows) {
|
|
529
|
+
for (const p of wf.prompts || []) {
|
|
530
|
+
promptLookup.set(p.id, p);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
// Enrich agent workflows using the lookup — no extra API calls
|
|
527
534
|
for (const agent of agents) {
|
|
528
535
|
if (!agent.workflows)
|
|
529
536
|
continue;
|
|
530
537
|
for (const workflow of agent.workflows) {
|
|
531
538
|
if (!workflow.prompts || workflow.prompts.length === 0)
|
|
532
539
|
continue;
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
catch {
|
|
545
|
-
return { id: prompt.id, name: prompt.name, order: 0, description: '' };
|
|
546
|
-
}
|
|
547
|
-
}));
|
|
548
|
-
workflow.prompts = enrichedPrompts.sort((a, b) => (a.order || 0) - (b.order || 0));
|
|
540
|
+
workflow.prompts = workflow.prompts
|
|
541
|
+
.map((prompt) => {
|
|
542
|
+
const enriched = promptLookup.get(prompt.id);
|
|
543
|
+
return {
|
|
544
|
+
id: prompt.id,
|
|
545
|
+
name: enriched?.name || prompt.name,
|
|
546
|
+
order: enriched?.order || 0,
|
|
547
|
+
description: enriched?.description || ''
|
|
548
|
+
};
|
|
549
|
+
})
|
|
550
|
+
.sort((a, b) => (a.order || 0) - (b.order || 0));
|
|
549
551
|
}
|
|
550
552
|
}
|
|
551
553
|
this.cachedAgents = agents;
|
|
@@ -554,35 +556,19 @@ class SecondBrainOSServer {
|
|
|
554
556
|
async fetchAndEnrichWorkflows() {
|
|
555
557
|
if (this.cachedWorkflows)
|
|
556
558
|
return this.cachedWorkflows;
|
|
559
|
+
// Single API call — now returns all workflows with prompt metadata
|
|
557
560
|
const data = await this.callRunPromptChain('', '');
|
|
558
561
|
const workflows = (data.workflows || []).filter((wf) => wf.name && wf.workflow_id);
|
|
559
|
-
const enriched =
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
order: promptData.order,
|
|
570
|
-
description: promptData.description || ''
|
|
571
|
-
};
|
|
572
|
-
}
|
|
573
|
-
catch {
|
|
574
|
-
return { id: promptId, name: '', order: 0, description: '' };
|
|
575
|
-
}
|
|
576
|
-
}));
|
|
577
|
-
return {
|
|
578
|
-
...wf,
|
|
579
|
-
prompts: promptResults.sort((a, b) => (a.order || 0) - (b.order || 0))
|
|
580
|
-
};
|
|
581
|
-
}
|
|
582
|
-
catch (error) {
|
|
583
|
-
console.error(`Failed to enrich workflow "${wf.name}":`, error);
|
|
584
|
-
return { ...wf, prompts: [] };
|
|
585
|
-
}
|
|
562
|
+
const enriched = workflows.map((wf) => ({
|
|
563
|
+
...wf,
|
|
564
|
+
prompts: (wf.prompts || [])
|
|
565
|
+
.map((p) => ({
|
|
566
|
+
id: p.prompt_id,
|
|
567
|
+
name: p.name || '',
|
|
568
|
+
order: p.order || 0,
|
|
569
|
+
description: p.description || ''
|
|
570
|
+
}))
|
|
571
|
+
.sort((a, b) => (a.order || 0) - (b.order || 0))
|
|
586
572
|
}));
|
|
587
573
|
this.cachedWorkflows = enriched;
|
|
588
574
|
return enriched;
|