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
Download agentic-mcp-flow.json, or take it from the samples folder on GitHub.
In the studio's workflow editor, import the file (see import and export).
Open the chat model node and point it at a model you have: pull
qwen2.5:7binto Ollama, type another model name, or switch the provider. In Docker,localhostis the container: usehttp://host.docker.internal:11434/v1for Ollama on the host. To check the webhook and memory first without a model, set the provider to echo. Save.Send a request:
bashcurl -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"}'Send a second request with the same
session_idand a follow-up question. The agent now sees the first exchange.Before anyone else can reach the URL, secure it (see below).
How it works
| Node | Type | Role |
|---|---|---|
| Webhook Input | webhook_input | Step in the run |
| Agent Orchestrator | agent_orchestrator | Step in the run |
| Output | output | Step in the run |
| OpenAI Chat Model | llm_call | Attached to Agent Orchestrator on its chat_model port |
| Simple Memory | local_memory | Attached to Agent Orchestrator on its memory port |
| MCP Time Tool | mcp_tool | Attached to Agent Orchestrator on its tool port |
| MCP Calculator Tool | mcp_tool | Attached 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 toauthorization, and pick a stored secret that holds the token. Callers then sendAuthorization: Bearer <token>. We checked: without the header the call gets401 {"error":"Unauthorized webhook request"}; with it, the agent answers. - HMAC signature. For callers that can sign requests,
hmac_sha256checks a hex HMAC-SHA256 oftimestamp + "." + 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-Keyreturns the first result instead of running the agent again; the same key with a different body gets409. Once it is on, every request must send the header, or it gets400. - 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
maxMessageson 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_promptfrom 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
calculatorandget_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.