@compilr-dev/sdk 0.2.2 → 0.2.3

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/dist/index.d.ts CHANGED
@@ -61,5 +61,7 @@ export { defineTool, createSuccessResult, createErrorResult, mergeHooks, createL
61
61
  export type { Tool, HooksConfig, AgentEvent, Message, LLMProvider, AnchorInput, ToolExecutionResult, AgentRunResult, PermissionHandler, ToolPermission, AgentTypeConfig, GuardrailTriggeredHandler, BeforeLLMHookResult, BeforeToolHook, BeforeToolHookResult, AfterToolHook, AgentState, AgentConfig, SessionInfo, Anchor, AnchorScope, AnchorClearOptions, AnchorPriority, AnchorQueryOptions, FileAccessType, FileAccess, GuardrailResult, GuardrailContext, MCPClient, MCPToolDefinition, } from '@compilr-dev/agents';
62
62
  export { DEFAULT_PERMISSION_RULES, findMatchingRule, permissionModeLabel, permissionLevelLabel, } from './permissions.js';
63
63
  export type { PermissionRule, PermissionMode, PermissionLevel } from './permissions.js';
64
+ export { readMCPConfigFile, writeMCPConfigFile, resolveServerEntry, loadMCPServers, saveMCPServerEntry, deleteMCPServerEntry, getServerNames, } from './mcp-config.js';
65
+ export type { MCPServerEntry, MCPConfigFile, ResolvedMCPServer } from './mcp-config.js';
64
66
  export { readFileTool, writeFileTool, createBashTool, bashTool, bashOutputTool, killShellTool, grepTool, globTool, editTool, todoWriteTool, todoReadTool, createTodoTools, TodoStore, webFetchTool, suggestTool, } from '@compilr-dev/agents';
65
67
  export { gitStatusTool, gitDiffTool, gitLogTool, gitCommitTool, gitBranchTool, gitStashTool, gitBlameTool, gitFileHistoryTool, detectProjectTool, findProjectRootTool, runTestsTool, runLintTool, runBuildTool, runFormatTool, findDefinitionTool, findReferencesTool, findTodosTool, checkOutdatedTool, findVulnerabilitiesTool, analyzeTestCoverageTool, getFileStructureTool, getComplexityTool, allCodingTools, unifiedTools, } from '@compilr-dev/agents-coding';
package/dist/index.js CHANGED
@@ -157,6 +157,10 @@ AgentError, ProviderError, ToolError, ToolTimeoutError, MaxIterationsError, Abor
157
157
  // =============================================================================
158
158
  export { DEFAULT_PERMISSION_RULES, findMatchingRule, permissionModeLabel, permissionLevelLabel, } from './permissions.js';
159
159
  // =============================================================================
160
+ // Shared MCP Configuration
161
+ // =============================================================================
162
+ export { readMCPConfigFile, writeMCPConfigFile, resolveServerEntry, loadMCPServers, saveMCPServerEntry, deleteMCPServerEntry, getServerNames, } from './mcp-config.js';
163
+ // =============================================================================
160
164
  // Individual Tool Re-exports (for consumers that build custom tool registries)
161
165
  // =============================================================================
162
166
  // Base tools from @compilr-dev/agents
@@ -0,0 +1,74 @@
1
+ /**
2
+ * MCP Configuration — shared types and file I/O for mcp.json
3
+ *
4
+ * Used by both @compilr-dev/cli and compilr-dev-desktop.
5
+ * Config format is compatible with Claude Desktop / Gemini CLI.
6
+ *
7
+ * File structure:
8
+ * { "mcpServers": { "name": { command?, url?, ... } } }
9
+ */
10
+ /**
11
+ * Single MCP server entry in the config file.
12
+ * If `command` is present → stdio transport.
13
+ * If `url` is present → HTTP transport.
14
+ */
15
+ export interface MCPServerEntry {
16
+ command?: string;
17
+ args?: string[];
18
+ env?: Record<string, string>;
19
+ cwd?: string;
20
+ url?: string;
21
+ headers?: Record<string, string>;
22
+ disabled?: boolean;
23
+ timeout?: number;
24
+ }
25
+ /**
26
+ * Shape of the mcp.json config file.
27
+ */
28
+ export interface MCPConfigFile {
29
+ mcpServers: Record<string, MCPServerEntry>;
30
+ }
31
+ /**
32
+ * Resolved MCP server config ready for MCPManager.
33
+ */
34
+ export interface ResolvedMCPServer {
35
+ name: string;
36
+ transport: 'stdio' | 'http';
37
+ command?: string;
38
+ args?: string[];
39
+ env?: Record<string, string>;
40
+ cwd?: string;
41
+ url?: string;
42
+ headers?: Record<string, string>;
43
+ timeout?: number;
44
+ }
45
+ /**
46
+ * Read and parse an mcp.json file. Returns empty record on any error.
47
+ */
48
+ export declare function readMCPConfigFile(filePath: string): Record<string, MCPServerEntry>;
49
+ /**
50
+ * Write servers to an mcp.json file (creates directory if needed).
51
+ */
52
+ export declare function writeMCPConfigFile(filePath: string, servers: Record<string, MCPServerEntry>): void;
53
+ /**
54
+ * Convert an MCPServerEntry to a ResolvedMCPServer.
55
+ * Returns null if the entry is invalid (neither command nor url) or disabled.
56
+ */
57
+ export declare function resolveServerEntry(name: string, entry: MCPServerEntry): ResolvedMCPServer | null;
58
+ /**
59
+ * Load and resolve MCP servers from one or more config file paths.
60
+ * Later paths override earlier ones (by server name).
61
+ */
62
+ export declare function loadMCPServers(...configPaths: string[]): ResolvedMCPServer[];
63
+ /**
64
+ * Save a single MCP server entry to a config file (add or overwrite by name).
65
+ */
66
+ export declare function saveMCPServerEntry(filePath: string, name: string, entry: MCPServerEntry): void;
67
+ /**
68
+ * Delete a single MCP server entry from a config file.
69
+ */
70
+ export declare function deleteMCPServerEntry(filePath: string, name: string): void;
71
+ /**
72
+ * Get all server names from one or more config files.
73
+ */
74
+ export declare function getServerNames(...configPaths: string[]): Set<string>;
@@ -0,0 +1,124 @@
1
+ /**
2
+ * MCP Configuration — shared types and file I/O for mcp.json
3
+ *
4
+ * Used by both @compilr-dev/cli and compilr-dev-desktop.
5
+ * Config format is compatible with Claude Desktop / Gemini CLI.
6
+ *
7
+ * File structure:
8
+ * { "mcpServers": { "name": { command?, url?, ... } } }
9
+ */
10
+ import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs';
11
+ import { dirname } from 'path';
12
+ // =============================================================================
13
+ // File I/O
14
+ // =============================================================================
15
+ /**
16
+ * Read and parse an mcp.json file. Returns empty record on any error.
17
+ */
18
+ export function readMCPConfigFile(filePath) {
19
+ try {
20
+ if (!existsSync(filePath))
21
+ return {};
22
+ const data = readFileSync(filePath, 'utf-8');
23
+ const parsed = JSON.parse(data);
24
+ if (parsed.mcpServers && typeof parsed.mcpServers === 'object') {
25
+ return parsed.mcpServers;
26
+ }
27
+ return {};
28
+ }
29
+ catch {
30
+ return {};
31
+ }
32
+ }
33
+ /**
34
+ * Write servers to an mcp.json file (creates directory if needed).
35
+ */
36
+ export function writeMCPConfigFile(filePath, servers) {
37
+ const dir = dirname(filePath);
38
+ if (!existsSync(dir)) {
39
+ mkdirSync(dir, { recursive: true });
40
+ }
41
+ const config = { mcpServers: servers };
42
+ writeFileSync(filePath, JSON.stringify(config, null, 2) + '\n', 'utf-8');
43
+ }
44
+ // =============================================================================
45
+ // Resolution
46
+ // =============================================================================
47
+ /**
48
+ * Convert an MCPServerEntry to a ResolvedMCPServer.
49
+ * Returns null if the entry is invalid (neither command nor url) or disabled.
50
+ */
51
+ export function resolveServerEntry(name, entry) {
52
+ if (entry.disabled)
53
+ return null;
54
+ if (entry.command) {
55
+ return {
56
+ name,
57
+ transport: 'stdio',
58
+ command: entry.command,
59
+ args: entry.args,
60
+ env: entry.env,
61
+ cwd: entry.cwd,
62
+ timeout: entry.timeout,
63
+ };
64
+ }
65
+ if (entry.url) {
66
+ return {
67
+ name,
68
+ transport: 'http',
69
+ url: entry.url,
70
+ headers: entry.headers,
71
+ timeout: entry.timeout,
72
+ };
73
+ }
74
+ return null;
75
+ }
76
+ // =============================================================================
77
+ // High-level helpers
78
+ // =============================================================================
79
+ /**
80
+ * Load and resolve MCP servers from one or more config file paths.
81
+ * Later paths override earlier ones (by server name).
82
+ */
83
+ export function loadMCPServers(...configPaths) {
84
+ const merged = {};
85
+ for (const p of configPaths) {
86
+ const servers = readMCPConfigFile(p);
87
+ Object.assign(merged, servers);
88
+ }
89
+ const resolved = [];
90
+ for (const [name, entry] of Object.entries(merged)) {
91
+ const server = resolveServerEntry(name, entry);
92
+ if (server)
93
+ resolved.push(server);
94
+ }
95
+ return resolved;
96
+ }
97
+ /**
98
+ * Save a single MCP server entry to a config file (add or overwrite by name).
99
+ */
100
+ export function saveMCPServerEntry(filePath, name, entry) {
101
+ const servers = readMCPConfigFile(filePath);
102
+ servers[name] = entry;
103
+ writeMCPConfigFile(filePath, servers);
104
+ }
105
+ /**
106
+ * Delete a single MCP server entry from a config file.
107
+ */
108
+ export function deleteMCPServerEntry(filePath, name) {
109
+ const servers = readMCPConfigFile(filePath);
110
+ const { [name]: _, ...rest } = servers;
111
+ writeMCPConfigFile(filePath, rest);
112
+ }
113
+ /**
114
+ * Get all server names from one or more config files.
115
+ */
116
+ export function getServerNames(...configPaths) {
117
+ const names = new Set();
118
+ for (const p of configPaths) {
119
+ for (const name of Object.keys(readMCPConfigFile(p))) {
120
+ names.add(name);
121
+ }
122
+ }
123
+ return names;
124
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@compilr-dev/sdk",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Universal agent runtime for building AI-powered applications",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",