Local webhook tunnels
Set up connections, serve agents and test signed callbacks before deployment.
#Test incoming webhooks locally
maivn dev-tunnel gives selected local connections temporary HTTPS callback URLs. It runs from a terminal with the SDK installed. Once your connection and project API key are configured, you can keep the agent and tunnel running without Studio or the Portal. First-time connection setup has a separate sign-in requirement. See Connection setup and terminal authentication.
The command uses an installed cloudflared client, licensed under Apache-2.0, and Cloudflare's free hosted Quick Tunnel service. No Cloudflare account, domain, paid plan, or additional Python dependency is required. The hosted service is operated by Cloudflare, and its availability is separate from the client's open-source license.
The tunnel is for a platform running on your own machine. If your project is on the hosted platform, you need no tunnel: see Test against your hosted account.
#Test against your hosted account
On the hosted platform (https://api.maivn.io) the connection receivers are already public, and they check every provider signature. The agent still runs on your machine. maivn serve pointed at the hosted platform claims each fire the receiver admits, so you can exercise a trigger against your real hosted connections, Stripe and GitHub included, before you go live.
- Create the connection in the Developer Portal (Connections → Add connection), or with
maivn connections create --base-url https://api.maivn.io(see Create a connection with the CLI). For anon_webhooktrigger, create its signing secret instead: see Webhook signing secrets. - Keep your project API key in
MAIVN_API_KEYand serve the agent against the hosted platform.
macOS and Linux
export MAIVN_BASE_URL=https://api.maivn.io
maivn serve myapp.agents:triage --project-id YOUR_PROJECT_ID --agent-id YOUR_AGENT_IDWindows (PowerShell)
$env:MAIVN_BASE_URL = 'https://api.maivn.io'
maivn serve myapp.agents:triage --project-id YOUR_PROJECT_ID --agent-id YOUR_AGENT_IDWait for Announced and keep the terminal running. In a second terminal, with the same variables, register the trigger once by calling its invoke().
- Print the callback URLs to give the provider. Against an HTTPS platform the command opens no tunnel:
maivn dev-tunnel --base-url https://api.maivn.io --connection-id conn-your-stripeIt prints https://api.maivn.io/v1/connections/conn-your-stripe/events. A real provider test, such as stripe trigger payment_intent.succeeded against a Workbench endpoint or Redeliver in GitHub, now reaches the hosted receiver and runs on your machine.
- To try the trigger before the provider sends anything, send a signed sample:
maivn connections send-test --base-url https://api.maivn.io --connection-id conn-your-stripe --kind stripe_webhook#Send a signed test delivery
maivn connections send-test signs one sample delivery on your machine and posts it to the receiver, as the provider would. The receiver verifies it and admits it exactly as it would the provider's own delivery. It works against the hosted platform and against a local one (http://127.0.0.1:8000, the default when MAIVN_BASE_URL is unset).
The defaults are maivn.test for triggers and generic webhooks, payment_intent.succeeded for Stripe (any type a Stripe trigger accepts), and pull_request.opened for GitHub (pull_request.*, issues.* or push). --stripe-mode must match the connection's mode. For GitHub, use the repository and branch your trigger selects, or the sample will not match it. For email, --dropzone is the inbox identity returned at setup, and --sender must be allowed by the trigger. No mail is sent and no mail domain is needed.
The command needs the secret the receiver checks: the connection's webhook secret, or the on_webhook signing secret. It reads it from --secret-file (the private JSON file that maivn connections create or maivn connections webhook-secret wrote), from --secret-env NAME, from a private prompt, or from one line on standard input. The secret is never sent or printed. HTTPS is required except for a platform on this machine.
maivn connections send-test --base-url https://api.maivn.io --trigger-id trg-sdk-0123 --secret-file ~/.maivn-private/billing-events.jsonAn accepted delivery prints one line such as {"accepted": true, "http_status": 202, "url": "https://api.maivn.io/v1/triggers/trg-sdk-0123/invoke"}. A refusal prints the same line to standard error and exits with status 1. A 404 means the target, secret or signature did not match; the receiver does not say which. Accepted means admitted, not that the agent finished: check the trigger's history in Studio or with trigger.history().
Each sample is a new event, so each one starts a run. To replay a saved body, pass --body-file PATH: the bytes are resent unchanged with a fresh signature. A trigger body with the same event_id (within the trigger's dedupe window), or a Stripe event with the same id, is recognized as a duplicate and starts no second run.
on_webhook triggers are always admitted. Connection events (Stripe, GitHub, generic webhooks and the other connection kinds) and email are admitted only when the platform has enabled that source for your project. If a delivery is accepted but no run starts, check that first, then the trigger, the serving agent ID and version, and the project.
#Prepare your local project
- Start your local platform so its API answers at
http://127.0.0.1:8000. The tunnel command forwards to this fixed local address. - Use an SDK build whose
maivn --helplistsdev-tunnel. In a project managed by uv, run commands asuv run maivn ...in that project's environment. In a platform source checkout, useuv run --frozen maivn ...fromlibraries/maivn-sdk. Use an absolute path to an agent outside that package. - Run
maivn dev-tunnel --install. This explicit setup downloads the official cloudflared release pinned by your SDK (CLOUDFLARED_VERSION, currently2026.8.3) from its GitHub releases, verifies its SHA-256 checksum, and stores it in~/.maivn/tools/cloudflared/. It needs no administrator access, PATH changes, Python extra, or Cloudflare account. Installation never opens a tunnel. An existing compatible client on PATH is also supported. Automatic downloads cover Windows (amd64, 386), Linux (amd64, 386, arm64, arm) and macOS (amd64, arm64). The download is limited to 128 MiB and 120 seconds. Use the official downloads for any other platform. - Create an incoming connection in the same local project as your agent. Keep its connection ID and configure the provider's signing secret through the connection setup. The tunnel does not create connections or secrets.
- Put that connection ID in your app's trigger declaration and register the trigger for the agent ID and version you will serve. If you use Studio, reload the app after editing the declaration and complete its trigger Setup steps. Start the agent in a terminal or use Run it from Studio when offered.
Check the tools before opening a tunnel:
maivn --help
maivn serve --help
maivn dev-tunnel --helpThe help commands do not open a public tunnel.
#Set up and control the tunnel in Studio
Open Config → Triggers → Connections (or your trigger's connection setup), then find Test webhooks locally. Both the project and Studio must use the local platform's API at http://127.0.0.1:8000.
- If the client is missing, choose Set up local tunnel. Wait for installation to finish. This uses the same verified installer as the terminal command.
- Choose the incoming Connection to expose, then Start tunnel.
- Choose Copy callback URL and paste it into the provider's webhook settings. An allocated address can take a moment to become reachable through public DNS. Send a provider test and inspect the trigger's run to confirm delivery.
- Choose Stop tunnel when finished. Closing the setup panel keeps it running, but closing Studio stops it. Starting again gives a new callback URL, which must replace the old URL in the provider settings.
One Studio tunnel can run at a time. Its callback exposes only the selected signed receiver. The rest of the platform stays private. A failed installation can be retried, and an unverified download is discarded. Stop remains available after sign-out or an upstream outage. Quick Tunnels do not support SSE.
The Developer Portal creates the connection and helps configure your provider. Use Studio running on your machine or the terminal commands to install and run the local tunnel. A hosted Portal cannot install software on your computer.
#Connection setup and terminal authentication
In Studio, use the project's Connections setup or the connection step in an app's trigger setup. In the Developer Portal, select the project and open Connections, then Add connection. Create an incoming connection of the correct provider type and retain any one-time secret before closing its reveal. These screens must point to your local platform for this local workflow. A connection created in a hosted project does not automatically exist locally; test it against the hosted platform instead, as described in Test against your hosted account.
The connection API is also available to terminal HTTP clients, but it requires a signed-in human session. Project MAIVN_API_KEY bearer tokens and user JWT bearer tokens do not authenticate these routes. Creating, updating, or revoking connections requires a project owner or admin and a CSRF token. Project members with read access can list them.
#Create a connection with the CLI
Run maivn connections create --help to see the supported connection kinds. The command prompts privately for your account password and any provider secret, creates one connection, then signs out. It uses the same human permissions as Studio and the Portal. It does not register a trigger or start an agent.
For example, create a Local files connection from any terminal with the SDK:
maivn connections create --project-id YOUR_PROJECT_ID --email YOU@example.com --name "Invoices folder" --kind local_file_watch --secret-file ~/.maivn-private/invoices.jsonReplace the project ID and email with your own. The project ID is the project's UUID. On Windows, native curl.exe must be on PATH, while macOS and Linux use curl. The command talks to MAIVN_BASE_URL, or to the local platform at http://127.0.0.1:8000 when that is unset; pass --base-url with a trusted HTTPS origin for a remote platform.
The command is the same on macOS, Linux and Windows. In --secret-file, ~ is your home folder: the command expands it itself when it creates the file, so it works in PowerShell too. If you prefer, write the path in full, for example $HOME\.maivn-private\invoices.json in PowerShell or $HOME/.maivn-private/invoices.json on macOS and Linux.
The secret destination must be a new file in an owner-private directory. The command creates and protects a missing parent directory, checks permissions before signing in, and refuses an existing file, shared directory, symlink or junction. Choose a private location outside your source repository and cloud sync folders. The JSON file contains the one-time signing secret and connection receipt. The terminal prints only the connection ID, callback URL and status.
For GitHub, for example:
maivn connections create --project-id YOUR_PROJECT_ID --email YOU@example.com --name "Repository events" --kind github_appThe command will ask for the provider secret privately. Keep passwords, signing secrets and private endpoint URLs out of command arguments. Automation can opt into --credentials-stdin, supplying one bounded JSON line directly from its secret store: password and the kind's required signing_secret, webhook_secret or endpoint_url. Do not echo that JSON into shell history or logs.
HTTPS session cookies stay in memory. Local HTTP uses curl's normal cookie engine and a temporary owner-private cookie folder, removed after the logout attempt. If you forcibly kill the process, it can leave a maivn-connection-session-* folder in your system temporary directory. Remove that folder after the command has stopped. A logout warning means server logout was not confirmed.
If creation was attempted but its result is unknown, check your project's Connections list before retrying. If the result says created_private_save_unconfirmed, preserve the private file for recovery and inspect the reported connection. The command never repeats the create request. If the one-time secret cannot be recovered, revoke that connection through the Portal or existing API and create a replacement.
#Serve your agent
For terminal serving, obtain your project API key through the normal project key setup, keep it in MAIVN_API_KEY, and select your local address. The SDK has one address knob (MAIVN_BASE_URL); point it at whatever single address your local platform answers requests on.
macOS and Linux
export MAIVN_BASE_URL=http://127.0.0.1:8000
maivn serve myapp.agents:triage --project-id YOUR_PROJECT_ID --agent-id YOUR_AGENT_IDWindows (PowerShell)
$env:MAIVN_BASE_URL = 'http://127.0.0.1:8000'
maivn serve myapp.agents:triage --project-id YOUR_PROJECT_ID --agent-id YOUR_AGENT_IDUse your actual import target and IDs. myapp.agents:triage means the triage Agent object exported by the myapp.agents module, and app.py:triage works for a file. Add --version N when the registered trigger targets a version other than the default of 1. --project-id can be replaced by the MAIVN_PROJECT_ID environment variable. Wait for the CLI's Announced message and keep that terminal running. The API key belongs to the agent process; the tunnel needs no mAIvn API key. Use the default worker transport for this workflow.
#Open the receiver tunnel
In a second terminal, run:
maivn dev-tunnel --connection-id conn-your-webhookRepeat the option to expose another connection in the same temporary tunnel:
maivn dev-tunnel --connection-id conn-your-webhook --connection-id conn-your-githubUse the actual connection ID from setup, not the connection's display name or the project ID. The command prints complete callback URLs, for example:
https://random-words.trycloudflare.com/v1/connections/conn-your-webhook/eventsCopy the complete URL for the matching connection into the provider's webhook configuration. Keep the path unchanged: the receiver uses it when verifying generic webhook signatures. GitHub and Slack signatures also reach the receiver unchanged, together with the original request bytes and delivery headers.
Send the provider's signed test delivery. An ordinary accepted event returns 202 with {"accepted":true}. Slack's URL-verification challenge has its own response. Then check the matching trigger's fire history and resulting run in Studio or the platform API. Admission does not mean a matching trigger has completed, and replaying the same delivery does not create another run. An HTTPS URL by itself does not prove connection setup, signature verification, trigger matching, or successful agent execution.
#What the tunnel exposes
Only POST /v1/connections/ID/events for the IDs explicitly passed on the command line reaches the fixed local API address. The proxy binds to loopback on an ephemeral port. Management routes, Studio, the Portal, other methods, unknown connection IDs, query strings, encoded paths, and alternate upstream URLs are refused. The platform still verifies provider signatures and deduplicates deliveries. The tunnel neither grants authorization nor weakens receiver checks.
The proxy limits request and response bodies to 1 MiB. The platform's receiver has a smaller 256 KiB request limit, so keep event bodies within that limit. Requests require one valid Content-Length; transfer-encoded requests are refused. The proxy handles at most 32 requests at a time, gives each connection a 5 second read deadline and waits 10 seconds for the local API. Upstream redirects are never followed or forwarded. Provider request bodies and headers are not logged. Cloudflared gets a temporary empty config and a minimal environment, so an existing named-tunnel configuration, tunnel token, or mAIvn API key is not inherited.
#Run the tunnel from Python
maivn dev-tunnel is built from the public maivn.dev_tunnel module, so a script can open the same receiver-only tunnel:
from maivn.dev_tunnel import (
CloudflaredTunnel,
ReceiverProxy,
find_cloudflared,
install_cloudflared,
)
if find_cloudflared() is None:
install_cloudflared()
with ReceiverProxy(["conn-your-webhook"]) as proxy, CloudflaredTunnel(proxy.port) as tunnel:
for path in sorted(proxy.paths):
print(tunnel.public_url + path)
tunnel.wait()Leaving the with blocks stops the cloudflared child and removes its temporary configuration. upstream_port is a Python-only option. The command always forwards to port 8000.
#Stop and troubleshoot
Press Ctrl-C in the tunnel terminal. The command stops its cloudflared child, closes its local receiver listener, and removes its temporary configuration. It does not stop your agent or local platform. Remove the temporary callback URL from the provider when you finish. Starting another Quick Tunnel produces a new URL.
- Unknown command
dev-tunnel: checkmaivn --helpin your project's SDK environment. A different globally installedmaivnmay be onPATH. - cloudflared is missing: run
maivn dev-tunnel --install, or choose Set up local tunnel in Studio. The managed client does not need to be on PATH. - The address is allocated but your browser cannot find it: allow time for public DNS propagation, then check the hostname with your network's resolver. A local resolver can return NXDOMAIN even when a public resolver has the new address. Check network filtering or ask your network operator if it persists. mAIvn does not change your machine's DNS settings. A running client alone does not prove a webhook was delivered. Confirm a provider test in the trigger's run.
- Startup exits or times out: check the installed client version and network access to Cloudflare. The command removes its child and proxy on failure.
- 404: verify the complete callback URL, connection ID, request method, and signature setup. The receiver deliberately does not disclose whether a refused connection exists.
- 400: send a fixed-length request with one
Content-Lengthheader and noTransfer-Encodingheader. - 413: the delivery is too large. The proxy refuses bodies above 1 MiB, and the receiver answers
413with codepayload_too_largeabove its smaller 256 KiB limit. - 502: check that the local platform's API answers at
http://127.0.0.1:8000. Redirects and oversized upstream responses are also refused. - The delivery arrives but no run completes: check registration and the serving process separately, including project, connection, agent ID, version, event match, and whether the trigger is enabled. Keep
MAIVN_BASE_URLpointed at the same local address the trigger was registered against, so the agent claims local fires. - Connection API returns
401or403: the serving API key does not sign you into connection setup. Check the human session, current CSRF token, and project role using the setup path above.
Quick Tunnels are temporary development endpoints with no uptime guarantee. Cloudflare limits them to 200 in-flight requests and does not support Server-Sent Events on them. Keep the agent's worker transport local. This command is for incoming receiver callbacks and does not publish the agent's streaming endpoint.