Skip to main content
Glama
qpd-v

MCP Word Counter

by qpd-v

analyze_text

Count words and characters in a text document to analyze its structure and size. Use the tool to obtain precise statistics for any text file, aiding in effective document analysis.

Instructions

Count words and characters in a text document

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesPath to the text file to analyze

Implementation Reference

  • Core handler function that reads the file content and computes word count, total characters, and non-space characters.
    public async analyzeFile(filePath: string) {
      const text = await fs.readFile(filePath, 'utf-8');
      return {
        words: this.countWords(text),
        characters: this.countCharacters(text),
        charactersNoSpaces: this.countCharactersNoSpaces(text)
      };
    }
  • MCP server request handler for tool execution (CallToolRequestSchema) that specifically handles 'analyze_text' tool calls, including name check, parameter validation, delegation to WordCounter, response formatting, and error handling.
    server.setRequestHandler(CallToolRequestSchema, async (request) => {
      if (request.params.name !== "analyze_text") {
        throw new McpError(
          ErrorCode.MethodNotFound,
          `Unknown tool: ${request.params.name}`
        );
      }
    
      const filePath = request.params.arguments?.filePath;
      if (!filePath || typeof filePath !== "string") {
        throw new McpError(
          ErrorCode.InvalidParams,
          "File path parameter is required and must be a string"
        );
      }
    
      try {
        const stats = await wordCounter.analyzeFile(filePath);
        return {
          content: [
            {
              type: "text",
              text: `Analysis Results:
    • Word count: ${stats.words}
    • Character count (including spaces): ${stats.characters}
    • Character count (excluding spaces): ${stats.charactersNoSpaces}`
            }
          ]
        };
      } catch (error) {
        return {
          isError: true,
          content: [
            {
              type: "text",
              text: `Error analyzing file: ${error instanceof Error ? error.message : String(error)}`
            }
          ]
        };
      }
    });
  • Tool schema definition including name, description, and input schema requiring a 'filePath' string.
        {
          name: "analyze_text",
          description: "Count words and characters in a text document",
          inputSchema: {
            type: "object",
            properties: {
              filePath: {
                type: "string",
                description: "Path to the text file to analyze"
              }
            },
            required: ["filePath"]
          }
        }
      ]
    }));
  • src/index.ts:28-45 (registration)
    Registers the ListToolsRequestHandler which exposes the 'analyze_text' tool with its schema.
    server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: [
        {
          name: "analyze_text",
          description: "Count words and characters in a text document",
          inputSchema: {
            type: "object",
            properties: {
              filePath: {
                type: "string",
                description: "Path to the text file to analyze"
              }
            },
            required: ["filePath"]
          }
        }
      ]
    }));
  • Helper method for counting words by splitting text on whitespace sequences.
    private countWords(text: string): number {
      // Handle empty or whitespace-only strings
      if (!text.trim()) {
        return 0;
      }
    
      // Split by whitespace and filter out empty strings
      const words = text.trim().split(/\s+/).filter(word => word.length > 0);
      return words.length;
    }
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 mentions counting words and characters but does not describe how the tool behaves, such as whether it reads files safely, handles errors, or returns specific formats. For a tool with no annotations, this is a significant gap in transparency.

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 that directly states the tool's purpose without any wasted words. It is appropriately sized and front-loaded, making it easy to understand quickly. Every part of the sentence contributes to clarity.

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 has no annotations and no output schema, the description is incomplete. It lacks details on behavioral traits, error handling, or return values, which are crucial for an agent to use the tool correctly. For a tool with such minimal structured data, the description should provide more context.

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?

The input schema has 100% description coverage, with the parameter 'filePath' clearly documented. The description does not add any additional meaning or details about parameters beyond what the schema provides. According to the rules, with high schema coverage, the baseline score is 3, as the schema does the heavy lifting.

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 function as 'Count words and characters in a text document,' which specifies the verb (count) and resources (words, characters). It distinguishes the tool's purpose well, though without sibling tools, differentiation isn't needed. It's not a tautology and is specific enough for understanding.

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, prerequisites, or exclusions. It simply states what the tool does without context for usage, leaving the agent to infer based on the purpose alone. This lack of explicit guidelines reduces its helpfulness.

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

Related 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/qpd-v/mcp-wordcounter'

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