config.ts•6.13 kB
import { readFileSync, existsSync } from 'fs';
import { ACIConfig } from '../services/aciApi.js';
export interface ACIServerConfig {
name: string;
toolSelectionMode: 'whitelist' | 'blacklist';
enableAllTools: boolean;
tenantFocus?: string; // Focus on specific tenant
}
export interface ToolConfiguration {
enabledTools: string[];
disabledTools: string[];
}
export interface MCPServerConfig {
serverConfig: ACIServerConfig;
toolConfiguration: ToolConfiguration;
}
// Core essential tools for basic ACI operations
const CORE_TOOLS = [
// Tenant Management (6 tools)
'list_tenants',
'get_tenant',
'create_tenant',
'update_tenant',
'delete_tenant',
'get_tenant_health',
// Application Profile Management (5 tools)
'list_application_profiles',
'get_application_profile',
'create_application_profile',
'update_application_profile',
'delete_application_profile',
// Endpoint Group Management (6 tools)
'list_endpoint_groups',
'get_endpoint_group',
'create_endpoint_group',
'update_endpoint_group',
'delete_endpoint_group',
'get_endpoint_group_stats',
// Bridge Domain Management (5 tools)
'list_bridge_domains',
'get_bridge_domain',
'create_bridge_domain',
'update_bridge_domain',
'delete_bridge_domain',
// VRF Management (5 tools)
'list_vrfs',
'get_vrf',
'create_vrf',
'update_vrf',
'delete_vrf',
// Contract Management (8 tools)
'list_contracts',
'get_contract',
'create_contract',
'update_contract',
'delete_contract',
'list_filters',
'create_filter',
'delete_filter',
// Monitoring & Health (8 tools)
'get_fabric_health',
'list_faults',
'get_fault_summary',
'list_nodes',
'get_node_health',
'list_interfaces',
'get_interface_stats',
'get_system_info',
// Physical Infrastructure (5 tools)
'list_physical_domains',
'list_vlan_pools',
'get_vlan_pool',
'list_leaf_switches',
'list_spine_switches'
];
// All available tools (expanded set)
const ALL_TOOLS = [
...CORE_TOOLS,
// Advanced Tenant Operations
'backup_tenant',
'restore_tenant',
'export_tenant_config',
'import_tenant_config',
// Advanced Networking
'create_subnet',
'list_subnets',
'delete_subnet',
'create_l3out',
'list_l3outs',
'delete_l3out',
'create_external_epg',
'list_external_epgs',
// Policy Management
'list_qos_policies',
'create_qos_policy',
'list_access_policies',
'create_access_policy',
'list_switch_policies',
'create_switch_policy',
// Monitoring & Analytics
'get_endpoint_tracker',
'get_traffic_analytics',
'get_policy_usage',
'get_capacity_dashboard',
'get_security_dashboard',
// Fabric Management
'list_fabric_policies',
'create_fabric_policy',
'get_fabric_topology',
'get_fabric_forwarding',
'perform_fabric_upgrade',
// Troubleshooting
'trace_route',
'ping_endpoint',
'get_forwarding_table',
'get_routing_table',
'analyze_policy_conflicts'
];
export function loadConfig(): ACIConfig {
const configFile = process.env.ACI_CONFIG_FILE || './aci-config.json';
if (existsSync(configFile)) {
const configData = JSON.parse(readFileSync(configFile, 'utf8'));
return configData;
}
// Try environment variables
const config: ACIConfig = {
apicUrl: process.env.ACI_APIC_URL || 'https://apic.example.com',
username: process.env.ACI_USERNAME || '',
password: process.env.ACI_PASSWORD,
certificateName: process.env.ACI_CERT_NAME,
privateKey: process.env.ACI_PRIVATE_KEY_PATH ?
readFileSync(process.env.ACI_PRIVATE_KEY_PATH, 'utf8') : undefined,
validateCerts: process.env.ACI_VALIDATE_CERTS?.toLowerCase() === 'true',
timeout: parseInt(process.env.ACI_TIMEOUT || '30000')
};
if (!config.username) {
throw new Error('ACI username not configured');
}
if (!config.password && !config.privateKey) {
throw new Error('ACI password or private key not configured');
}
return config;
}
export function loadMCPServerConfig(): MCPServerConfig {
const configPath = process.env.ACI_MCP_CONFIG_FILE || './aci-mcp-config.json';
let config: MCPServerConfig;
try {
if (existsSync(configPath)) {
config = JSON.parse(readFileSync(configPath, 'utf8'));
} else {
// Default configuration
const toolMode = process.env.ACI_TOOL_MODE || 'core';
config = {
serverConfig: {
name: 'aci',
toolSelectionMode: 'whitelist',
enableAllTools: toolMode === 'all',
tenantFocus: process.env.ACI_TENANT_FOCUS
},
toolConfiguration: {
enabledTools: toolMode === 'all' ? ALL_TOOLS : CORE_TOOLS,
disabledTools: []
}
};
}
} catch (error) {
console.error('Error loading MCP config, using defaults:', error);
const toolMode = process.env.ACI_TOOL_MODE || 'core';
config = {
serverConfig: {
name: 'aci',
toolSelectionMode: 'whitelist',
enableAllTools: toolMode === 'all',
tenantFocus: process.env.ACI_TENANT_FOCUS
},
toolConfiguration: {
enabledTools: toolMode === 'all' ? ALL_TOOLS : CORE_TOOLS,
disabledTools: []
}
};
}
return config;
}
export function isToolEnabled(toolName: string, config: MCPServerConfig): boolean {
const { toolConfiguration, serverConfig } = config;
if (serverConfig.enableAllTools) {
return !toolConfiguration.disabledTools.includes(toolName);
}
if (serverConfig.toolSelectionMode === 'whitelist') {
return toolConfiguration.enabledTools.includes(toolName);
} else {
return !toolConfiguration.disabledTools.includes(toolName);
}
}
export function getEnabledTools(config: MCPServerConfig): string[] {
if (config.serverConfig.enableAllTools) {
return ALL_TOOLS.filter(tool => !config.toolConfiguration.disabledTools.includes(tool));
}
if (config.serverConfig.toolSelectionMode === 'whitelist') {
return config.toolConfiguration.enabledTools;
} else {
return ALL_TOOLS.filter(tool => !config.toolConfiguration.disabledTools.includes(tool));
}
}
export { CORE_TOOLS, ALL_TOOLS };