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, }; } });

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