Skip to main content
Glama

apply_text_formatting

Apply bold, italic, underline, or highlight formatting to specific text in Microsoft Word documents. Use this tool to modify text appearance by specifying search text and formatting options.

Instructions

Apply formatting to specific text in the document

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
docIdYesDocument identifier
searchTextYesText to format
formattingYes

Implementation Reference

  • Input schema definition for the 'apply_text_formatting' tool, specifying parameters docId, searchText, and formatting options.
    {
      name: "apply_text_formatting",
      description: "Apply formatting to specific text in the document",
      inputSchema: {
        type: "object",
        properties: {
          docId: {
            type: "string",
            description: "Document identifier",
          },
          searchText: {
            type: "string",
            description: "Text to format",
          },
          formatting: {
            type: "object",
            properties: {
              bold: { type: "boolean" },
              italic: { type: "boolean" },
              underline: { type: "boolean" },
              highlight: { type: "string", description: "Highlight color" },
            },
          },
        },
        required: ["docId", "searchText", "formatting"],
      },
    },
  • src/index.ts:24-28 (registration)
    Registers the documentTools array (including 'apply_text_formatting') with the MCP server for the ListTools request.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: documentTools,
      };
    });
  • Tool dispatcher function that handles calls to all registered tools; 'apply_text_formatting' falls through to default case throwing 'Unknown tool' error as no specific implementation exists.
    export async function handleToolCall(toolName: string, args: any) {
      switch (toolName) {
        case "create_document":
          const docId = documentManager.createDocument(args.filepath, args.title);
          return {
            content: [
              {
                type: "text",
                text: `Document created successfully with ID: ${docId}. Use this ID for all future operations on this document.`,
              },
            ],
          };
    
        case "add_heading":
          documentManager.addHeading(args.docId, args.text, args.level);
          return {
            content: [
              {
                type: "text",
                text: `Heading level ${args.level} added: "${args.text}"`,
              },
            ],
          };
    
        case "add_paragraph":
          documentManager.addParagraph(args.docId, args.text, args.formatting);
          return {
            content: [
              {
                type: "text",
                text: `Paragraph added successfully.`,
              },
            ],
          };
    
        case "add_bullet_list":
          documentManager.addBulletList(args.docId, args.items);
          return {
            content: [
              {
                type: "text",
                text: `Bullet list added with ${args.items.length} items.`,
              },
            ],
          };
    
        case "add_numbered_list":
          documentManager.addNumberedList(args.docId, args.items);
          return {
            content: [
              {
                type: "text",
                text: `Numbered list added with ${args.items.length} items.`,
              },
            ],
          };
    
        case "add_table":
          documentManager.addTable(args.docId, args.headers, args.rows);
          return {
            content: [
              {
                type: "text",
                text: `Table added with ${args.headers.length} columns and ${args.rows.length} rows.`,
              },
            ],
          };
    
        case "find_and_replace":
          const count = documentManager.findAndReplace(
            args.docId,
            args.findText,
            args.replaceText,
            args.replaceAll ?? true
          );
          return {
            content: [
              {
                type: "text",
                text: `Replaced ${count} occurrence(s) of "${args.findText}" with "${args.replaceText}".`,
              },
            ],
          };
    
        case "save_document":
          const filepath = await documentManager.saveDocument(args.docId);
          return {
            content: [
              {
                type: "text",
                text: `Document saved successfully to: ${filepath}`,
              },
            ],
          };
    
        case "get_document_structure":
          const structure = documentManager.getDocumentStructure(args.docId);
          return {
            content: [
              {
                type: "text",
                text: `Document structure:\n${structure}`,
              },
            ],
          };
    
        default:
          throw new Error(`Unknown tool: ${toolName}`);
      }
    }
  • MCP server request handler for tool execution that invokes handleToolCall for the specified tool name.
    // Handle tool calls
    server.setRequestHandler(CallToolRequestSchema, async (request) => {
      try {
        const result = await handleToolCall(request.params.name, request.params.arguments);
        return result;
      } catch (error) {
        const errorMessage = error instanceof Error ? error.message : String(error);
        return {
          content: [
            {
              type: "text",
              text: `Error: ${errorMessage}`,
            },
          ],
          isError: true,
        };
      }
    });
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 implies a mutation operation ('apply formatting'), but doesn't specify whether this requires write permissions, if changes are reversible, potential side effects, or error conditions. For a tool that modifies documents, this lack of detail is a significant gap.

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 function without unnecessary words. It's front-loaded and wastes no space, making it easy for an agent to parse quickly.

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 complexity of a document formatting tool with 3 parameters, no annotations, no output schema, and moderate schema coverage, the description is insufficient. It doesn't address behavioral aspects like permissions or side effects, provide usage context, or detail parameter nuances, leaving critical gaps for effective tool invocation.

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 schema description coverage is 67%, with 'docId' and 'searchText' well-described, but 'formatting' object properties lack descriptions. The description adds no parameter semantics beyond the schema, such as explaining how 'searchText' matches text or what 'highlight' color values are valid. Since coverage is moderate, the baseline is 3, but it doesn't compensate for the gaps.

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 'apply' and the resource 'formatting to specific text in the document', making the purpose understandable. However, it doesn't explicitly distinguish this tool from sibling tools like 'find_and_replace' or 'add_heading', which might also involve text manipulation in documents, so it misses full sibling differentiation.

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, such as needing an existing document, or compare it to siblings like 'find_and_replace' for text modifications or 'add_heading' for structural changes, leaving the agent to infer usage from context alone.

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/bibash44/word-documet-mcp-server'

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