Skip to main content
Glama

Gmail MCP Server

by nvdpsingh
direct_test.pyโ€ข5.95 kB
#!/usr/bin/env python3 """ Direct Test for Gmail MCP Server This script directly tests the Gmail functionality without MCP protocol complexity. It imports and tests the GmailMCPServer class directly. """ import asyncio import json import time from gmail_mcp_server import GmailMCPServer class DirectGmailTester: def __init__(self): self.server = GmailMCPServer() async def test_authentication(self): """Test Gmail authentication directly""" print("๐Ÿ” Testing Gmail Authentication...") try: # Call the authentication method directly result = await self.server._authenticate_gmail() if result and len(result) > 0: print("โœ… Authentication successful!") print(f"Result: {result[0].text}") return True else: print("โŒ Authentication failed - no result") return False except Exception as e: print(f"โŒ Authentication error: {e}") return False async def test_list_emails(self): """Test listing emails directly""" print("\n๐Ÿ“ง Testing List Emails...") try: result = await self.server._list_emails({"max_results": 3}) if result and len(result) > 0: print("โœ… Email listing successful!") print(f"Result: {result[0].text[:200]}...") # Show first 200 chars return True else: print("โŒ Email listing failed - no result") return False except Exception as e: print(f"โŒ Email listing error: {e}") return False async def test_send_email(self, recipient: str): """Test sending email directly""" print(f"\nโœ‰๏ธ Testing Send Email to {recipient}...") test_subject = "Gmail MCP Server Direct Test Email" test_body = f""" Hello! This is a test email sent directly from the Gmail MCP Server testing suite. Timestamp: {time.strftime('%Y-%m-%d %H:%M:%S')} Test Type: Direct Function Call Test Server: Gmail MCP Server v1.0.0 This email was sent automatically as part of the direct testing process. Best regards, Gmail MCP Server Direct Test Suite """.strip() try: result = await self.server._send_email({ "to": recipient, "subject": test_subject, "body": test_body }) if result and len(result) > 0: print("โœ… Email sent successfully!") print(f"Result: {result[0].text}") return True else: print("โŒ Email sending failed - no result") return False except Exception as e: print(f"โŒ Email sending error: {e}") return False async def test_search_emails(self): """Test searching emails directly""" print("\n๐Ÿ” Testing Search Emails...") try: result = await self.server._search_emails({ "query": "is:unread", "max_results": 3 }) if result and len(result) > 0: print("โœ… Email search successful!") print(f"Result: {result[0].text[:200]}...") # Show first 200 chars return True else: print("โŒ Email search failed - no result") return False except Exception as e: print(f"โŒ Email search error: {e}") return False async def run_all_tests(self, test_email: str): """Run all tests""" print("๐Ÿงช Gmail MCP Server Direct Test Suite") print("=" * 60) print(f"Test Email: {test_email}") print("=" * 60) results = {} # Test authentication results["authentication"] = await self.test_authentication() if not results["authentication"]: print("\nโŒ Authentication failed - skipping other tests") print("Please check your GCP OAuth credentials and Gmail API access") return results # Test other functionality results["list_emails"] = await self.test_list_emails() results["search_emails"] = await self.test_search_emails() results["send_email"] = await self.test_send_email(test_email) return results def print_results(self, results: dict): """Print test results""" print("\n" + "=" * 60) print("๐Ÿ“Š DIRECT TEST RESULTS") print("=" * 60) total_tests = len(results) passed_tests = sum(1 for result in results.values() if result) for test_name, result in results.items(): status = "โœ… PASS" if result else "โŒ FAIL" print(f"{test_name:20} {status}") print("-" * 60) print(f"Total Tests: {total_tests}") print(f"Passed: {passed_tests}") print(f"Failed: {total_tests - passed_tests}") print(f"Success Rate: {(passed_tests/total_tests)*100:.1f}%") if passed_tests == total_tests: print("\n๐ŸŽ‰ ALL DIRECT TESTS PASSED!") print("The Gmail MCP Server core functionality is working correctly!") else: print(f"\nโš ๏ธ {total_tests - passed_tests} tests failed.") print("Check the error messages above for details.") async def main(): """Main test function""" tester = DirectGmailTester() test_email = "navdeepsinghdhangar@gmail.com" results = await tester.run_all_tests(test_email) tester.print_results(results) if __name__ == "__main__": asyncio.run(main())

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/nvdpsingh/GmailMCPServer'

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