google-context-mcp
Version:
Secure Google Search MCP server providing real-time coding context to AI models and LLMs - find latest docs, solutions, and best practices while coding
62 lines • 1.82 kB
JavaScript
import { promises as fs } from 'fs';
import { join } from 'path';
import { homedir } from 'os';
import { fileURLToPath } from 'url';
import { dirname } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
export class ConfigManager {
configPath;
config;
constructor() {
this.configPath = join(homedir(), '.google-context-mcp.json');
this.config = {};
}
async loadConfig() {
try {
const configData = await fs.readFile(this.configPath, 'utf-8');
this.config = JSON.parse(configData);
return this.config;
}
catch (error) {
this.config = {};
return this.config;
}
}
async saveConfig(config) {
this.config = { ...this.config, ...config };
await fs.writeFile(this.configPath, JSON.stringify(this.config, null, 2));
}
async getConfig() {
if (Object.keys(this.config).length === 0) {
await this.loadConfig();
}
return this.config;
}
async hasValidCredentials() {
const config = await this.getConfig();
return !!(config.googleApiKey && config.customSearchEngineId);
}
async getCredentials() {
const config = await this.getConfig();
if (config.googleApiKey && config.customSearchEngineId) {
return {
apiKey: config.googleApiKey,
customSearchEngineId: config.customSearchEngineId
};
}
return null;
}
getConfigPath() {
return this.configPath;
}
async resetConfig() {
this.config = {};
try {
await fs.unlink(this.configPath);
}
catch (error) {
}
}
}
//# sourceMappingURL=config-manager.js.map