Skip to main content
Glama

IMAP MCP Server

by non-dirty
TASKS_COMPLETED.md13.5 kB
# Completed Implementation Tasks ## 1. Expand Core IMAP Client Tests **Task Name**: Implement comprehensive IMAP client tests **Test Specifications**: - Test connection/disconnection behavior - Test folder listing functionality - Test message retrieval with various filters - Test message action functions (mark read, move, delete) - Test error handling and edge cases **Implementation Steps**: ``` 1. Create test_imap_client.py with test cases covering: - Connection establishment/teardown - Authentication methods - Folder operations - Message retrieval operations - Message modification operations - Error scenarios and recovery 2. Use mocking to simulate IMAP server responses 3. Include tests for both successful and error conditions ``` **TDD Process**: 1. Run `pytest tests/test_imap_client.py -v` to see all tests fail 2. Fix or implement the functionality in imap_client.py 3. Run tests again until all pass 4. Run `pytest --cov=imap_mcp.imap_client` to verify coverage **Accomplishments**: 1. Created comprehensive test suite for the IMAP client with 25 test cases covering: - Client initialization and configuration - Connection and authentication - Folder listing and selection - Email search functionality - Email fetching (single and multiple) - Email operations (marking, moving, deleting) - Error handling for all operations 2. Achieved 98% test coverage for the IMAP client module 3. Used mock objects to simulate IMAP server responses, allowing tests to run without a real IMAP server 4. Implemented tests for both successful cases and error scenarios to ensure the client is robust 5. Updated project configuration to use Python 3.10+ and configured the environment using `uv` tool 6. Added documentation for using `uv` to manage the project's Python environment ## 2. Implement Config Module Tests **Task Name**: Test and enhance configuration handling **Test Specifications**: - Test loading configurations from files - Test environment variable integration - Test validation of configuration values - Test default values and fallbacks - Test error handling for invalid configurations **Implementation Steps**: ``` 1. Create test_config.py with test cases covering: - Config file loading - Environment variable integration - Configuration validation - Default values - Error handling for invalid configurations 2. Use temporary files and environment variables in tests ``` **TDD Process**: 1. Run `pytest tests/test_config.py -v` to see all tests fail 2. Fix or enhance the config.py module to handle all test cases 3. Run tests again until all pass 4. Run `pytest --cov=imap_mcp.config` to verify coverage **Accomplishments**: 1. Created comprehensive test suite for the configuration module with 12 test cases covering: - ImapConfig class initialization and validation - ServerConfig class initialization and validation - Loading configuration from YAML files - Loading configuration from environment variables - Error handling for invalid configurations - Default value handling and fallbacks 2. Achieved 100% test coverage for the config module 3. Enhanced the config.py module to handle file not found errors gracefully 4. Added proper environment variable integration tests 5. Implemented thorough validation testing for all configuration components ## 0. Enhance Test Infrastructure **Task Name**: Set up comprehensive test infrastructure **Test Specifications**: - Test fixtures for mocking IMAP connections - Utilities for creating test email data - Configuration for running both unit and integration tests - Test coverage reporting configuration **Implementation Steps**: ``` 1. First analyze the current test setup in tests/test_models.py 2. Create a tests/conftest.py file with: - IMAP mock fixtures - Test email data generators - Configuration fixtures 3. Implement a test_utils.py module with helper functions 4. Configure pytest.ini for proper test organization 5. Set up coverage reporting configuration ``` **TDD Process**: 1. Create empty test files with expected test functions (they should fail) 2. Implement the test infrastructure code until tests pass 3. Run `pytest --cov=imap_mcp tests/test_infrastructure.py` to verify **Accomplishments**: 1. Created a comprehensive set of test fixtures in conftest.py including: - Mock IMAP client fixtures - Email message fixtures (simple, multipart, with attachments, encoded headers) - Email model fixtures - Environment configuration fixtures 2. Implemented test utility functions in test_utils.py including: - Random data generation for testing - Email message creation helpers - Email comparison utilities - Mock IMAP folder list creation 3. Created test_infrastructure.py to validate the infrastructure itself, ensuring all fixtures and utilities work as expected 4. Fixed bugs in the EmailAddress.parse method to correctly handle edge cases and make existing tests pass 5. Added a pytest.ini file for proper test organization and configuration ## 3. Implement MCP Resources Tests **Task Name**: Test and enhance MCP resources **Test Specifications**: - Test email resource representation - Test folder resource representation - Test resource serialization/deserialization - Test resource validation - Test resource error handling **Implementation Steps**: ``` 1. Create test_resources.py with test cases covering: - Resource initialization - Resource serialization/deserialization - Resource validation - Resource error handling 2. Mock necessary dependencies ``` **TDD Process**: 1. Run `pytest tests/test_resources.py -v` to see all tests fail 2. Implement or fix resource functionality in resources.py 3. Run tests again until all pass 4. Run `pytest --cov=imap_mcp.resources` to verify coverage **Accomplishments**: 1. Created a comprehensive test suite for MCP resources in test_resources.py with 7 test cases covering: - Client retrieval from context - Resource registration with the MCP server - Email folders listing functionality - Email listing within folders - Email search functionality across folders - Individual email retrieval by UID - Error handling for all resource operations 2. Implemented proper test fixtures for mocking the MCP server and IMAP client 3. Fixed import issues in the resources.py file to correctly import the Context class from mcp.server.fastmcp 4. Achieved 91% test coverage for the resources module 5. Used asyncio test fixtures to properly test asynchronous resource handlers 6. Implemented comprehensive error handling tests to ensure robustness 6. Created a CLAUDE.md file with build/test commands and code style guidelines for the project ## 4. Implement MCP Tools Tests **Task Name**: Test and enhance MCP tools **Test Specifications**: 1. Created tests for email browsing tools in test_tools.py: - Tests for move_email functionality - Tests for mark_as_read/unread functionality - Tests for flag/unflag email functionality - Tests for email deletion 2. Created tests for email action tools: - Tests for process_email with different actions (move, read, unread, flag, delete) - Tests for action validation and error handling 3. Created tests for search tools: - Tests for search_emails with different criteria - Tests for folder-specific and multi-folder searches - Tests for search result limits and formatting 4. Created tests for parameter validation in all tools: - Tests with valid parameters - Tests with invalid or missing parameters - Tests with edge case values 5. Created tests for error handling in tools: - Tests for network errors - Tests for invalid email/folder combinations - Tests for server errors **Fixes and Improvements**: 1. Fixed parameter order issues in tools.py for multiple functions: - Moved context parameter before optional parameters in flag_email, search_emails, and process_email - Ensured proper function signatures throughout the tools module 2. Fixed import errors in both tools.py and test_tools.py: - Updated Context import to use mcp.server.fastmcp instead of mcp.server.types 3. Created comprehensive test mocks and fixtures: - Created mock IMAP client with controlled responses - Created mock MCP server with mock tool registration - Created mock Email and EmailAddress objects for testing 4. Achieved 100% test passing rate with 9 comprehensive test cases covering all major tool functionalities 5. Used Test-Driven Development approach to identify and fix issues in the tools module 7. Added a comprehensive .gitignore file to exclude temporary and generated files This test infrastructure provides a solid foundation for implementing the remaining tasks in the project using a test-driven development approach. ## 20. Set up Google Cloud Project for OAuth2 **Task Name**: Set up Google Cloud Project for Gmail OAuth2 **Test Specifications**: - Create a structured configuration file for OAuth2 credentials - Validate that config file correctly loads client ID and secret - Ensure environment variables can override config file values **Implementation Steps**: 1. ✅ Create a Google Cloud Project via the [Google Cloud Console](https://console.cloud.google.com/) 2. ✅ Enable the Gmail API for your project 3. ✅ Configure the OAuth consent screen: - ✅ Select "External" user type - ✅ Add required app information (name, support email) - ✅ Add scope: "https://mail.google.com/" 4. ✅ Create OAuth Client ID credentials (type: Desktop application) 5. ✅ Download the credentials JSON (client_secret_*.json) and add to .gitignore 6. ✅ Add the client ID and secret to your application config 7. ✅ Create tests to validate config loading **TDD Process**: 1. ✅ Create tests for OAuth2 config validation 2. ✅ Implement credential loading function 3. ✅ Run tests to verify functionality **Accomplishments**: 1. Created a complete OAuth2 implementation for Gmail authentication in the IMAP MCP server, including: - Configuration module (`oauth2_config.py`) to handle loading and validating OAuth2 settings - Authentication setup tool (`auth_setup.py`) to facilitate the OAuth2 flow - Browser-based authentication component (`browser_auth.py`) for handling user authorization 2. Set up a Google Cloud Project with the Gmail API enabled and configured OAuth2 credentials: - Created OAuth consent screen with appropriate scopes - Generated client ID and secret for desktop application - Securely stored credentials in the project 3. Updated the configuration system to support OAuth2: - Enhanced `config.yaml` to include OAuth2 settings (client ID, client secret, tokens) - Added support for environment variables (GMAIL_CLIENT_ID, GMAIL_CLIENT_SECRET, GMAIL_REFRESH_TOKEN) - Implemented token refresh mechanism to handle expired access tokens 4. Created test script `test_oauth2_gmail.py` to verify the OAuth2 implementation: - Successfully connects to Gmail using OAuth2 - Lists mailboxes to confirm authentication works - Properly manages token lifecycle 5. Updated the IMAP client to seamlessly work with both traditional password authentication and OAuth2 based on the email provider ## 5. Implement Server Tests **Task Name**: Implement comprehensive server module tests **Test Specifications**: - Test server initialization and configuration - Test lifecycle management (startup and shutdown) - Test CLI argument parsing - Test error handling **Implementation Steps**: ``` 1. Created test_server.py with test cases covering: - Server initialization and configuration loading - Lifecycle management (lifespan context manager) - CLI argument parsing with different options - Error handling for invalid configurations - Tool registration and functionality ``` **Accomplishments**: 1. Implemented a comprehensive test suite for the server module using pytest and mock objects: - Created tests for `create_server` function with various configuration options - Implemented async tests for the `server_lifespan` context manager - Added tests for config fallback and error handling - Created tests for command-line argument parsing 2. Achieved 89% code coverage for the server module: - All major code paths covered - Remaining uncovered paths are primarily formatting code and edge cases 3. Addressed testing challenges: - Used mock objects to simulate IMAP client connections - Implemented proper async testing with AsyncExitStack - Developed approaches to test inner function tools without direct access 4. Improved project structure: - Ensured tests follow the same structure as the implementation - Used pytest fixtures effectively - Added proper docstrings to all test functions **Code Coverage**: - Improved overall project coverage from 53% to 58% - Server module coverage achieved 89% - Remaining untested code includes only some formatting code and specific edge cases **TDD Process**: 1. Started with failing tests that verified the expected server behavior 2. Adjusted test approaches to account for FastMCP implementation details 3. Implemented tests for error handling and edge cases 4. Achieved near-complete coverage of the server module This task completes the foundational testing of the IMAP MCP server's core components, providing a solid base for implementing additional features.

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/non-dirty/imap-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server