M
Mastraโ€ข2mo ago
Karl

Mastra in Google Cloud Run

I am having a difficult time using Mastra in GCP Cloud Run. I have enabled CORS in the most permissive way possible. I connected Mastra Cloud with my Mastra server in Cloud Run, and I can see the agents and workflows and everything, but when I tried to chat with an agent, I see some network error message showing up. Upon refresh, I see my message 4 times, and Mastra server replied 4 times. Inspecting the networks, I see 4 POST requests which resulted in CORS error, but I think it is not CORS related. The endpoint I am invoking is https://mastra-ai-service-***.europe-*****.run.app/api/agents/weatherAgent/stream, and I see in Bruno/Postman 502 Bad Gateway: upstream connect error or disconnect/reset before headers. reset reason: protocol error. Thus, this is not directly a CORS problem. Then, I inspected the GCP Cloud Run log, and I only see
{
httpRequest: {14}
insertId: "***"
labels: {3}
logName: "projects/***/logs/run.googleapis.com%2Frequests"
payload: "payloadNotSet"
receiveLocation: "europe-*****"
receiveTimestamp: "2025-10-31T11:45:18.930954731Z"
resource: {2}
severity: "ERROR"
spanId: "***"
timestamp: "2025-10-31T11:45:18.879029Z"
trace: "projects/***/traces/***"
traceSampled: true
}
{
httpRequest: {14}
insertId: "***"
labels: {3}
logName: "projects/***/logs/run.googleapis.com%2Frequests"
payload: "payloadNotSet"
receiveLocation: "europe-*****"
receiveTimestamp: "2025-10-31T11:45:18.930954731Z"
resource: {2}
severity: "ERROR"
spanId: "***"
timestamp: "2025-10-31T11:45:18.879029Z"
trace: "projects/***/traces/***"
traceSampled: true
}
So there is nothing useful in the log, even though I have set the PinoLogger to DEBUG level. Has anyone successfully run Mastra in Google Cloud Run? Did you connect Mastra cloud to it? Please share.
4 Replies
Mastra Triager
Mastra Triagerโ€ข2mo ago
๐Ÿ“ Created GitHub issue: https://github.com/mastra-ai/mastra/issues/9572
GitHub
[DISCORD:1433785136364781720] Mastra in Google Cloud Run ยท Issue #...
This issue was created from Discord post: https://discord.com/channels/1309558646228779139/1433785136364781720 I am having a difficult time using Mastra in GCP Cloud Run. I have enabled CORS in the...
_roamin_
_roamin_โ€ข2mo ago
Hey @Karl ! Are you able to interact with your Mastra API endpoint outside of Studio?
Karl
KarlOPโ€ข3w ago
Hi Romain, I cannot interact with Mastra Streaming API even outside of Studio. I tried with Postman and it does not work. The fix for me was to not use Google Cloud Run, and instead I switched to Digital Ocean App Platform. My team lead is also Romain, so for a moment I thought my team lead reached out to me even here ๐Ÿ™‚
Abhi Aiyer
Abhi Aiyerโ€ข3w ago
Hi @Karl do you have a cors config in the Mastra instance? We have people using cloud run like @kosukeoya

Did you find this page helpful?