mirror of
https://github.com/penpot/penpot.git
synced 2026-04-05 02:42:35 +02:00
* ✨ Reduce instructions transferred at MCP connection to a minimum Force on-demand loading of the 'Penpot High-Level Overview', which was previously transferred in the MCP server's instructions. This greatly reduces the number of tokens for users who will not actually interact with Penpot, allowing the MCP server to remain enabled for such users without wasting too many tokens. Resolves #8647 * 📎 Update Serena project
52 lines
1.6 KiB
TypeScript
52 lines
1.6 KiB
TypeScript
import { existsSync, readFileSync } from "fs";
|
|
import { join } from "path";
|
|
import { createLogger } from "./logger.js";
|
|
|
|
/**
|
|
* Configuration loader for prompts and server settings.
|
|
*/
|
|
export class ConfigurationLoader {
|
|
private readonly logger = createLogger("ConfigurationLoader");
|
|
private readonly baseDir: string;
|
|
private readonly initialInstructions: string;
|
|
private readonly baseInstructions: string;
|
|
|
|
/**
|
|
* Creates a new configuration loader instance.
|
|
*
|
|
* @param baseDir - Base directory for resolving configuration file paths
|
|
*/
|
|
constructor(baseDir: string) {
|
|
this.baseDir = baseDir;
|
|
this.initialInstructions = this.loadFileContent(join(this.baseDir, "data", "initial_instructions.md"));
|
|
this.baseInstructions = this.loadFileContent(join(this.baseDir, "data", "base_instructions.md"));
|
|
}
|
|
|
|
private loadFileContent(filePath: string): string {
|
|
if (!existsSync(filePath)) {
|
|
throw new Error(`Configuration file not found at ${filePath}`);
|
|
}
|
|
return readFileSync(filePath, "utf8");
|
|
}
|
|
|
|
/**
|
|
* Gets the initial instructions for the MCP server corresponding to the
|
|
* 'Penpot High-Level Overview'
|
|
*
|
|
* @returns The initial instructions string
|
|
*/
|
|
public getInitialInstructions(): string {
|
|
return this.initialInstructions;
|
|
}
|
|
|
|
/**
|
|
* Gets the base instructions which shall be provided to clients when connecting to
|
|
* the MCP server
|
|
*
|
|
* @returns The initial instructions string
|
|
*/
|
|
public getBaseInstructions(): string {
|
|
return this.baseInstructions;
|
|
}
|
|
}
|