Mastra agents with Appwrite functions

Kam ChehresaKam Chehresa
2 min read

A Boring Weekend Turned Serverless Adventure

It was one of those weekends where the highlight of my social calendar was deciding which series to binge next—and yet, the itch to tinker with some AI stuff wouldn’t let me rest. I glanced at the clock on Saturday afternoon and thought: “Why not deploy a stock Mastra “Weather-Agent” into Appwrite Functions and see if serverless can wrangle a chat-based tool?”

The Setup

I cloned the Mastra quick-start, spun up a mastra's weather-tool in TypeScript, and scaffolded an Appwrite Function to host the Hono server bundle. The promise? A five-line wrapper that proxies incoming JSON to my mastra agent’s /generate endpoint and streams back real-time weather data.

The Rollercoaster of “It Works… No, It Doesn’t, oh wait, no it didn't”

What followed was equal parts fun and frustration:

  1. Cold-Start Limbo: The Function would spin up but reply with empty bodies unless I added a health-check loop to wait for Mastra’s Hono server.
  2. Schema Battles: At first I sent the wrong payload shape and faced cryptic Zod _def errors whenever I tried to include the tools array manually.
  3. Appwrite Quirks: The Exec-API hid my JSON under a "body" or "data" field, so I had to inspect every corner of req (bodyRaw, payload, body, bodyText) before I finally got my messages array through. Docs Docs Docs. Read them folks.
  4. Victory and Vagueness: After dozens of iterations, I cracked it—my wrapper now reliably forwards your chat messages, Mastra invokes the weather tool, and the real weather JSON flows back, wrapped in CORS headers and friendly logs in my Postman.

Was It Worth It?

Maybe not, if you measure strictly by business value or production readiness. The Appwrite Functions were quite something to get my head around it, the payload gymnastics made my head spin, and a simple heroku or cloudflare worker would have gotten me there faster for mastra. But on a dull weekend, wrestling with cold-starts, streaming, and JSON detective work beat the heck out of staring at Netflix menus....OK, I did end up watching Punisher season 1 at some point.

And hey—if you ever want a ready-made case study on serverless staging, payload parsing, and the joys of side-effectful imports, you know where to find me. Sometimes, the best way to beat boredom is to turn it into a mini engineering saga. 🚀

code is here

0
Subscribe to my newsletter

Read articles from Kam Chehresa directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Kam Chehresa
Kam Chehresa

All opinions are my own.