MCP Email Orchestrator
An intelligent email orchestration system that connects local LLMs to an SMTP email sender using the Model Context Protocol, enabling dynamic tool discovery and execution via natural language.
README
MCP Email Orchestrator
An intelligent email orchestration system built using the Model Context Protocol (MCP), FastAPI, and Ollama. This project demonstrates how to seamlessly connect local Large Language Models (LLMs) to external tools—specifically, an SMTP email sender—using a standardized client-server architecture.
Table of Contents
- What is the Model Context Protocol (MCP)?
- Project Architecture
- LLM Integration
- What This Project Achieves
- Repository Structure
- Installation & Setup
- Usage
What is the Model Context Protocol (MCP)?
The Model Context Protocol (MCP) is an open standard introduced by Anthropic in November 2024. It provides a universal, standardized way for AI applications (like LLMs) to connect with external systems, data sources, and tools. Before MCP, developers had to write custom integrations for every new data source or tool they wanted their AI to use. MCP solves this by establishing a consistent, two-way communication protocol based on JSON-RPC 2.0.
MCP Client vs. MCP Server
MCP follows a strict client-server architecture:
- MCP Host / Client: The AI application or agent (in this project, the FastAPI orchestrator running the Ollama model). The client maintains a connection to the server, requests context, and asks the server to execute specific tools based on the LLM's reasoning.
- MCP Server: A lightweight program that exposes specific capabilities (Tools, Resources, or Prompts) to the client. In this project, the
email_mcp_server.pyacts as the MCP Server, exposing asend_emailtool that handles the actual SMTP communication.
By separating the AI logic (Client) from the execution logic (Server), MCP ensures secure, modular, and scalable AI tool use.
Project Architecture
This project implements a complete MCP lifecycle using a local LLM:
- FastAPI Orchestrator (The Host):
main.pyserves as the entry point. It manages the lifecycle of the MCP Server, spawning it as a subprocess via standard input/output (stdio) transport. - Dynamic Tool Discovery: Upon startup, the FastAPI app connects to the MCP Server, dynamically fetches the available tools (e.g.,
send_email), and translates the MCP tool schemas into a format that the Ollama LLM understands. - The LLM (Ollama): When a user sends a prompt via the
/chatendpoint, the orchestrator passes the prompt and the available tools to the local LLM. - Tool Execution: If the LLM determines that an email needs to be sent, it returns a tool call request. The orchestrator routes this request back to the MCP Server.
- MCP Server (The Executor):
email_mcp_server.pyreceives the execution request, securely accesses the SMTP credentials from the environment, and sends the email.
LLM Integration
This project utilizes Ollama to run local, open-source models.
- Default Model:
qwen2.5:1.5b - Function Calling: The project leverages the native function-calling capabilities of modern LLMs. The system prompt explicitly instructs the model: "You are a helpful assistant. If the user wants to send an email, use the send_email tool."
- Bulletproof Extraction: The orchestrator includes robust parsing logic to handle the LLM's responses, ensuring that tool calls are accurately extracted whether the model returns them as dictionaries or Pydantic objects.
What This Project Achieves
- Standardized AI Tooling: Demonstrates a working implementation of the newly released Model Context Protocol, moving away from hardcoded tool logic to dynamic discovery.
- Local AI Privacy: By using Ollama, the reasoning engine runs entirely locally, ensuring that user prompts are not sent to third-party APIs.
- Secure Credential Management: The MCP Server handles the sensitive SMTP credentials (
.env), keeping them isolated from the LLM and the main orchestrator logic. - Extensibility: Because it uses MCP, adding new capabilities (like reading files, querying a database, or searching the web) is as simple as adding a new tool to the MCP Server—no changes to the core LLM routing logic are required.
Repository Structure
MCP_Email/
├── main.py # FastAPI app, MCP Client, and Ollama orchestrator
├── email_mcp_server.py # FastMCP Server exposing the send_email tool
├── requirements.txt # Python dependencies
├── .env # (Not tracked) SMTP credentials
└── tools/
├── email_tool.py # Core SMTP execution logic
└── mcp_registry.py # Tool schemas and registry
Installation & Setup
Prerequisites
- Python 3.10+
- Ollama installed and running locally.
- The
qwen2.5:1.5bmodel pulled in Ollama (ollama run qwen2.5:1.5b).
1. Clone the Repository
git clone https://github.com/SOUGUR/MCP_Email.git
cd MCP_Email
2. Install Dependencies
pip install -r requirements.txt
3. Configure Environment Variables
Create a .env file in the root directory and add your SMTP credentials:
SENDER_EMAIL=your_email@gmail.com
SENDER_PASSWORD=your_app_password
SMTP_SERVER=smtp.gmail.com
SMTP_PORT=587
Usage
-
Start the Orchestrator:
python main.pyNote: The FastAPI app will automatically spawn and connect to the MCP Server on startup.
-
Send a Request: You can interact with the system by sending a POST request to the
/chatendpoint.curl -X POST "http://localhost:8000/chat" \ -H "Content-Type: application/json" \ -d '{"prompt": "Please send an email to test@example.com with the subject Hello and body This is a test from MCP."}' -
Expected Output: The LLM will process the natural language request, trigger the
send_emailtool via the MCP Server, and return the execution results.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。