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
uvinstalled (pip install uvorcurl -LsSf https://astral.sh/uv/install.sh | sh) uv.exeaccessible 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:
- Python creates a COM object to access the running Outlook instance
- Uses O(1) direct lookups via
GetItemFromID()for performance - Returns structured data (emails, calendar events, tasks) as Python dictionaries
- 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 pywin32for 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 inplugin.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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mailtool-0.9.1.tar.gz.
File metadata
- Download URL: mailtool-0.9.1.tar.gz
- Upload date:
- Size: 32.3 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
827a1b193b8e5d6be1220edea6a1702e3659d153479c23d62029ca721aac4e14
|
|
| MD5 |
f8ca7afc86c67982865cf48b5e0aa65c
|
|
| BLAKE2b-256 |
dda0b3f52d00abb5a5122b80e0e11880b7ebf59a731e3ec7e5adb0912c8a6f5b
|
File details
Details for the file mailtool-0.9.1-py3-none-any.whl.
File metadata
- Download URL: mailtool-0.9.1-py3-none-any.whl
- Upload date:
- Size: 36.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c935bd22d261650a0de67773475175d6338566a5c00ebf26426bb209a7ce207e
|
|
| MD5 |
d15509ce137f019b4823a12a0b2d8bce
|
|
| BLAKE2b-256 |
6bf46ba5820dceb699a58a73ba904dcd2b40605cb6415035313030b66b0d7dc2
|