> For the complete documentation index, see [llms.txt](https://dnotifier.gitbook.io/product-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dnotifier.gitbook.io/product-docs/workflows-and-agents/example-mcp-agent/python.md). Agents can also search and read this documentation through its [MCP server](https://dnotifier.gitbook.io/product-docs/~gitbook/mcp).

# Python

```python
import asyncio
import os
from dnotifier import DNotifier, define_agent

async def main():
    user_id = "demo-user"
    notifier = DNotifier(
        app_id=os.environ["DNOTIFIER_APP_ID"],
        secret=os.environ["DNOTIFIER_SECRET"],
        transport="http",
        user_id=user_id,
        permission_enforcement="backend",
        on_agent_event=lambda e: print(
            "[agent]", e.get("type"), e.get("toolId"), e.get("mcpServerId")
        ),
    )
    await notifier.connect()

    mermaid = await notifier.mcp.connect(
        {
            "id": "mermaid",
            "name": "Agentic Mermaid",
            "transport": "http",
            "endpoint": "https://agentic-mermaid.dev/mcp",
        }
    )

    all_tools = mermaid.tools()
    print("Discovered:", ", ".join(t["name"] for t in all_tools))

    by_name = {t["name"]: t for t in all_tools}
    verify = by_name.get("mermaid.verify")
    describe = by_name.get("mermaid.describe")
    render_ascii = by_name.get("mermaid.render_ascii")
    if not verify or not describe or not render_ascii:
        raise RuntimeError("Expected verify, describe, and render_ascii tools")

    sample = "flowchart LR\n  A[Start] --> B[Done]"
    direct = await verify["execute"](
        {"source": sample},
        {"executionId": "manual", "agentId": "manual", "toolId": verify["id"]},
    )
    print("Direct verify:", str(direct)[:200])

    agent = define_agent(
        name="mermaid-assistant",
        description="Validates and explains Mermaid diagrams using MCP tools.",
        instructions=(
            "You help with Mermaid diagrams. Use mermaid.verify, mermaid.describe, "
            "and mermaid.render_ascii when needed. Keep answers concise."
        ),
        provider="open_ai",
        model="gpt-4o",
        observability=True,
        tools=[verify, describe, render_ascii],
        permissions={
            "mermaid.verify": ["execute"],
            "mermaid.describe": ["execute"],
            "mermaid.render_ascii": ["execute"],
        },
    )

    result = await notifier.run_agent(
        agent,
        input=(
            "Create a Mermaid diagram for a 3-tier web architecture "
            "and render it in ASCII."
        ),
        user_id=user_id,
        max_tool_rounds=6,
    )

    print("finishReason:", result["finishReason"])
    print("executionId:", result["executionId"])
    print("output:\n", result["output"])

if __name__ == "__main__":
    asyncio.run(main())
```

## Learn more

* [**Tools & MCP — Python**](https://dnotifier.gitbook.io/product-docs/workflows-and-agents/tools-and-mcp/python.md)
* [**Local tool agent example**](https://dnotifier.gitbook.io/product-docs/workflows-and-agents/example-tool-agent/python.md)
