@deimoscloud/coreai 0.1.0 → 0.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deimoscloud/coreai",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "A configurable, team-ready AI agent orchestration platform",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -8,6 +8,7 @@ import { existsSync, mkdirSync, writeFileSync } from 'fs';
8
8
  import { join, dirname } from 'path';
9
9
  import type { CoreAIConfig } from '../config/types.js';
10
10
  import type { AgentDefinition, AgentMetadata, AgentSource } from './types.js';
11
+ import { DEFAULT_AGENT_TOOLS } from './types.js';
11
12
  import { loadAgentsFromDirectory } from './loader.js';
12
13
  import { resolveAgentDefinition } from './resolver.js';
13
14
 
@@ -44,6 +45,13 @@ export interface CompileOptions {
44
45
  * Returns true to include the agent, false to exclude.
45
46
  */
46
47
  filter?: (agent: AgentDefinition) => boolean;
48
+
49
+ /**
50
+ * MCP server names to include as tools.
51
+ * These will be added to the agent's tools as mcp__<server-name>.
52
+ * Example: ['github', 'postgres'] -> 'mcp__github, mcp__postgres'
53
+ */
54
+ mcpServers?: string[];
47
55
  }
48
56
 
49
57
  /**
@@ -69,12 +77,53 @@ export interface CompileResult {
69
77
  }[];
70
78
  }
71
79
 
80
+ /**
81
+ * Build the tools string for agent frontmatter
82
+ *
83
+ * @param agent - Agent definition (may have custom tools)
84
+ * @param mcpServers - Optional MCP server names to include
85
+ * @returns Comma-separated list of tools
86
+ */
87
+ export function buildAgentTools(agent: AgentDefinition, mcpServers?: string[]): string {
88
+ // Start with agent-specific tools or defaults
89
+ const tools: string[] = agent.tools
90
+ ? [...agent.tools]
91
+ : [...DEFAULT_AGENT_TOOLS];
92
+
93
+ // Add MCP tools if servers are specified
94
+ if (mcpServers && mcpServers.length > 0) {
95
+ for (const server of mcpServers) {
96
+ tools.push(`mcp__${server}`);
97
+ }
98
+ }
99
+
100
+ return tools.join(', ');
101
+ }
102
+
72
103
  /**
73
104
  * Generate markdown content from a resolved agent definition
105
+ *
106
+ * The output includes YAML frontmatter required by Claude Code for subagent detection.
107
+ * See: https://code.claude.com/docs/en/sub-agents
108
+ *
109
+ * @param agent - Resolved agent definition
110
+ * @param mcpServers - Optional MCP server names to include as tools
74
111
  */
75
- export function generateAgentMarkdown(agent: AgentDefinition): string {
112
+ export function generateAgentMarkdown(agent: AgentDefinition, mcpServers?: string[]): string {
76
113
  const lines: string[] = [];
77
114
 
115
+ // Build tools string
116
+ const tools = buildAgentTools(agent, mcpServers);
117
+
118
+ // YAML frontmatter (required by Claude Code for subagent detection)
119
+ lines.push('---');
120
+ lines.push(`name: ${agent.role}`);
121
+ // Flatten description to single line for YAML frontmatter
122
+ lines.push(`description: ${agent.description.replace(/\n/g, ' ').trim()}`);
123
+ lines.push(`tools: ${tools}`);
124
+ lines.push('---');
125
+ lines.push('');
126
+
78
127
  // Header
79
128
  lines.push(`# ${agent.display_name}`);
80
129
  lines.push('');
@@ -235,10 +284,18 @@ function formatTitle(str: string): string {
235
284
 
236
285
  /**
237
286
  * Compile a single agent to markdown
287
+ *
288
+ * @param agent - Agent definition to compile
289
+ * @param config - Optional CoreAI config for variable resolution
290
+ * @param mcpServers - Optional MCP server names to include as tools
238
291
  */
239
- export function compileAgent(agent: AgentDefinition, config?: CoreAIConfig): string {
292
+ export function compileAgent(
293
+ agent: AgentDefinition,
294
+ config?: CoreAIConfig,
295
+ mcpServers?: string[]
296
+ ): string {
240
297
  const resolved = resolveAgentDefinition(agent, config);
241
- return generateAgentMarkdown(resolved);
298
+ return generateAgentMarkdown(resolved, mcpServers);
242
299
  }
243
300
 
244
301
  /**
@@ -328,7 +385,7 @@ export function compileAgents(config?: CoreAIConfig, options: CompileOptions = {
328
385
  }
329
386
 
330
387
  try {
331
- const markdown = compileAgent(metadata.definition, config);
388
+ const markdown = compileAgent(metadata.definition, config, options.mcpServers);
332
389
  const outputPath = join(outputDir, `${role}.md`);
333
390
 
334
391
  writeFileSync(outputPath, markdown, 'utf-8');
@@ -25,6 +25,7 @@ export {
25
25
  type ResolutionOptions,
26
26
  } from './resolver.js';
27
27
  export {
28
+ buildAgentTools,
28
29
  generateAgentMarkdown,
29
30
  compileAgent,
30
31
  compileAgents,
@@ -42,6 +42,11 @@ export interface AgentCommunication {
42
42
  outbox?: string;
43
43
  }
44
44
 
45
+ /**
46
+ * Default Claude Code tools available to agents
47
+ */
48
+ export const DEFAULT_AGENT_TOOLS = ['Read', 'Write', 'Edit', 'Bash', 'Glob', 'Grep'] as const;
49
+
45
50
  /**
46
51
  * Raw agent definition as loaded from YAML (before variable resolution)
47
52
  */
@@ -57,6 +62,11 @@ export interface AgentDefinition {
57
62
  behaviors?: AgentBehaviors;
58
63
  context_sources?: AgentContextSources;
59
64
  communication?: AgentCommunication;
65
+ /**
66
+ * Claude Code tools available to this agent.
67
+ * If not specified, defaults to: Read, Write, Edit, Bash, Glob, Grep
68
+ */
69
+ tools?: string[];
60
70
  }
61
71
 
62
72
  /**
@@ -8,6 +8,7 @@ import { configExists, loadConfig, ConfigError } from '../../config/loader.js';
8
8
  import type { ResolvedCoreAIConfig } from '../../config/types.js';
9
9
  import { compileAgents, type CompileOptions, type CompileResult } from '../../agents/index.js';
10
10
  import { initAgentKnowledgeLibrary } from '../../knowledge-library/index.js';
11
+ import { discoverMcpServers } from '../../adapters/mcp/index.js';
11
12
 
12
13
  /**
13
14
  * Options for build command
@@ -47,6 +48,14 @@ export interface BuildCommandOptions {
47
48
  * Initialize KnowledgeLibrary directories for agents
48
49
  */
49
50
  initKnowledgeLibrary?: boolean;
51
+
52
+ /**
53
+ * Include MCP servers as agent tools.
54
+ * If true, discovers MCP servers from config files.
55
+ * If an array, uses the specified server names.
56
+ * Default: true (auto-discover)
57
+ */
58
+ mcpServers?: boolean | string[];
50
59
  }
51
60
 
52
61
  /**
@@ -59,6 +68,7 @@ export interface BuildCommandResult {
59
68
  error?: string;
60
69
  warnings?: string[];
61
70
  knowledgeLibraryInitialized?: string[];
71
+ mcpServers?: string[];
62
72
  }
63
73
 
64
74
  /**
@@ -108,6 +118,29 @@ export function build(options: BuildCommandOptions = {}): BuildCommandResult {
108
118
  compileOptions.filter = (agent) => agentsList.includes(agent.role);
109
119
  }
110
120
 
121
+ // Discover MCP servers for tools
122
+ const includeMcpServers = options.mcpServers ?? true;
123
+ if (includeMcpServers !== false) {
124
+ try {
125
+ if (Array.isArray(includeMcpServers)) {
126
+ // Use explicitly provided server names
127
+ compileOptions.mcpServers = includeMcpServers;
128
+ } else {
129
+ // Auto-discover from config files
130
+ const discoveredServers = discoverMcpServers({
131
+ projectRoot,
132
+ includeGlobal: false, // Only use project-level MCP config
133
+ });
134
+ if (discoveredServers.length > 0) {
135
+ compileOptions.mcpServers = discoveredServers.map((s) => s.name);
136
+ }
137
+ }
138
+ } catch {
139
+ // MCP discovery failed, continue without MCP tools
140
+ // This is non-fatal - agents will just use default tools
141
+ }
142
+ }
143
+
111
144
  // Compile agents
112
145
  try {
113
146
  const result = compileAgents(config, compileOptions);
@@ -144,6 +177,7 @@ export function build(options: BuildCommandOptions = {}): BuildCommandResult {
144
177
  config,
145
178
  warnings: warnings.length > 0 ? warnings : undefined,
146
179
  knowledgeLibraryInitialized,
180
+ mcpServers: compileOptions.mcpServers,
147
181
  };
148
182
  } catch (error) {
149
183
  return {
@@ -227,6 +261,12 @@ export function formatBuildResult(result: BuildCommandResult): string {
227
261
  lines.push('');
228
262
  }
229
263
 
264
+ // MCP servers included
265
+ if (result.mcpServers && result.mcpServers.length > 0) {
266
+ lines.push(`MCP tools included: ${result.mcpServers.map((s) => `mcp__${s}`).join(', ')}`);
267
+ lines.push('');
268
+ }
269
+
230
270
  // KnowledgeLibrary initialization
231
271
  if (result.knowledgeLibraryInitialized && result.knowledgeLibraryInitialized.length > 0) {
232
272
  lines.push(