Skip to main content
Glama

apply_text_formatting

Apply bold, italic, underline, or highlight formatting to specific text in Microsoft Word documents programmatically.

Instructions

Apply formatting to specific text in the document

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
docIdYesDocument identifier
searchTextYesText to format
formattingYes

Implementation Reference

  • Defines the Tool object for 'apply_text_formatting' including name, description, and input schema.
    { 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 list of tools including 'apply_text_formatting' via the documentTools array for ListToolsRequest.
    server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: documentTools, }; });
  • Generic tool handler dispatcher. 'apply_text_formatting' falls to default case throwing 'Unknown tool' error since no specific case.
    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}`); } }
  • src/index.ts:31-47 (registration)
    Registers the generic CallToolRequest handler which dispatches to handleToolCall for all tools including 'apply_text_formatting'.
    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