
How to fix Stitch MCP not working with API key in Antigravity?
Your Stitch MCP server fails in Antigravity when configured with an API key. You see errors like “Bad Request,” “client is closing,” and “API keys are not supported by this API.”
How to fix Stitch MCP not working with API key in Antigravity?
Antigravity’s HTTP server configuration with an API key or static bearer token does not work with Stitch MCP. The server responds with errors such as:
- API keys are not supported by this API. Expected OAuth2 access token or other authentication credentials that assert a principal.
- Bad Request / connection closed
- invalid character 'd' looking for beginning of value
- Streamable HTTP error: Error POSTing to endpoint
These appear both in Antigravity and Gemini CLI when calling tools (e.g., list_projects). The fix is to stop using HTTP + API Key and run the official Stitch MCP STDIO proxy authenticated via Google Cloud credentials.

Tip: If you’re also seeing model fetch issues in Antigravity, see this quick fix: models not loading in Antigravity.
Solution Overview
| Aspect | Detail |
|---|---|
| Root Cause | Stitch MCP rejects API keys; it expects OAuth2 credentials (principal) via Google Cloud Auth (ADC). |
| Primary Fix | Use the local Stitch MCP STDIO proxy with Google Cloud Application Default Credentials. |
| Complexity | Easy |
| Estimated Time | 10–15 minutes |
How to fix Stitch MCP not working with API key in Antigravity?
Step-by-Step Solution
1) Install and initialize Google Cloud CLI (ADC)
- Install Google Cloud SDK: Install guide
- Authenticate and set your project:
gcloud auth application-default login
gcloud config set project YOUR_PROJECT_ID
gcloud auth application-default set-quota-project YOUR_PROJECT_IDWhy this matters: Stitch MCP requires OAuth2 credentials (ADC), not API keys. The proxy will read these credentials.
2) Enable the Stitch API for your project
gcloud services enable stitch.googleapis.com --project=YOUR_PROJECT_IDReference: Enable APIs
3) Configure Antigravity to use the Stitch MCP STDIO proxy (not serverUrl)
- Open Antigravity MCP server settings.
- Add/Edit the “stitch” server configuration as a local command (STDIO), not an HTTP URL.
- Use this exact working setup (Windows example from the thread):
"stitch": {
"command": "npx.cmd",
"args": ["-y", "@_davideast/stitch-mcp@latest", "proxy"],
"env": {
"STITCH_USE_SYSTEM_GCLOUD": "1",
"GOOGLE_CLOUD_PROJECT": "YOUR_PROJECT_ID",
"CI": "1",
"DOTENV_CONFIG_QUIET": "true",
"DOTENV_QUIET": "true",
"NO_COLOR": "1"
}
}Notes:
- On macOS/Linux,
"command": "npx"is typical instead ofnpx.cmd. - The key variable is STITCH_USE_SYSTEM_GCLOUD=1, which tells the proxy to use your Google Cloud ADC.
4) Restart Antigravity
- Fully quit and relaunch Antigravity to ensure the new MCP server starts.
- Re-run your Stitch tools (e.g., list_projects) — they should now work under your authenticated principal.
5) If you get “invalid character 'd'” This usually means dotenv is printing logs like:
- [dotenv@…] injecting env…
Fix options:
- Keep
DOTENV_QUIET=trueas shown above, or - Remove/rename any
.envin the working directory so it doesn’t print during STDIO RPC.
If you also run into thinking/token limits in Antigravity, here’s a related fix: resolving the 1024 tokens not thinking issue.
Alternative Fixes & Workarounds
Use a Service Account for non-interactive environments
- Create a service account and download its JSON key. Set:
set GOOGLE_APPLICATION_CREDENTIALS=C:\path\to\sa.json # Windows (cmd)
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/sa.json # macOS/Linux (bash/zsh)- Keep the same STDIO proxy configuration. The proxy will read the service account via ADC instead of your user login.
- Ensure the service account has required IAM roles for Stitch.
Direct HTTP with OAuth2 (not recommended in Antigravity)
- If your client supports dynamic OAuth2 tokens, you could use:
Authorization: Bearer $(gcloud auth print-access-token)- However, Antigravity’s HTTP-based MCP config is unstable for Stitch. The STDIO proxy is the reliable approach.
For broader Antigravity issues impacting MCP behavior, see this quick help: fixing common token/thinking stalls.
Troubleshooting Tips
- Verify ADC is present:
gcloud auth application-default print-access-tokenIf it prints a token, ADC is set up.
- Confirm the correct project is active:
gcloud config get-value project- Ensure Stitch API is enabled:
gcloud services list --enabled --project=YOUR_PROJECT_ID | findstr stitch
# macOS/Linux: ... | grep stitch- Check Node/npm availability:
node -v
npm -v
npx -vOn Windows, Antigravity uses npx.cmd. On macOS/Linux, it’s npx.
-
Permissions: Make sure your user or service account has the required Stitch roles in IAM.
-
Environment noise: Keep
DOTENV_QUIET=trueor remove.envfiles that log during startup. -
Network/Proxy: Corporate proxies can block token exchange or STDIO spawns. Test outside the restricted network if needed.
-
Keep Google Cloud SDK current:
gcloud components updateBest Practices
- Do not use API keys with Stitch MCP; use OAuth2/ADC via gcloud or a service account.
- Prefer the local STDIO proxy over HTTP serverUrl for Antigravity.
- Pin versions where possible:
npx -y @_davideast/stitch-mcp@latest proxy(or a specific version)
- Keep
.envquiet in tools that communicate over STDIO to avoid corrupting JSON-RPC. - Regularly review IAM roles and restrict credentials to least privilege.
Final Thought
The issue isn’t with Antigravity itself—it’s authentication. Switch from API keys to Google Cloud ADC via the Stitch MCP STDIO proxy, and the errors vanish. With the steps above, Stitch tools work reliably under a valid principal.
Subscribe to our newsletter
Get the latest updates and articles directly in your inbox.
Related Posts

How to fix Agent execution terminated due to error in Antigravity?
How to fix Agent execution terminated due to error in Antigravity?

How to fix 1024 tokens is not thinking error in Antigravity?
How to fix 1024 tokens is not thinking error in Antigravity?

How to fix Ultra dramatic quota reduction after update in Antigravity?
How to fix Ultra dramatic quota reduction after update in Antigravity?

