LingTai IMAP MCP server — real email via IMAP/SMTP.
Project description
lingtai-imap
LingTai IMAP MCP server — real email via IMAP/SMTP, exposed as MCP tools, with multi-account support and a cross-agent relay bridge.
This is the canonical setup, configuration, and troubleshooting doc for the lingtai-imap MCP. It is fetched by LingTai agents (or anyone else) when they need to install or configure this server.
MCP / LICC contract spec: see the
lingtai-anatomyskill,reference/mcp-protocol.md, for the canonical specification of the catalog → registry → activation chain, environment-variable injection, and the LICC v1 inbox callback protocol. The reference client implementation issrc/lingtai_imap/licc.pyin this repo (vendored verbatim into all first-party LingTai MCP repos — copy it if you're writing your own).
Tools
One omnibus MCP tool: imap(action=...). Actions: send, check, read, reply, search, delete, move, flag, folders, contacts, add_contact, remove_contact, edit_contact, accounts. Email IDs are compound keys: account:folder:uid.
Inbound mail (LICC)
Inbound IMAP messages flow into the host agent's inbox via the LingTai Inbox Callback Contract. The server reads two env vars that the LingTai kernel injects automatically when spawning the MCP:
LINGTAI_AGENT_DIR— host agent's working directory.LINGTAI_MCP_NAME— this MCP's registry name (typicallyimap).
Each new email is delivered as a LICC event with:
from,subject— straight from the email headers.body— a ~300 char preview (useimap(action="read", email_id=...)to fetch the full message).metadata.email_id— compound key for downstream tool calls.metadata.account— which configured account received it.
The server-side stub listener has been removed; real IMAP IDLE polling runs on every account.
Cross-agent relay bridge
Other agents on the same host can route outbound mail through this server by writing message files into <agent_working_dir>/imap_bridge/inbox/<sender>/<msg-id>/message.json. The bridge picks them up and sends via this MCP's IMAP/SMTP. Useful for networks where only one agent owns the email account.
Install
# Into the LingTai agent's venv (typically ~/.lingtai-tui/runtime/venv/)
pip install git+https://github.com/Lingtai-AI/lingtai-imap.git
After install, python -m lingtai_imap (or the lingtai-imap script) starts the MCP server over stdio.
Configure
The server reads its IMAP/SMTP credentials from a JSON file pointed at by the LINGTAI_IMAP_CONFIG environment variable. Recommended path: .secrets/imap.json inside the agent's working directory. Plaintext only — this MCP does not support *_env indirection.
Config schema
{
"accounts": [
{
"email_address": "agent@example.com",
"email_password": "16-char-app-password",
"imap_host": "imap.gmail.com",
"imap_port": 993,
"smtp_host": "smtp.gmail.com",
"smtp_port": 587,
"allowed_senders": ["someone@example.com"],
"poll_interval": 30
}
]
}
accountsis an array — append more entries to add accounts.email_passwordshould be an app password (not your account password). For Gmail: enable 2FA, then create one at myaccount.google.com/apppasswords. For Outlook: account.microsoft.com/security → App passwords.imap_host/imap_portdefault toimap.gmail.com/993. Override for non-Gmail providers.smtp_host/smtp_portdefault tosmtp.gmail.com/587.allowed_senders— optional allow-list. When set, IMAP messages from other senders are silently ignored by the listener.poll_interval— seconds between IDLE reconciliation slices (default 30).
Activation in LingTai
Inside init.json, add imap to your addons: list (which auto-registers via the kernel catalog) and add an entry under mcp: to activate:
{
"addons": ["imap"],
"mcp": {
"imap": {
"type": "stdio",
"command": "/path/to/your/python",
"args": ["-m", "lingtai_imap"],
"env": {
"LINGTAI_IMAP_CONFIG": ".secrets/imap.json"
}
}
}
}
Then run system(action="refresh") from the agent. The MCP subprocess starts, the IMAP IDLE listener begins polling, the bridge directory is created, and the omnibus imap tool becomes available.
Troubleshooting
LINGTAI_IMAP_CONFIG env var not set— yourinit.jsonmcp.imap.enventry is missing theLINGTAI_IMAP_CONFIGkey.IMAP config not found— the path resolves but no file exists. Relative paths are resolved againstLINGTAI_AGENT_DIR.Login failed/AUTHENTICATIONFAILED— usually a wrong password or a regular password instead of an app password. Re-create the app password.gaierror: nodename nor servname provided—imap_hostis wrong or DNS resolution failed.SSL: CERTIFICATE_VERIFY_FAILED— corporate certificate stores. Workaround under discussion; for now, run from a venv with up-to-datecertifi.MCP server failed to start— usually thecommandpath ininit.jsondoesn't havelingtai_imapinstalled. Confirm with<command> -m lingtai_imap --helpfrom a shell.- Tool calls return
IMAP manager not initialized— server boot failed. Check stderr for the underlying exception and fix the config / env, thensystem(action="refresh"). - Listener says
tool_connected: false, listening: false— callimap(action="accounts")to see per-account status. The listener auto-reconnects with backoff; transient failures recover on their own.
License
MIT.
Project details
Release history Release notifications | RSS feed
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 lingtai_imap-0.1.0.tar.gz.
File metadata
- Download URL: lingtai_imap-0.1.0.tar.gz
- Upload date:
- Size: 23.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0f3e6294a555877d1f1a4c31cfd2d918aca7a03a679e06fc11513d0f5264c7cc
|
|
| MD5 |
3a916e4763db4ccac05b87786ea7922d
|
|
| BLAKE2b-256 |
9072d9a891ceb903ac9f8b2cfa3256a1ae1d0cf85e557d0facfb23f949c29b4d
|
File details
Details for the file lingtai_imap-0.1.0-py3-none-any.whl.
File metadata
- Download URL: lingtai_imap-0.1.0-py3-none-any.whl
- Upload date:
- Size: 28.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
41813a0d2ae8c52a471cdb6129af51fe4643c02223e9c6c2be3869f2103781cf
|
|
| MD5 |
c3c1248bf25b9b6e63de5787ad63d712
|
|
| BLAKE2b-256 |
5039d4399bf910f7c4af247d0a1d5b778639a21516857035feaaa7bfaa0a4fd1
|