# Connect n8n or your own code over MCP

In n8n, add an **MCP Client** node, choose HTTP Streamable transport and the URL `https://mcp.xgenplus.com/mcp`, and use header auth with name `Authorization` and value `Bearer <TOKEN>`. In your own code, connect with any MCP SDK's Streamable HTTP client and send the same header. Give automations narrow permissions, because nobody watches each step.

## How to connect n8n or your own code over MCP

1. Create an agent password with only the permissions the automation needs, and [make your token](/developers/mcp-make-a-token/).
2. In n8n: add an **MCP Client** node, set the transport to HTTP Streamable and the URL to `https://mcp.xgenplus.com/mcp`.
3. Set authentication to header auth, with name `Authorization` and value `Bearer <TOKEN>`, saved as an n8n credential.
4. In your own code: connect with the MCP SDK's Streamable HTTP client and the same header.

## When to use it

> Rohit builds an n8n workflow that runs every evening, lists the day's unread supplier mail and posts a summary to his team. Its agent password has only List folders, Search email and Read email.

## Python example

```python
import asyncio, os
from mcp import ClientSession
from mcp.client.streamable_http import streamablehttp_client

async def main():
    headers = {"Authorization": "Bearer " + os.environ["XGENPLUS_TOKEN"]}
    async with streamablehttp_client("https://mcp.xgenplus.com/mcp", headers=headers) as (read, write, _):
        async with ClientSession(read, write) as session:
            await session.initialize()
            result = await session.call_tool("get_inbox_summary", {})
            print(result.content)

asyncio.run(main())
```

## Good to know

- **Mail content is untrusted.** Automations act without a person watching. Never let mail content decide where mail is sent.
- Keep the token in your automation tool's credential store or an environment variable, never in code.
- Respect the [limits](/developers/mcp-troubleshooting/). A `RATE_LIMITED` error says when to retry.
- Pass the same `idempotency_key` when you retry a send, so it is not sent twice.

## Common questions

**Can an automation send mail on its own?**

Only if you turn on Send email for its agent password. Risky sends, such as to a first-time external recipient, are still held as drafts for review.


Source: https://docs.xgenplus.com/developers/mcp-automation/
