Sponsored by Deepsite.site

remote-mcp-server

Created By
ivannafigueroa6 months ago
Content

remote-mcp-server

This project provides a simple Cloudflare Worker that can fetch unread emails from Gmail using the Gmail API and OAuth 2.0 refresh tokens.

The Worker expects Gmail OAuth credentials to be set as environment variables:

  • GMAIL_CLIENT_ID
  • GMAIL_CLIENT_SECRET
  • GMAIL_REFRESH_TOKEN (This token must have been authorized with the https://www.googleapis.com/auth/gmail.readonly scope or a broader scope that includes read access).

Gmail API Scope Requirements

The GMAIL_REFRESH_TOKEN provided must have been generated with at least the https://www.googleapis.com/auth/gmail.readonly scope to allow the worker to read email messages. If you are using a token with a more restrictive scope (e.g., only for sending), this worker will not be able to fetch emails.

Deploying

  1. Install the Cloudflare wrangler CLI and authenticate with your Cloudflare account.
  2. Configure the secrets in the Cloudflare dashboard or via wrangler secret put.
  3. Deploy the worker:
wrangler deploy

Usage

Send a GET request to the worker's URL to retrieve a list of unread emails.

curl https://<your-worker-url>

The worker will refresh the access token using the stored refresh token and then fetch unread emails via the Gmail API.

The response will be a JSON array of email summaries, for example:

[
  {
    "id": "18f5examplemessageid1",
    "from": "Sender Name <sender@example.com>",
    "date": "Mon, 20 May 2024 10:30:00 +0000",
    "subject": "Example Unread Email",
    "snippet": "This is a snippet of the unread email body..."
  },
  {
    "id": "18f5examplemessageid2",
    "from": "Another Sender <another@example.com>",
    "date": "Mon, 20 May 2024 11:00:00 +0000",
    "subject": "Important Update",
    "snippet": "Please review the attached document regarding the recent update."
  }
]

If there are no unread emails, an empty array [] will be returned.

Integration with a WhatsApp Agent

This Cloudflare Worker can be used as a backend for a WhatsApp agent to periodically fetch and display unread emails. Here's a high-level overview of how such an integration could work:

  1. Initiating the Request:

    • The backend of your WhatsApp agent will make an HTTPS GET request to the deployed Cloudflare Worker's URL (e.g., https://remote-mcp-server.your-username.workers.dev).
    • This request can be triggered by a user command in WhatsApp (e.g., "/checkemails") or run on a schedule.
  2. Authentication (Recommended Enhancement):

    • For added security, consider protecting your Cloudflare Worker endpoint.
    • One common method is to require a secret token (API key) in a specific header (e.g., X-Custom-Auth-Token) with the request from your WhatsApp agent's backend.
    • Your Cloudflare Worker would then need to be modified to validate this token before processing the request. (Note: This authentication mechanism is not implemented in the current version of this worker and would be an enhancement you'd add.)
  3. Receiving the Response:

    • The Cloudflare Worker will respond with a JSON array if successful.
    • Each object in the array represents an unread email and contains the following fields: id, from, date, subject, and snippet.
    • An empty array [] signifies no unread emails.
  4. Parsing and Displaying in WhatsApp:

    • Your WhatsApp agent's backend needs to parse this JSON response.
    • Iterate through each email summary object in the array.
    • For each email, format the information (e.g., "From: [sender]\nSubject: [subject]\nSnippet: [snippet]\nDate: [date]") into a user-friendly string.
    • Send these formatted strings as messages to the user in the WhatsApp chat interface. You might want to send each email summary as a separate message or combine them, depending on preference and message length limits.
  5. Error Handling by the WhatsApp Agent:

    • The WhatsApp agent's backend should be prepared to handle various error scenarios:
      • Network issues when trying to reach the Cloudflare Worker.
      • Non-200 HTTP status codes from the Cloudflare Worker (e.g., 500 if there's an issue with Gmail API access on the worker's side, 405 if the wrong HTTP method is used).
      • The worker might return an error message in the response body that could be logged or (selectively) relayed.
      • Timeouts if the worker takes too long to respond.
    • Implement appropriate logging and user feedback mechanisms in your WhatsApp agent for these situations (e.g., "Sorry, I couldn't fetch your emails right now. Please try again later.").
Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
Amap Maps高德地图官方 MCP Server
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
Tavily Mcp
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
WindsurfThe new purpose-built IDE to harness magic
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
Playwright McpPlaywright MCP server
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
ChatWiseThe second fastest AI chatbot™
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
Serper MCP ServerA Serper MCP Server
CursorThe AI Code Editor
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
DeepChatYour AI Partner on Desktop