Skip to main content

A Model Context Protocol server for Microsoft Word integration

Project description

Word MCP Server

PyPI version Python Support License: MIT

A powerful Model Context Protocol (MCP) server for Microsoft Word integration, enabling AI assistants and automation tools to interact with Word documents across Windows and macOS platforms.

🚀 Features

  • Cross-platform Support: Works on both Windows and macOS
  • Document Automation: Read, write, and manipulate Word documents programmatically
  • AI-Powered Workflows: Perfect for document translation, content generation, and editing
  • Section-by-Section Processing: Systematically process documents paragraph by paragraph
  • State Management: Intelligent tracking of processed content to avoid infinite loops
  • Multiple Word Instances: Support for multiple Word documents simultaneously

📦 Installation

pip install word-mcp

Platform-Specific Requirements

Windows:

  • Microsoft Word (part of Microsoft Office)
  • pywin32 (automatically installed)

macOS:

  • Microsoft Word (part of Microsoft Office)
  • AppleScript support (built into macOS)

🛠️ Quick Start

1. Command Line Usage

Start the MCP server:

word-mcp

2. Programmatic Usage

import asyncio
from word_mcp import create_server, run_server

# Create a server instance
server = create_server("my-word-server")

# Or run the server directly
run_server("my-word-server")

3. Integration with AI Assistants

The server exposes the following MCP tools that AI assistants can use:

  • get_selection_text - Get currently selected text
  • replace_selection_text - Replace selected text with new content
  • select_next_section - Move to the next document section
  • find_and_select_section - Find and select text by keywords
  • list_word_instances - List all open Word documents

📖 Use Cases

Document Translation

Perfect for section-by-section translation workflows:

# AI assistant workflow:
# 1. select_next_section() -> finds next untranslated paragraph
# 2. get_selection_text() -> gets the content
# 3. [AI translates the text]
# 4. replace_selection_text() -> replaces with translation
# 5. Repeat until document is fully translated

Content Generation

Automate content creation and editing:

  • Generate documentation from templates
  • Apply consistent formatting across documents
  • Bulk content updates and modifications

Document Analysis

Extract and analyze document content:

  • Parse document structure
  • Extract specific sections or data
  • Generate summaries and reports

🔧 API Reference

Tools Available via MCP

get_selection_text

Retrieves the currently selected text from the active Word document.

Parameters:

  • instance_id (optional): Target specific Word instance

Returns:

{
  "text": "Selected content...",
  "instance_id": "word-instance-1"
}

replace_selection_text

Replaces the currently selected text with new content.

Parameters:

  • text: New text to insert
  • instance_id (optional): Target specific Word instance

Returns:

{
  "success": true,
  "instance_id": "word-instance-1"
}

select_next_section

Finds and selects the next section in the document.

Parameters:

  • section_type: Type of section ("paragraph", "heading", "any")
  • instance_id (optional): Target specific Word instance

Returns:

{
  "found": true,
  "section_text": "Next section content...",
  "section_type": "paragraph",
  "instance_id": "word-instance-1"
}

find_and_select_section

Finds and selects a section containing specific keywords.

Parameters:

  • keywords: Keywords to search for
  • section_type: Type of section to search in
  • instance_id (optional): Target specific Word instance

list_word_instances

Lists all currently running Word instances.

Returns:

{
  "instances": [
    {
      "instance_id": "word-instance-1",
      "document_title": "Document1.docx",
      "is_active": true
    }
  ]
}

🔒 Security & Permissions

Windows

  • Requires Microsoft Word to be installed and accessible
  • Uses COM automation (requires appropriate permissions)

macOS

  • Requires Microsoft Word to be installed
  • Uses AppleScript (may require accessibility permissions for some operations)
  • Grant permissions in System Preferences > Security & Privacy > Privacy > Accessibility

🐛 Troubleshooting

Common Issues

"No Word instances found"

  • Ensure Microsoft Word is running
  • Check that Word documents are open

"Platform not supported"

  • Currently supports Windows and macOS only
  • Linux support may be added in future versions

AppleScript permission errors (macOS)

  • Grant accessibility permissions to your terminal/IDE
  • System Preferences > Security & Privacy > Privacy > Accessibility

Debug Mode

Enable detailed logging:

import logging
logging.basicConfig(level=logging.DEBUG)

🤝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Setup

git clone https://github.com/word-mcp/word-mcp.git
cd word-mcp
pip install -e ".[dev]"

Running Tests

pytest tests/

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • Built on the Model Context Protocol
  • Inspired by the need for better AI-document integration
  • Thanks to the Microsoft Office automation community

📞 Support


Made with ❤️ for the AI automation community

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

word_mcp-1.0.0.tar.gz (18.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

word_mcp-1.0.0-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file word_mcp-1.0.0.tar.gz.

File metadata

  • Download URL: word_mcp-1.0.0.tar.gz
  • Upload date:
  • Size: 18.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for word_mcp-1.0.0.tar.gz
Algorithm Hash digest
SHA256 081abab98f4a58a2e2c725d7ab47a44e093efc765b96a37c3bc7cee6ce230ab8
MD5 bf5a4dc73c74fb22edc8adc1a019f381
BLAKE2b-256 9d981bf849caa3292a4b49064d9cfc288532415543ff04aea87009d2e7a8a400

See more details on using hashes here.

File details

Details for the file word_mcp-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: word_mcp-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 18.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for word_mcp-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fdd37574d951ae9569cb89fb668197d3d3045809414a2c2e5c538232a205b271
MD5 c13108a7523c114c0d8e8b4c2ed1ebeb
BLAKE2b-256 09bc5790f41503ce9882e4f12ebbbb295ae300cb55f070d4517af704f6d241cc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page