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. Using uvx (Recommended)

Run the server directly without installing:

# Using the main command
uvx wordmcp

# Or the alternative command name
uvx word-mcp

# When published to PyPI, you can also use:
# uvx word-mcp

For development or local testing with a wheel file:

# Build the package first
python -m build

# Run with local wheel
uvx --from ./dist/word_mcp-1.0.0-py3-none-any.whl wordmcp

2. Command Line Usage (After Installation)

Install and run the MCP server:

pip install word-mcp
word-mcp
# or
wordmcp

3. Module Usage

Run as a Python module:

python -m word_mcp

4. 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.1.tar.gz (28.5 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.1-py3-none-any.whl (34.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: word_mcp-1.0.1.tar.gz
  • Upload date:
  • Size: 28.5 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.1.tar.gz
Algorithm Hash digest
SHA256 685726a7716df34538bfc996c5728cb4e00dc3df69d1782f7853eb11264af357
MD5 132bb699cbe5653fb594735e2708a2b5
BLAKE2b-256 656bcb3f1459775a853c4d069483bbff9d7324a0fab52de45408a36e71489fbb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: word_mcp-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 34.5 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c15e5882ebd3117773ed37a461c5211750395cb0a9d6bde15c9139b0ccaa8cba
MD5 59c70345f735379d6bcc4cabaf51843a
BLAKE2b-256 342d449d8af92cf3bbad1ad6437ca3bdae58f32c658edabb1d7ef15ea08301c9

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