49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
import * as fs from 'fs';
|
|
import * as path from 'path';
|
|
import { MCPServerSettings } from './types';
|
|
|
|
const DEFAULT_SETTINGS: MCPServerSettings = {
|
|
port: 3000,
|
|
autoStart: false,
|
|
enableDebugLog: false,
|
|
allowedOrigins: ['*'],
|
|
maxConnections: 10
|
|
};
|
|
|
|
function getSettingsPath(): string {
|
|
return path.join(Editor.Project.path, 'settings', 'mcp-server.json');
|
|
}
|
|
|
|
function ensureSettingsDir(): void {
|
|
const settingsDir = path.dirname(getSettingsPath());
|
|
if (!fs.existsSync(settingsDir)) {
|
|
fs.mkdirSync(settingsDir, { recursive: true });
|
|
}
|
|
}
|
|
|
|
export function readSettings(): MCPServerSettings {
|
|
try {
|
|
ensureSettingsDir();
|
|
const settingsFile = getSettingsPath();
|
|
if (fs.existsSync(settingsFile)) {
|
|
const content = fs.readFileSync(settingsFile, 'utf8');
|
|
return { ...DEFAULT_SETTINGS, ...JSON.parse(content) };
|
|
}
|
|
} catch (e) {
|
|
console.error('Failed to read settings:', e);
|
|
}
|
|
return DEFAULT_SETTINGS;
|
|
}
|
|
|
|
export function saveSettings(settings: MCPServerSettings): void {
|
|
try {
|
|
ensureSettingsDir();
|
|
const settingsFile = getSettingsPath();
|
|
fs.writeFileSync(settingsFile, JSON.stringify(settings, null, 2));
|
|
} catch (e) {
|
|
console.error('Failed to save settings:', e);
|
|
throw e;
|
|
}
|
|
}
|
|
|
|
export { DEFAULT_SETTINGS }; |