Skip to content

Webhook to AI agent with memory and MCP tools ​

What you get: An agent behind a webhook URL, with per-session memory and two MCP tools, that any app can call with a question and a session id.

Needs: A model: local Ollama or a provider key · Nodes: 7

A Webhook Input node at POST /webhook/agent-demo passes system_prompt, user_prompt and session_id from the request body to an Agent Orchestrator. The agent has a chat model, a Simple Memory node keyed by the session id, and two tools from the mock MCP server built into L2M. As shipped, the chat model points at a local Ollama server (http://localhost:11434/v1, model qwen2.5:7b), so you need that model, or you point the node at another one. As shipped, the webhook also has no authentication: secure it before you expose it.

Steps ​

  1. Download agentic-mcp-flow.json, or take it from the samples folder on GitHub.

  2. In the studio's workflow editor, import the file (see import and export).

  3. Open the chat model node and point it at a model you have: pull qwen2.5:7b into Ollama, type another model name, or switch the provider. In Docker, localhost is the container: use http://host.docker.internal:11434/v1 for Ollama on the host. To check the webhook and memory first without a model, set the provider to echo. Save.

  4. Send a request:

    bash
    curl -X POST http://localhost:4000/webhook/agent-demo \
      -H "Content-Type: application/json" \
      -d '{"system_prompt": "You are a helpful assistant.", "user_prompt": "What is 12 * 7?", "session_id": "demo-2"}'
  5. Send a second request with the same session_id and a follow-up question. The agent now sees the first exchange.

  6. Before anyone else can reach the URL, secure it (see below).

How it works ​

Diagram of the Agentic MCP + Memory Webhook Flow workflowRuns Webhook Input, then Agent Orchestrator, then Output. OpenAI Chat Model is attached to Agent Orchestrator as its chat model; Simple Memory is attached to Agent Orchestrator as its memory; MCP Time Tool is attached to Agent Orchestrator as its tool; MCP Calculator Tool is attached to Agent Orchestrator as its tool.Webhook Input (webhook_input)Webhook Inputwebhook_inputAgent Orchestrator (agent_orchestrator)Agent Orchestratoragent_orchestratorOpenAI Chat Model (llm_call)OpenAI Chat Modelllm_callSimple Memory (local_memory)Simple Memorylocal_memoryMCP Time Tool (mcp_tool)MCP Time Toolmcp_toolMCP Calculator Tool (mcp_tool)MCP Calculator Toolmcp_toolOutput (output)Outputoutput
Solid arrows are the order the steps run in. Dashed lines attach a chat model, memory, tools or workers to an agent; the agent uses them while it runs.
NodeTypeRole
Webhook Inputwebhook_inputStep in the run
Agent Orchestratoragent_orchestratorStep in the run
OutputoutputStep in the run
OpenAI Chat Modelllm_callAttached to Agent Orchestrator on its chat_model port
Simple Memorylocal_memoryAttached to Agent Orchestrator on its memory port
MCP Time Toolmcp_toolAttached to Agent Orchestrator on its tool port
MCP Calculator Toolmcp_toolAttached to Agent Orchestrator on its tool port

6 node types. Each type links to its config fields in the node reference.

What a run does ​

Two things are worth knowing before you call it from an app.

A model error comes back as the answer. If the chat model call fails (the model is not pulled, the server is down, the key is wrong), the agent usually does not fail the run. It returns the error message as its answer, such as Provider ollama request failed (404): ..., with stopReason: "error", and the webhook replies with that text in output.result. If an app gets text like that back, open the run and look at the Agent node.

Memory, checked with the echo model. To test the webhook and memory without a model, we set the chat model to the built-in echo provider. Two requests with session_id: "demo-2" returned Echo: What is 12 * 7? and then Echo: And what time is it in Toronto?. The second run's agent messages held the first question and answer before the new question: that is the memory. Echo never calls tools, so this check says nothing about tool use; a model that supports tool calling can call get_current_time and calculator.

Memory keeps the last 20 messages of a session (maxMessages) and, with Persist Tool Messages off, leaves tool results out of it. The tools' connection names an HTTP endpoint (http://127.0.0.1:7001/mcp), but the mock-mcp server runs inside L2M: nothing has to listen on that port.

Secure the webhook ​

With no auth mode set, anyone who can reach your L2M can call the agent and spend your model budget. On the Webhook Input node:

  • Bearer token. Set the auth mode to bearer_token, the auth header name to authorization, and pick a stored secret that holds the token. Callers then send Authorization: Bearer <token>. We checked: without the header the call gets 401 {"error":"Unauthorized webhook request"}; with it, the agent answers.
  • HMAC signature. For callers that can sign requests, hmac_sha256 checks a hex HMAC-SHA256 of timestamp + "." + raw body, sent with a timestamp header. Requests outside the replay window (300 seconds by default) and repeated signatures are rejected.
  • Idempotency. Turn it on so a retried request with the same Idempotency-Key returns the first result instead of running the agent again; the same key with a different body gets 409. Once it is on, every request must send the header, or it gets 400.
  • Allowed addresses. List the IPs or CIDR ranges that may call the trigger.

See Secure webhooks for the signing format and error codes.

Make it yours ​

  • Switch the chat model to OpenAI, Anthropic, Gemini or any OpenAI-compatible endpoint, with its key stored as a secret.
  • Replace the mock tools with a server from your MCP server registry.
  • Raise maxMessages on the memory node for longer conversations, or lower it to keep prompts small.

Make it safer ​

These controls are optional; the recipe runs without them.

  • The sample takes system_prompt from the request, so any caller can rewrite the agent's instructions. Write the system prompt on the agent node instead.
  • Require approval before write tools: with Ask before write tools on, the agent pauses before both calculator and get_current_time. This gate ignores the server's own read-only annotation and trusts only an admin's read-only mark on a registered server; the sample's inline mock tools are not registered, so both always pause. See human approval for agent tool calls.
  • Cap what callers can spend with a workflow budget.

Further reading ​

This website (not the L2M product) uses Google Analytics, only after you accept cookies. Cookie settings