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);
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the action ('cluster content') but doesn't describe how it works (e.g., algorithm, processing time), what it returns (e.g., list of themes with examples), or any constraints (e.g., file size limits, supported formats). For a tool with 3 parameters and no annotations, this leaves significant gaps in understanding its behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero wasted words. It's front-loaded with the core purpose ('cluster content into main themes/topics'), making it immediately understandable. Every word earns its place by specifying the action and outcome without redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (thematic clustering with 3 parameters), lack of annotations, and no output schema, the description is incomplete. It doesn't explain the clustering method, output format, performance considerations, or error handling. For a tool that likely involves non-trivial processing, more context is needed to use it effectively beyond the basic purpose.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents all 3 parameters (project_path, scope, num_themes). The description adds no additional meaning about parameters beyond what's in the schema (e.g., it doesn't explain how 'scope' affects theme extraction or what 'num_themes' optimizes). With high schema coverage, the baseline score of 3 is appropriate as the description doesn't compensate but doesn't detract.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with a specific verb ('cluster') and resource ('content'), and specifies the output ('main themes/topics'). It distinguishes from most siblings (e.g., 'find_duplicates', 'search_content') by focusing on thematic analysis rather than search or validation. However, it doesn't explicitly differentiate from tools like 'suggest_reorganization' or 'analyze_link_graph' that might involve thematic grouping.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing content to analyze), exclusions (e.g., not for small documents), or comparisons to sibling tools like 'holistic_search' or 'suggest_reorganization' that might overlap in topic discovery. Usage is implied only by the purpose statement.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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