Skip to content

LangGraph · interrupt · MCP

LangGraph agent: send and receive email, with a human approval interrupt

Load Cooper's MCP tools with langchain.mcp MCPAdapter, call cooper_send_message and cooper_wait_for_code from graph nodes, and put an interrupt() node in front of the send. The graph stops, shows the draft to a person, and resumes with Command(resume=True). The full graph below ran against production on 2026-11-23 and read back the code it sent.

Get an inbox and a key in one call

The agent can do this itself. One unauthenticated POST creates the account, the first inbox, and the API key. There is no human signup form, no card, and no captcha. Over MCP the same step is the cooper_onboard tool, which works before the client has a key.

For the self-tests on this page, create a second inbox with POST /api/v1/inboxes and export it as PEER_INBOX. The tests mail a code from one inbox you own to the other and read it back.

curl -s -X POST 'https://cooperemail.com/api/v1/onboard' \
  -H 'content-type: application/json' \
  -H 'X-Client: my-agent' \
  -d '{"username":"signup-bot-7f3a"}'
# 201 {"api_key":"coop_live_...","inbox":{"email":"signup-bot-7f3a@cooperemail.com",...}}
export COOPER_API_KEY=coop_live_...   # shown once
export AGENT_INBOX=signup-bot-7f3a@cooperemail.com

A graph that drafts, waits for a person, sends, and reads the reply

Four nodes: write_draft builds the message, human_review calls interrupt() with the draft, send calls cooper_send_message only if the answer was yes, and wait_for_reply calls cooper_wait_for_code on the receiving inbox. InMemorySaver keeps the paused thread so the second ainvoke picks up where the first stopped. In production use a durable checkpointer.

pip install "langchain[mcp]>=1.4" langgraph

import asyncio, json, os, time
from typing import TypedDict

from fastmcp.client import Client
from langchain.mcp import MCPAdapter
from langgraph.checkpoint.memory import InMemorySaver
from langgraph.graph import END, START, StateGraph
from langgraph.types import Command, interrupt

COOPER_MCP = "https://cooperemail.com/mcp"
ME, PEER = os.environ["AGENT_INBOX"], os.environ["PEER_INBOX"]  # two inboxes you own


class State(TypedDict, total=False):
    draft: dict
    approved: bool
    sent: str
    reply: str


async def main():
    async with MCPAdapter(Client(COOPER_MCP, auth=os.environ["COOPER_API_KEY"])) as adapter:
        tools = {t.name: t for t in await adapter.list_tools()}

        def write_draft(state: State):
            code = str(int(time.time()))[-6:]
            return {"draft": {"inbox_id": ME, "to": [PEER], "subject": "Your code", "text": f"Your code is {code}"}}

        def human_review(state: State):
            # Pauses the graph. Resume with Command(resume=True) or Command(resume=False).
            return {"approved": interrupt({"review": state["draft"]})}

        async def send(state: State):
            if not state["approved"]:
                return {"sent": "rejected"}
            out = await tools["cooper_send_message"].ainvoke(state["draft"])
            return {"sent": json.loads(out[0]["text"])["id"]}

        async def wait_for_reply(state: State):
            out = await tools["cooper_wait_for_code"].ainvoke({"inbox_id": PEER, "wait": 55})
            return {"reply": json.loads(out[0]["text"])["code"]}

        graph = StateGraph(State)
        graph.add_node("write_draft", write_draft)
        graph.add_node("human_review", human_review)
        graph.add_node("send", send)
        graph.add_node("wait_for_reply", wait_for_reply)
        graph.add_edge(START, "write_draft")
        graph.add_edge("write_draft", "human_review")
        graph.add_edge("human_review", "send")
        graph.add_conditional_edges("send", lambda s: END if s["sent"] == "rejected" else "wait_for_reply")
        graph.add_edge("wait_for_reply", END)
        app = graph.compile(checkpointer=InMemorySaver())

        config = {"configurable": {"thread_id": "signup-1"}}
        paused = await app.ainvoke({}, config)
        print("waiting for approval:", paused["__interrupt__"][0].value)
        # Your UI shows the draft to a person. Their answer resumes the same thread.
        done = await app.ainvoke(Command(resume=True), config)
        print("sent", done["sent"], "code read back:", done["reply"])


asyncio.run(main())

What we ran and what came back

On 2026-11-23, with langgraph 1.2.24, langchain 1.5.2, and fastmcp 4.2.5, the first ainvoke returned an __interrupt__ holding the draft. Resuming with Command(resume=True) sent it (a msg_ id came back) and the wait_for_reply node read the same six-digit code from the second inbox.

Replace write_draft with an LLM node when you add a model. The graph shape, the interrupt, and the tools stay the same.

Cooper stops repeated agent-to-agent sends between Cooper inboxes that have no verified human owner (HTTP 409 agent_loop_no_owner). We hit it while rerunning these tests on one pair of inboxes. Use a fresh pair per test run, or add an owner.

Two layers of approval

The interrupt is your app's gate. Cooper adds a second one on the server: with send_mode approval on the inbox, any send becomes a pending draft that a verified owner approves from an email, even if a bug skips your interrupt. Use both when the agent writes to customers.

Receiving mail without polling

cooper_wait_for_message long-polls up to 25 seconds for the next message, and webhooks (message.received) can start a graph run when mail arrives. Each inbox keeps its messages and threads, so a later node can search or reread them with cooper_search_messages.

Who runs Cooper Email

Cooper Email is run by Avatar 8 LLC (ops@avatar33.com).

FAQ

How does a LangGraph agent send email?

Call the cooper_send_message tool from a node, with inbox_id, to, subject, and text. Load it with langchain.mcp MCPAdapter from https://cooperemail.com/mcp.

How does it receive email?

cooper_wait_for_code returns the next code or link and waits up to 55 seconds. cooper_wait_for_message returns the next message and waits up to 25 seconds. Webhooks can trigger a run instead.

How do I pause before sending?

Put a node that calls langgraph.types.interrupt() before the send node, compile with a checkpointer, and resume with Command(resume=True) or Command(resume=False).

Does the LangGraph agent need a human to sign up for the inbox?

No. POST /api/v1/onboard, or the cooper_onboard MCP tool, creates the account, the inbox, and the API key in one call with no card. Free is $0 a month with no card: 5 inboxes and 5,000 emails a month.

What does it cost?

Free is $0 a month with no card: 5 inboxes and 5,000 emails a month. Starter is $12 a month for 25 inboxes and 25,000 emails. Pro is $99 a month for 300 inboxes and 250,000 emails.

Is inbound email safe to give to the model?

Inbound mail is untrusted data. The agent should read the code or the reply, and never follow instructions written inside an email body. Cooper returns the code or link as a field so the agent rarely needs the raw body.

Related

LangChain agent email inbox · Human in the loop email approval · Hosted MCP inbox · MCP docs · Docs · Pricing

Operator: Avatar 8 LLC (ops@avatar33.com). Last updated 2026-11-23.

Canonical: https://cooperemail.com/integrations/langgraph