# Agents in n8n and LangChain

Give an agent ByDomu’s tools through MCP, or the API as your own tool.

Guide n8n · LangChain · LangGraph Secret key

**Before you start.** An agent running without a person watching needs its own read-only secret key, with just the permissions it needs, stored in n8n credentials or an environment variable.

## An agent in n8n

Attach an MCP Client Tool to the AI Agent node, with the server URL and Bearer authentication. Use an n8n version that offers the HTTP Streamable transport: the server doesn’t speak SSE (GET returns 405), so SSE mode won’t connect.

MCP Client Tool:

```
AI Agent
 └─ Tool: MCP Client Tool
      Endpoint        https://mcp.bydomu.com/mcp
      Server Transport  HTTP Streamable   (en versiones recientes; SSE no conecta)
      Authentication  Bearer  →  credencial con domu_sk_live_… (solo lectura)
      Tools to Include  Selected → search_properties, get_property, list_appointments
```

HTTP Request:

```
HTTP Request
  Method   GET
  URL      https://api.bydomu.com/v1/properties
  Authentication  Generic Credential Type → Header Auth
                  Name: X-API-Key   Value: domu_sk_live_…
  Query    city = {{ $json.ciudad }} · transactionType = RENT · pageSize = 12
```

For fixed steps (without the model deciding), the HTTP Request node against the REST API with X-API-Key is simpler and more predictable.

## LangChain and LangGraph

With LangChain’s MCP adapters, the nine tools arrive as regular agent tools (create_agent runs on LangGraph). LangChain is moving these adapters into langchain.mcp; the server configuration (URL and header) is the same.

Python:

```python
# pip install langchain langchain-mcp-adapters langchain-anthropic
import asyncio, os
from langchain.agents import create_agent
from langchain_mcp_adapters.client import MultiServerMCPClient

async def main():
    client = MultiServerMCPClient({
        "bydomu": {
            "transport": "streamable_http",
            "url": "https://mcp.bydomu.com/mcp",
            "headers": {"Authorization": f"Bearer {os.environ['BYDOMU_API_KEY']}"},
        }
    })
    tools = await client.get_tools()
    agent = create_agent("anthropic:claude-opus-5", tools)
    result = await agent.ainvoke(
        {"messages": [{"role": "user", "content": "¿Qué tareas vencidas tiene el equipo?"}]}
    )
    print(result["messages"][-1].content)

asyncio.run(main())
```

TypeScript:

```ts
// npm install langchain @langchain/mcp-adapters @langchain/anthropic
import { MultiServerMCPClient } from "@langchain/mcp-adapters";
import { createAgent } from "langchain";

const client = new MultiServerMCPClient({
  bydomu: {
    transport: "http",
    url: "https://mcp.bydomu.com/mcp",
    headers: { Authorization: `Bearer ${process.env.BYDOMU_API_KEY}` },
  },
});
const tools = await client.getTools();
const agent = createAgent({ model: "anthropic:claude-opus-5", tools });
const result = await agent.invoke({
  messages: [{ role: "user", content: "Resume los negocios abiertos por etapa." }],
});
console.log(result.messages.at(-1)?.content);
```

## MCP or API?

- MCP: the model picks from nine read tools already designed for conversation (short, paginated results). It’s the fastest route for an assistant.
- REST API: everything else, including writes with their approved permission. Wrap each endpoint as your own tool, send Idempotency-Key and ask for human confirmation before writing.

[Ready-made prompts for coding agents](https://developers.bydomu.com/en/prompts)

## What it can do, how to revoke it and good practices

The server is read-only: the AI can query, but it doesn’t create, change or delete anything, and it never messages your customers. It only sees what these permissions allow, with a secret key’s limit (60 requests per minute).

It can Permission

Search and view published listings `portal:read`

Search and view contacts `contacts:read`

Calendar and appointments `appointments:read`

Read a contact’s messages `conversations:read`

Pipelines and deals `deals:read`

Pending tasks `tasks:read`

With a key, the AI sees whatever that key allows. To cut access, pause or delete the key in Settings › API Keys; the next call returns 401.

- One key per integration, with only the read permissions it uses. Leave conversations:read out if you don’t need messages.
- The key goes in an environment variable or the client’s secret store, never pasted into a chat, a repository file or a URL.
- What ByDomu returns includes text your customers wrote: treat it as data, not instructions. Don’t chain this connector with tools that send emails or messages without a person approving it.
- Review Connected apps now and then and remove what’s no longer used.
