Skip to main content
Glama
zeph-gh

DOCX MCP Server

by zeph-gh

extract_text

Extract plain text content from DOCX files to access and process document information without formatting.

Instructions

Extract plain text content from a DOCX file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYesPath to the .docx file

Implementation Reference

  • The handler function implementing the 'extract_text' tool. It resolves the DOCX file path, extracts raw text using mammoth.extractRawText, computes word count, structures the output as MCP content blocks, and handles errors appropriately.
    async ({ file_path }) => {
      try {
        const absolutePath = path.resolve(file_path)
    
        if (!fs.existsSync(absolutePath)) {
          throw new Error(`File not found: ${absolutePath}`)
        }
    
        const result = await mammoth.extractRawText({ path: absolutePath })
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(
                {
                  text: result.value,
                  messages: result.messages,
                  word_count: result.value
                    .split(/\s+/)
                    .filter((word: string) => word.length > 0).length,
                },
                null,
                2
              ),
            },
          ],
        }
      } catch (error) {
        return {
          content: [
            {
              type: 'text',
              text: `Error extracting text: ${(error as Error).message}`,
            },
          ],
          isError: true,
        }
      }
    }
  • Zod input schema for the 'extract_text' tool, defining the required 'file_path' parameter.
    {
      file_path: z.string().describe('Path to the .docx file'),
    },
  • src/index.ts:19-65 (registration)
    MCP server registration of the 'extract_text' tool, specifying name, description, input schema, and handler function.
    server.tool(
      'extract_text',
      'Extract plain text content from a DOCX file',
      {
        file_path: z.string().describe('Path to the .docx file'),
      },
      async ({ file_path }) => {
        try {
          const absolutePath = path.resolve(file_path)
    
          if (!fs.existsSync(absolutePath)) {
            throw new Error(`File not found: ${absolutePath}`)
          }
    
          const result = await mammoth.extractRawText({ path: absolutePath })
    
          return {
            content: [
              {
                type: 'text',
                text: JSON.stringify(
                  {
                    text: result.value,
                    messages: result.messages,
                    word_count: result.value
                      .split(/\s+/)
                      .filter((word: string) => word.length > 0).length,
                  },
                  null,
                  2
                ),
              },
            ],
          }
        } catch (error) {
          return {
            content: [
              {
                type: 'text',
                text: `Error extracting text: ${(error as Error).message}`,
              },
            ],
            isError: true,
          }
        }
      }
    )
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states the action ('extract plain text content') but doesn't cover important traits: whether it handles errors (e.g., invalid files), what permissions are needed, if it modifies the original file, or the format of the output. This is inadequate for a tool with mutation implications.

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, clear sentence with zero waste. It's front-loaded with the core action and resource, making it highly efficient and easy to parse. Every word earns its place 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 no annotations and no output schema, the description is incomplete. It doesn't explain what 'plain text content' entails (e.g., stripped formatting, handling of tables/images) or potential errors. For a tool with implied file reading and content extraction, more context is needed to guide effective use.

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 already documents the single parameter 'file_path' with its description. The tool description adds no additional meaning beyond what the schema provides (e.g., no examples or constraints on file paths). Baseline 3 is appropriate 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 verb ('extract') and resource ('plain text content from a DOCX file'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'convert_to_html' or 'convert_to_markdown' which also extract content but in different formats, so it doesn't fully distinguish from alternatives.

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 like 'convert_to_html' or 'convert_to_markdown'. It doesn't mention prerequisites (e.g., file must be a valid DOCX) or exclusions (e.g., not for other file types). This leaves the agent with minimal context for tool selection.

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/zeph-gh/Docx-Mcp-Server'

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