Skip to main content
Glama

extract_themes

Analyze manuscript content to identify and cluster main topics, helping writers organize and understand key themes in their writing projects.

Instructions

Cluster content into main themes/topics

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_pathNoPath to manuscript directory (defaults to current directory)
scopeNoFile scope pattern
num_themesNoNumber of themes to extract

Implementation Reference

  • Defines the input schema and description for the extract_themes MCP tool.
    { name: "extract_themes", description: "Cluster content into main themes/topics", inputSchema: { type: "object", properties: { project_path: { type: "string", description: "Path to manuscript directory (defaults to current directory)" }, scope: { type: "string", description: "File scope pattern" }, num_themes: { type: "number", description: "Number of themes to extract", default: 5 }, }, }, },
  • The handler function that processes the tool call, parses arguments (scope, num_themes), and delegates to WritersAid.extractThemes.
    private async extractThemes(args: Record<string, unknown>) { const scope = args.scope as string | undefined; const numThemes = (args.num_themes as number) || 5; return this.writersAid.extractThemes({ scope, numThemes }); }
  • Registers the extract_themes tool in the main handleTool switch statement, dispatching to the specific handler method.
    case "extract_themes": return this.extractThemes(args);
  • Core implementation of theme extraction using simple word frequency counting from manuscript files.
    async extractThemes(options?: ThemeOptions) { const { numThemes = 5 } = options || {}; const files = await this.storage.getAllFiles(); const wordFreq = new Map<string, number>(); // Simple theme extraction based on word frequency for (const file of files) { const words = file.content.toLowerCase().match(/\b\w+\b/g) || []; for (const word of words) { if (word.length > 4) { // Skip short words wordFreq.set(word, (wordFreq.get(word) || 0) + 1); } } } // Get top themes const themes = Array.from(wordFreq.entries()) .sort((a, b) => b[1] - a[1]) .slice(0, numThemes) .map(([word, count]) => ({ theme: word, count })); return themes; }
  • Intermediate delegation layer in WritersAid class from tool handler to ThemeExtractor.
    async extractThemes(options?: { scope?: string; numThemes?: number }) { return this.themeExtractor.extractThemes(options); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/xiaolai/claude-writers-aid-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server