Gmail + SAP MCP Server
Provides MCP tools for searching, reading, and drafting Gmail emails, as well as querying SAP OData endpoints with safe read operations and mock mode.
README
Gmail + SAP MCP Integration
A complete starter project that exposes Gmail and SAP OData operations as Model Context Protocol (MCP) tools.
What this project can do
Gmail tools
- Authenticate with Google OAuth 2.0
- Search emails using normal Gmail search syntax
- Read an email
- List recent inbox emails
- Create an email draft
- Send an email, disabled by default for safety
SAP tools
- Test the SAP connection
- Read an OData entity set
- Read a single OData entity
- Create an OData record, disabled by default
- Update an OData record, disabled by default
- Execute a safe raw GET request
- Run without a real SAP system using built-in mock data
MCP
- Runs as a standard
stdioMCP server - Can be connected to MCP-compatible clients
- Uses explicit environment flags for write operations
- Returns JSON-friendly tool results
Project structure
gmail_sap_mcp_project/
├── app/
│ ├── config.py
│ ├── server.py
│ ├── gmail_client.py
│ ├── sap_client.py
│ ├── models.py
│ └── utils.py
├── scripts/
│ ├── gmail_auth.py
│ └── test_connections.py
├── tests/
│ ├── test_sap_client.py
│ └── test_utils.py
├── credentials/
│ └── .gitkeep
├── .env.example
├── .gitignore
├── mcp-config.example.json
├── pyproject.toml
├── requirements.txt
├── run_server.py
└── README.md
1. Prerequisites
Install:
- Python 3.11 or 3.12
- A Google Cloud project
- Gmail API enabled in Google Cloud
- OAuth Desktop App credentials
- Optional: SAP S/4HANA, SAP Gateway, SAP Business One service layer, or another SAP OData endpoint
This project does not require a Google service-account key. Gmail user data is accessed using OAuth user consent.
2. Setup on Windows PowerShell
Open PowerShell in the project folder.
py -3.11 -m venv .venv
.venv\Scripts\Activate.ps1
python -m pip install --upgrade pip
pip install -r requirements.txt
Copy-Item .env.example .env
If PowerShell blocks activation:
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
.venv\Scripts\Activate.ps1
3. Configure Gmail
Google Cloud steps
- Create or select a Google Cloud project.
- Open APIs & Services → Library.
- Enable Gmail API.
- Open Google Auth Platform.
- Configure the consent screen.
- Add your Gmail address as a test user while the app is in testing.
- Open Clients → Create Client.
- Select Desktop app.
- Download the JSON file.
- Rename it to
credentials.json. - Put it here:
credentials/credentials.json
Generate the Gmail token
python scripts/gmail_auth.py
A browser window will ask you to approve Gmail access. The generated token is stored at:
credentials/token.json
The default scopes allow reading Gmail, creating drafts, and sending mail. To use read-only access, change GMAIL_SCOPES in .env, delete credentials/token.json, and authenticate again.
4. Configure SAP
Copy .env.example to .env.
Option A: Start in mock mode
Keep:
SAP_MOCK_MODE=true
No real SAP credentials are needed. This is the best way to learn and test the MCP integration.
Option B: Use a real SAP OData service
Example configuration:
SAP_MOCK_MODE=false
SAP_BASE_URL=https://your-sap-host.example.com
SAP_ODATA_PATH=/sap/opu/odata/sap/API_BUSINESS_PARTNER
SAP_AUTH_TYPE=basic
SAP_USERNAME=your_username
SAP_PASSWORD=your_password
SAP_VERIFY_SSL=true
For bearer-token authentication:
SAP_AUTH_TYPE=bearer
SAP_BEARER_TOKEN=your_access_token
SAP_ODATA_PATH should point to the service root, not an individual entity set.
Examples:
/sap/opu/odata/sap/API_BUSINESS_PARTNER
/sap/opu/odata/sap/API_SALES_ORDER_SRV
Entity-set names vary by SAP service, such as:
A_BusinessPartner
A_SalesOrder
A_Product
5. Test connections
python scripts/test_connections.py
This checks configuration, Gmail authentication, and SAP connectivity.
6. Run the MCP server
python run_server.py
Because this is a stdio MCP server, it waits for an MCP client and normally does not show a web page.
Important: do not add print() statements to the MCP server's standard output. Logging goes to standard error.
7. Connect it to an MCP client
Use the absolute path to your Python executable and project folder.
Example MCP configuration:
{
"mcpServers": {
"gmail-sap": {
"command": "C:\\absolute\\path\\gmail_sap_mcp_project\\.venv\\Scripts\\python.exe",
"args": [
"C:\\absolute\\path\\gmail_sap_mcp_project\\run_server.py"
],
"cwd": "C:\\absolute\\path\\gmail_sap_mcp_project",
"env": {
"ENV_FILE": "C:\\absolute\\path\\gmail_sap_mcp_project\\.env"
}
}
}
}
A ready template is included as mcp-config.example.json.
Restart your MCP client after changing its configuration.
8. Available MCP tools
Gmail
| Tool | Purpose |
|---|---|
gmail_status |
Check whether Gmail credentials and token are available |
gmail_list_recent |
List recent inbox messages |
gmail_search |
Search Gmail using Gmail query syntax |
gmail_read_message |
Read one message by ID |
gmail_create_draft |
Create a Gmail draft |
gmail_send_email |
Send an email when enabled |
Examples of Gmail search queries:
from:manager@example.com newer_than:7d
subject:invoice has:attachment
is:unread in:inbox
SAP
| Tool | Purpose |
|---|---|
sap_status |
Show safe SAP configuration status |
sap_test_connection |
Test the service connection |
sap_list_entities |
Read an OData entity set |
sap_get_entity |
Read one entity by OData key |
sap_safe_get |
Perform a restricted GET request |
sap_create_entity |
Create a record when enabled |
sap_update_entity |
Update a record when enabled |
9. Safety settings
Write operations are disabled by default:
ALLOW_GMAIL_SEND=false
ALLOW_SAP_WRITE=false
To enable them:
ALLOW_GMAIL_SEND=true
ALLOW_SAP_WRITE=true
Restart the MCP server after changing .env.
For production:
- Use a secrets manager rather than committing secrets.
- Use least-privilege Google scopes.
- Use a dedicated SAP communication user.
- Restrict SAP authorizations to required business objects.
- Keep TLS verification enabled.
- Add approval steps before sending email or changing SAP data.
- Log tool invocation metadata, but never log tokens or passwords.
10. Example real-life workflow
A manager asks:
Find unread supplier emails received this week, extract the supplier numbers, and check those suppliers in SAP.
The AI client can:
- Call
gmail_searchwithis:unread newer_than:7d supplier. - Read selected messages using
gmail_read_message. - Extract supplier IDs.
- Query the relevant SAP entity set using
sap_list_entities. - Present a combined summary.
A write workflow could draft a reply with gmail_create_draft. Sending remains blocked unless explicitly enabled.
11. Run tests
pytest -q
12. Common errors
credentials.json was not found
Put the downloaded Desktop OAuth JSON file at:
credentials/credentials.json
Google says the app is not verified
For development, keep the app in testing and add your Gmail account as a test user.
invalid_grant
Delete credentials/token.json and run:
python scripts/gmail_auth.py
SAP returns 401 or 403
Check the authentication method, username, password/token, communication arrangement, and SAP authorizations.
SAP returns 404
Confirm SAP_BASE_URL, SAP_ODATA_PATH, and entity-set spelling. Open the service $metadata endpoint in a browser or API client.
SSL certificate error
Prefer installing the proper corporate CA certificate. Only for local testing, set:
SAP_VERIFY_SSL=false
Do not disable TLS verification in production.
Notes
MCP connects the AI client to tools. It does not automatically decide your SAP business rules, approve transactions, or bypass Google/SAP permissions.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.