ConfigurationTools.jsā¢9.54 kB
export class ConfigurationTools {
constructor(configManager, factTypeManager) {
this.configManager = configManager;
this.factTypeManager = factTypeManager;
}
async registerTools(server) {
// Register config_list_fact_types tool
server.registerTool(
'config_list_fact_types',
'List all configured fact types with their properties',
{
type: 'object',
properties: {},
},
async (args) => {
return await this.handleListFactTypes(args);
}
);
// Register config_add_fact_type tool
server.registerTool(
'config_add_fact_type',
'Add a new fact type to the configuration',
{
type: 'object',
properties: {
type: {
type: 'string',
description: 'The name of the new fact type',
},
description: {
type: 'string',
description: 'Description of what this fact type represents',
},
priority: {
type: 'number',
description: 'Priority level (1-10, higher is more important)',
minimum: 1,
maximum: 10,
default: 5,
},
retentionMonths: {
type: 'number',
description: 'How many months to retain facts of this type',
minimum: 1,
default: 6,
},
scoringMultiplier: {
type: 'number',
description: 'Multiplier for quality scoring (0.5-2.0)',
minimum: 0.5,
maximum: 2.0,
default: 1.0,
},
keywords: {
type: 'array',
items: { type: 'string' },
description: 'Keywords that help classify content as this type',
},
color: {
type: 'string',
description: 'Color code for UI display (e.g., #FF0000)',
default: '#9E9E9E',
},
icon: {
type: 'string',
description: 'Icon/emoji for UI display',
default: 'š',
},
},
required: ['type', 'description'],
},
async (args) => {
return await this.handleAddFactType(args);
}
);
// Register config_update_scoring_weights tool
server.registerTool(
'config_update_scoring_weights',
'Update the weights used for quality scoring',
{
type: 'object',
properties: {
novelty: {
type: 'number',
description: 'Weight for novelty dimension (0-1)',
minimum: 0,
maximum: 1,
},
generalizability: {
type: 'number',
description: 'Weight for generalizability dimension (0-1)',
minimum: 0,
maximum: 1,
},
specificity: {
type: 'number',
description: 'Weight for specificity dimension (0-1)',
minimum: 0,
maximum: 1,
},
validation: {
type: 'number',
description: 'Weight for validation dimension (0-1)',
minimum: 0,
maximum: 1,
},
impact: {
type: 'number',
description: 'Weight for impact dimension (0-1)',
minimum: 0,
maximum: 1,
},
},
additionalProperties: false,
},
async (args) => {
return await this.handleUpdateScoringWeights(args);
}
);
// Register config_export tool
server.registerTool(
'config_export',
'Export all configuration as JSON',
{
type: 'object',
properties: {},
},
async (args) => {
return await this.handleExport(args);
}
);
// Register config_get_settings tool
server.registerTool(
'config_get_settings',
'Get current system settings',
{
type: 'object',
properties: {},
},
async (args) => {
return await this.handleGetSettings(args);
}
);
// Register config_validate tool
server.registerTool(
'config_validate',
'Validate current configuration for issues',
{
type: 'object',
properties: {},
},
async (args) => {
return await this.handleValidate(args);
}
);
}
async handleListFactTypes(args) {
try {
const factTypes = this.factTypeManager.getFactTypes();
let response = `āļø **Configured Fact Types:**\n\n`;
for (const [typeName, config] of Object.entries(factTypes)) {
response += `**${config.icon} ${config.name}**\n`;
response += `*${config.description}*\n`;
response += `Priority: ${config.priority} | Retention: ${config.retentionMonths} months | Multiplier: ${config.scoringMultiplier}\n`;
response += `Keywords: ${config.keywords.join(', ')}\n\n`;
}
return {
content: [
{
type: 'text',
text: response.trim(),
},
],
};
} catch (error) {
return {
content: [
{
type: 'text',
text: `Error listing fact types: ${error.message}`,
},
],
isError: true,
};
}
}
async handleAddFactType(args) {
try {
const { type, ...config } = args;
if (this.factTypeManager.getFactType(type)) {
throw new Error(`Fact type '${type}' already exists`);
}
await this.factTypeManager.addFactType(type, config);
return {
content: [
{
type: 'text',
text: `ā
Fact type '${type}' added successfully!\n\n**Description:** ${config.description}\n**Priority:** ${config.priority || 5}\n**Retention:** ${config.retentionMonths || 6} months`,
},
],
};
} catch (error) {
return {
content: [
{
type: 'text',
text: `Error adding fact type: ${error.message}`,
},
],
isError: true,
};
}
}
async handleUpdateScoringWeights(args) {
try {
const currentWeights = this.configManager.getScoringWeights() || {
novelty: 0.25,
generalizability: 0.25,
specificity: 0.2,
validation: 0.15,
impact: 0.15,
};
const newWeights = { ...currentWeights, ...args };
await this.configManager.saveScoringWeights(newWeights);
return {
content: [
{
type: 'text',
text: `ā
Scoring weights updated successfully!\n\n**New Weights:**\n- Novelty: ${newWeights.novelty}\n- Generalizability: ${newWeights.generalizability}\n- Specificity: ${newWeights.specificity}\n- Validation: ${newWeights.validation}\n- Impact: ${newWeights.impact}\n\n*Total: ${Object.values(newWeights).reduce((a, b) => a + b, 0).toFixed(3)}*`,
},
],
};
} catch (error) {
return {
content: [
{
type: 'text',
text: `Error updating scoring weights: ${error.message}`,
},
],
isError: true,
};
}
}
async handleExport(args) {
try {
const configData = await this.configManager.exportConfiguration();
return {
content: [
{
type: 'text',
text: `š¤ **Configuration Export**\n\n\`\`\`json\n${configData}\n\`\`\`\n\n*Copy this JSON to backup or share your configuration*`,
},
],
};
} catch (error) {
return {
content: [
{
type: 'text',
text: `Error exporting configuration: ${error.message}`,
},
],
isError: true,
};
}
}
async handleGetSettings(args) {
try {
const settings = this.configManager.getSettings();
let response = `āļø **System Settings**\n\n`;
for (const [key, value] of Object.entries(settings)) {
response += `**${key}:** ${typeof value === 'object' ? JSON.stringify(value) : value}\n`;
}
return {
content: [
{
type: 'text',
text: response.trim(),
},
],
};
} catch (error) {
return {
content: [
{
type: 'text',
text: `Error getting settings: ${error.message}`,
},
],
isError: true,
};
}
}
async handleValidate(args) {
try {
const validation = await this.configManager.validateConfiguration();
let response = `š **Configuration Validation**\n\n`;
response += `**Status:** ${validation.valid ? 'ā
Valid' : 'ā Issues Found'}\n`;
if (validation.issues.length > 0) {
response += `\n**Issues:**\n`;
for (const issue of validation.issues) {
response += `- ${issue}\n`;
}
} else {
response += `\n*No issues found. Configuration is valid.*`;
}
response += `\n\n*Checked at: ${validation.checkedAt}*`;
return {
content: [
{
type: 'text',
text: response,
},
],
};
} catch (error) {
return {
content: [
{
type: 'text',
text: `Error validating configuration: ${error.message}`,
},
],
isError: true,
};
}
}
}