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.
Files changed (2) hide show
  1. package/build/index.js +47 -61
  2. 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
- // Fetch workflow metadata from the workflows list
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 workflowDetail = await this.callRunPromptChain('workflow', workflowId);
325
- const promptIds = workflowDetail.prompt_id || [];
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
- // Fetch prompt metadata (no instructions)
330
- const promptResults = await Promise.all(promptIds.map(async (promptId) => {
331
- const promptData = await this.callRunPromptChain('prompt', promptId);
332
- return {
333
- id: promptId,
334
- name: promptData.name,
335
- order: promptData.order,
336
- description: promptData.description || ''
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
- const data = await this.callGetAIAgentsSchema();
525
- const agents = data.agents || [];
526
- // Enrich each agent's workflows with full prompt details
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
- // Fetch prompt metadata (name, order, description) — no instructions
534
- const enrichedPrompts = await Promise.all(workflow.prompts.map(async (prompt) => {
535
- try {
536
- const promptData = await this.callRunPromptChain('prompt', prompt.id);
537
- return {
538
- id: prompt.id,
539
- name: promptData.name || prompt.name,
540
- order: promptData.order,
541
- description: promptData.description || ''
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 = await Promise.all(workflows.map(async (wf) => {
560
- try {
561
- const workflowDetail = await this.callRunPromptChain('workflow', wf.workflow_id);
562
- const promptIds = workflowDetail.prompt_id || [];
563
- const promptResults = await Promise.all(promptIds.map(async (promptId) => {
564
- try {
565
- const promptData = await this.callRunPromptChain('prompt', promptId);
566
- return {
567
- id: promptId,
568
- name: promptData.name,
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "secondbrainos-mcp-server",
3
- "version": "1.4.9",
3
+ "version": "1.5.1",
4
4
  "description": "Second Brain OS MCP Server for Claude Desktop",
5
5
  "type": "module",
6
6
  "main": "build/index.js",