Skip to main content

Outlook automation bridge for WSL2 via COM with MCP server for Claude Code

Project description

Mailtool - Outlook Automation Bridge

A Python library and CLI tool for accessing Outlook email, calendar, and tasks from WSL2 via Windows COM automation.

Uses uv for dependency management - no global Python needed!

๐Ÿš€ Installation

PyPI Installation (Recommended)

# Install via pip
pip install mailtool

# Or via uv
uv pip install mailtool

Claude Code Integration

For Claude Code integration, install the mailtool-plugin package:

/plugin marketplace add utsmok/mailtool-plugin
/plugin install mailtool

This will configure the MCP server with 24 tools for email, calendar, and task management.

Prerequisites

  • Windows with Outlook (classic) installed and running
  • WSL2 with uv installed (pip install uv or curl -LsSf https://astral.sh/uv/install.sh | sh)
  • uv.exe accessible from WSL2 (automatically available if installed on Windows)

Setup

1. Start Outlook

Make sure Outlook is running and logged into your s.mok@utwente.nl account.

2. That's it!

Dependencies are managed automatically by uv. No manual pip installs needed.

Usage

As a Python Library

from mailtool.bridge import OutlookBridge

# Create bridge instance
bridge = OutlookBridge()

# List emails
emails = bridge.list_emails(limit=5)
for email in emails:
    print(f"{email['subject']}: {email['sender']}")

# Create appointment
entry_id = bridge.create_appointment(
    subject="Team Meeting",
    start="2025-01-20 14:00:00",
    end="2025-01-20 15:00:00",
    location="Room 101"
)

As a CLI Tool

# List recent emails
mailtool emails --limit 5

# List calendar events for next 7 days
mailtool calendar --days 7

# Get specific email body (use entry_id from emails command)
mailtool email --id <entry_id>

As an MCP Server (for Claude Code)

See the mailtool-plugin repository for Claude Code integration instructions.

How It Works

The library uses Windows COM automation to communicate with Outlook:

  1. Python creates a COM object to access the running Outlook instance
  2. Uses O(1) direct lookups via GetItemFromID() for performance
  3. Returns structured data (emails, calendar events, tasks) as Python dictionaries
  4. MCP server mode exposes this functionality via JSON-RPC for AI agents

Project Structure

mailtool/
โ”œโ”€โ”€ pyproject.toml          # uv project config
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ mailtool/
โ”‚       โ”œโ”€โ”€ __init__.py
โ”‚       โ”œโ”€โ”€ bridge.py       # Core COM automation (~1100 lines)
โ”‚       โ”œโ”€โ”€ cli.py          # CLI interface
โ”‚       โ””โ”€โ”€ mcp/            # MCP Server (SDK v2 + FastMCP)
โ”‚           โ”œโ”€โ”€ __init__.py
โ”‚           โ”œโ”€โ”€ server.py   # FastMCP server with 24 tools
โ”‚           โ”œโ”€โ”€ models.py   # Pydantic models
โ”‚           โ”œโ”€โ”€ lifespan.py # Async COM bridge lifecycle
โ”‚           โ”œโ”€โ”€ resources.py # 7 resources
โ”‚           โ””โ”€โ”€ exceptions.py # Custom exceptions
โ”œโ”€โ”€ tests/
โ”‚   โ”œโ”€โ”€ conftest.py         # Test fixtures
โ”‚   โ”œโ”€โ”€ test_bridge.py      # Core connectivity tests
โ”‚   โ”œโ”€โ”€ test_emails.py      # Email operation tests
โ”‚   โ”œโ”€โ”€ test_calendar.py    # Calendar operation tests
โ”‚   โ”œโ”€โ”€ test_tasks.py       # Task operation tests
โ”‚   โ””โ”€โ”€ mcp/                # MCP server tests
โ”‚       โ”œโ”€โ”€ test_models.py      # Pydantic model tests
โ”‚       โ”œโ”€โ”€ test_tools.py       # Tool implementation tests
โ”‚       โ”œโ”€โ”€ test_resources.py   # Resource tests
โ”‚       โ”œโ”€โ”€ test_integration.py # End-to-end workflow tests
โ”‚       โ””โ”€โ”€ test_exceptions.py  # Exception class tests
โ”œโ”€โ”€ docs/                   # Documentation
โ””โ”€โ”€ .github/
    โ””โ”€โ”€ workflows/
        โ”œโ”€โ”€ ci.yml          # Continuous Integration
        โ””โ”€โ”€ publish.yml     # PyPI publishing

Advantages

  • โœ… uv for dependencies - No global Python pollution
  • โœ… Official MCP SDK v2 - Type-safe, well-documented, maintainable
  • โœ… Structured output - Pydantic models for all tool results
  • โœ… 7 Resources - Quick data access without tool calls
  • โœ… No API registration - Uses existing Outlook auth
  • โœ… Works with any Outlook account
  • โœ… Full access to email, calendar, and tasks
  • โœ… Stable - Doesn't break on UI changes
  • โœ… Cross-shell - Works from WSL2, PowerShell, etc.

Limitations

  • โš ๏ธ Outlook must be running on Windows
  • โš ๏ธ Windows-specific (COM automation)
  • โš ๏ธ MCP server requires Windows with Outlook (works from WSL2/Linux clients)

Claude Code Integration (MCP)

NEW: v2.3.0 - Now powered by MCP Python SDK v2 with FastMCP framework!

This includes a Model Context Protocol (MCP) server for Claude Code integration using the official MCP Python SDK v2 and FastMCP framework.

Key Features

  • 24 Tools for email, calendar, and task management
  • 7 Resources for quick data access (inbox, calendar, tasks)
  • Structured Output - All tools return typed Pydantic models
  • Type Safety - Full type annotations for better IDE support
  • Error Handling - Custom exception classes with detailed error messages
  • Logging - Comprehensive logging for debugging and monitoring
  • Zero-Config - Uses uv run --with pywin32 for dependency-free execution

Manual Installation

If you prefer manual installation or want to contribute:

# Clone the repository
git clone https://github.com/utsmok/mailtool.git
cd mailtool

# Install in editable mode
uv pip install -e .

Then Claude Code can:

  • ๐Ÿ“ง Read, send, reply to, forward, move, search, and manage emails
  • ๐Ÿ“… View, create, edit, respond to meetings, check free/busy, and manage appointments
  • โœ… Create, edit, complete, delete, and manage tasks

MCP Server Architecture

Version 2.3.0 uses the official MCP Python SDK v2 with FastMCP framework:

Claude Code (WSL2/Linux)
    โ†“ (JSON-RPC via stdio)
FastMCP Server (mailtool.mcp.server)
    โ†“ (async context manager)
Outlook COM Bridge (thread pool executor)
    โ†“ (COM)
Outlook Application

Key improvements from v2.2:

  • โœ… Official MCP SDK v2 (mcp>=0.9.0) with FastMCP framework
  • โœ… Structured Pydantic models for all tool outputs (EmailDetails, AppointmentDetails, TaskSummary, etc.)
  • โœ… 7 resources for quick data access (inbox://emails, calendar://today, tasks://active, etc.)
  • โœ… Custom exception classes (OutlookNotFoundError, OutlookComError, OutlookValidationError)
  • โœ… Comprehensive logging for debugging and monitoring
  • โœ… Type-safe tool definitions with @mcp.tool() decorator
  • โœ… Async lifespan management for COM bridge lifecycle

See MCP_INTEGRATION.md for full documentation.

Future Directions

This could become:

  • CLI Tool: Full-featured email/calendar CLI
  • Web App: Backend for a web interface
  • Library: Importable Python module

Troubleshooting

"Could not connect to Outlook"

  • Make sure Outlook is running
  • Check that you're logged into your account

"uv.exe not found"

  • Install uv on Windows: powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
  • Make sure uv is in your Windows PATH

UNC path warnings (harmless)

  • These appear because of WSL2 โ†’ Windows path translation
  • Safe to ignore, everything still works

MCP tools not available after plugin installation

  • This may be due to Claude Code Bug #16143
  • The MCP server is configured in .mcp.json (not inline in plugin.json) to work around this issue
  • Try restarting Claude Code after plugin installation
  • Verify the plugin installed correctly: /plugin list
  • Check MCP server status: /mcp

Development

# Add new dependencies
uv add <package>

# Run on Linux/WSL2 (for tooling)
uv run python <script>

# Run on Windows (for COM automation)
./outlook.sh <command>

# Run tests
./run_tests.sh

# Run linter and formatter
uv run ruff check .
uv run ruff format .

MCP Server Development

The MCP server is implemented in src/mailtool/mcp/ using the official MCP Python SDK v2:

  • server.py - FastMCP server with 23 tools
  • models.py - Pydantic models for structured output
  • lifespan.py - Async context manager for COM bridge lifecycle
  • resources.py - 7 resources for quick data access
  • exceptions.py - Custom exception classes

See CLAUDE.md for development patterns and architecture.

Performance Benchmarks

Performance benchmarks are available in scripts/benchmarks/ for validating MCP server performance:

# Run performance benchmarks (requires Windows with Outlook running)
uv run --with pytest --with pywin32 python -m scripts.benchmarks.performance_benchmark

Note: Benchmarks require Windows with Outlook running and pywin32 installed. They cannot run in WSL2 or CI/CD environments without Outlook access.

See scripts/benchmarks/README.md for benchmark documentation and scripts/benchmarks/EXPECTED_RESULTS.md for expected output format and success criteria.

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

mailtool-0.8.1.tar.gz (29.2 kB view details)

Uploaded Source

Built Distribution

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

mailtool-0.8.1-py3-none-any.whl (33.2 kB view details)

Uploaded Python 3

File details

Details for the file mailtool-0.8.1.tar.gz.

File metadata

  • Download URL: mailtool-0.8.1.tar.gz
  • Upload date:
  • Size: 29.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mailtool-0.8.1.tar.gz
Algorithm Hash digest
SHA256 cf2696f595a435cdcfaecace8d4ccc12549b450041fcdd7e59c8289eee6fa9a0
MD5 fec075b6a05fd874c94b9230bf1bce23
BLAKE2b-256 e75f9090ca5ddea29c91a9b39f307a58b8a51e9a68eec197936e4b00ef6a5267

See more details on using hashes here.

File details

Details for the file mailtool-0.8.1-py3-none-any.whl.

File metadata

  • Download URL: mailtool-0.8.1-py3-none-any.whl
  • Upload date:
  • Size: 33.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mailtool-0.8.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a0466ff8a1755763ac98215bdc946b5722002b8dab311a9c1401d67e7ae1751e
MD5 4c480abdcb746fb243c34076d5da4b0c
BLAKE2b-256 6d51b142033abb88957583eb57d2a8bb6c22ff9f9c4957a4fbcd9655ae0b4de8

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