Muhammad Fari Madyan
Hire me
MCP Server · part 6 of 6

Building a Remote MCP Server on GCP Part 6: Load Balancer, Domain, Bots, and Cost — Serverless NEG, Certificates, Ingress Lock & the VPS Option

Part six and the end of a Building a Remote MCP Server on GCP series that opens with a quiz: the load balancer chain with a serverless NEG, FAILED_NOT_VISIBLE certificates and DNS only, locking ingress last, Cloud Armor with a quota of 0 on a trial account, uninvited bots, a forwarding rule costing about $18 a month, the VPS option, and teardown.

Muhammad Fari Madyan

· 15 min read

Baca dalam Bahasa Indonesia →

Opening: Guests I Never Invited

After the load balancer was up, I opened the request logs to see my own test calls. They were there. So were requests I never sent: paths my server has never had, the usual list of config files and admin pages that scanners try on every address they find.

I had not linked the new subdomain anywhere. It did not matter. A new public IP is scanned whether or not anyone links to it, and a new certificate is published in public Certificate Transparency logs, which scanners also watch.

Part 5 put the server on an appspot.com URL. This final part puts it where a real service lives: behind an External Application Load Balancer, on my own domain, with App Engine locked so only the load balancer can reach it. Then we look at the bots, the bill, the simpler VPS alternative, and how the server ended up as a connector in Claude.


Warm-Up Quiz: Do You Still Remember?

Answer first. All correct? Jump to the Summary. Missed one? Let's refresh the material.

Question 1. A load balancer with a serverless NEG pointing to App Engine. Where do you configure its health check?

  • A. On the backend service, like for VM instance groups
  • B. Nowhere. Serverless NEGs do not use load balancer health checks; the platform manages instance health
  • C. In app.yaml
Show the answer to question 1

B. This surprises people who know instance groups. Section 1 has the whole chain.

Question 2. The Google-managed certificate stays in FAILED_NOT_VISIBLE. The most likely cause?

  • A. The certificate quota is used up
  • B. The domain does not resolve to the load balancer's IP yet, for example because the DNS record is missing or proxied through a CDN
  • C. App Engine is not deployed
Show the answer to question 2

B. Google can only issue the certificate when the domain points at the load balancer. With Cloudflare, the record must be "DNS only" (grey cloud). Section 2 explains.

Question 3. Why lock App Engine's ingress to internal-and-cloud-load-balancing only after the domain works?

  • A. The lock takes a day to apply
  • B. After the lock, the appspot.com URL stops answering. If the domain does not work yet, you have no way left to reach the app
  • C. The lock deletes the certificate
Show the answer to question 3

B. That is why my script has a separate lock step that runs after the health check works through the domain.

Question 4. Roughly how much does an idle global External Application Load Balancer with one forwarding rule cost per month?

  • A. Nothing while there is no traffic
  • B. About $18, because forwarding rules are billed per hour whether or not traffic flows
  • C. About $300
Show the answer to question 4

B. $0.025 per hour for the first five forwarding rules, times about 720 hours. Section 6 has the full breakdown.

Question 5. Why could my trial account not use Cloud Armor?

  • A. Cloud Armor does not work with serverless NEGs
  • B. The free trial has a SECURITY_POLICIES quota of 0
  • C. Cloud Armor only works in us-central1
Show the answer to question 5

B. Creating the policy failed on quota. My script skips Cloud Armor with a warning, and the app's own rate limit from Part 4 is the only limit left. Section 4 covers what that means.


1. The Load Balancer, Piece by Piece

"A load balancer" on GCP is a chain of separate resources. My script creates them in this order:

BASH
g compute addresses create "$NAME-ip" --global
g compute network-endpoint-groups create "$NAME-neg" --region="$REGION" \
  --network-endpoint-type=serverless --app-engine-app
g compute backend-services create "$NAME-backend" --global --load-balancing-scheme=EXTERNAL_MANAGED
g compute backend-services add-backend "$NAME-backend" --global \
  --network-endpoint-group="$NAME-neg" --network-endpoint-group-region="$REGION"
g compute url-maps create "$NAME-urlmap" --default-service="$NAME-backend"
g compute ssl-certificates create "$NAME-cert" --domains="$DOMAIN" --global
g compute target-https-proxies create "$NAME-https" --url-map="$NAME-urlmap" --ssl-certificates="$NAME-cert"
g compute forwarding-rules create "$NAME-fr" --global --load-balancing-scheme=EXTERNAL_MANAGED \
  --address="$NAME-ip" --target-https-proxy="$NAME-https" --ports=443

(Each command in the real script is guarded by a describe, so running it twice does not fail.)

ResourceJob
Global IP addressOne static anycast IP that the DNS record points to
Forwarding rule"Traffic to this IP on port 443 goes to this proxy". This is the part that is billed per hour
Target HTTPS proxyTerminates TLS with the certificate
SSL certificateGoogle-managed, issued and renewed automatically for my domain
URL mapRoutes by host and path. Mine sends everything to one backend
Backend serviceEXTERNAL_MANAGED, where Cloud Armor would attach
Serverless NEGPoints at the App Engine app, in the app's region

The load balancer chain: a DNS A record points to a global IP, the forwarding rule on port 443 sends traffic to an HTTPS proxy with a Google-managed certificate, the URL map routes to a backend service with an optional Cloud Armor policy, and a serverless NEG forwards to App Engine with ingress locked to the load balancer

No health check. With VM instance groups, the backend service needs a health check so the load balancer knows which VMs can take traffic. A serverless NEG has no health check at all. App Engine decides which instances are healthy and how many to run. The load balancer only knows "send it to the App Engine app".

What the load balancer adds on top of the appspot.com URL:

  • My own domain with a managed certificate.
  • One place for edge policy: Cloud Armor, CDN, or routing several services under one domain.
  • A way to hide the origin: once ingress is locked, the only way in is through the load balancer.

2. Certificate and DNS: FAILED_NOT_VISIBLE and a Grey Cloud

The script ends by printing the IP and what to do next:

TEXT
Load balancer IP: 203.0.113.10
DNS: add an A record mcp.example.com → 203.0.113.10 (Cloudflare: DNS only, grey cloud).
When './deploy/gcp.sh status' shows ACTIVE and https://mcp.example.com/health works, run: ./deploy/gcp.sh lock

Google issues a managed certificate only after it can see that the domain resolves to the load balancer. Until then, the status tells you it cannot:

BASH
$ ./deploy/gcp.sh status
203.0.113.10
FAILED_NOT_VISIBLE    mcp.example.com=FAILED_NOT_VISIBLE

In my case, the cause was simple: I had not added the DNS record yet. After adding it, the record has to be DNS only in Cloudflare (grey cloud), not proxied (orange cloud). A proxied record resolves to Cloudflare's IPs, so Google would never see its own load balancer behind the name, and renewals would fail later for the same reason.

While the certificate is still provisioning, the HTTPS proxy has no certificate to present. Firefox showed PR_END_OF_FILE_ERROR, and curl fails during the TLS handshake. That looks alarming but is expected. Wait for:

BASH
$ ./deploy/gcp.sh status
203.0.113.10
ACTIVE    mcp.example.com=ACTIVE

Then the health check works through the domain:

BASH
$ curl -s https://mcp.example.com/health
{"ok":true,"articles":194,"generatedAt":"...","version":"0.1.0"}

3. Locking the Back Door

Until now, App Engine answers on two addresses: the domain (through the load balancer) and the appspot.com URL (directly). The direct URL bypasses everything the load balancer adds. One command closes it:

BASH
$ ./deploy/gcp.sh lock
# runs: gcloud app services update default --ingress=internal-and-cloud-load-balancing

After that, the appspot.com URL answers 404, and only traffic that comes through a Cloud Load Balancer (or from inside the project's network) reaches the app.

Order matters. My first version of the script locked ingress inside the lb step, right after creating the load balancer. But at that moment the certificate is not active and DNS may not exist, so the domain does not work either. Locking then would have left no working way to reach the app at all. That is why lock became its own step, run only after https://<domain>/health answers.


4. Cloud Armor, and What Happens Without It

The plan was to put the real rate limit at the edge, where it sees all traffic, with Cloud Armor:

BASH
g compute security-policies create "$NAME-armor" --description="Rate limit for the blog MCP server"
g compute security-policies rules create 1000 --security-policy="$NAME-armor" \
  --expression="true" --action=throttle \
  --rate-limit-threshold-count=120 --rate-limit-threshold-interval-sec=60 \
  --conform-action=allow --exceed-action=deny-429 --enforce-on-key=IP
g compute backend-services update "$NAME-backend" --global --security-policy="$NAME-armor"

On my trial account, the first command failed on quota (recreated):

TEXT
ERROR: (gcloud.compute.security-policies.create) Could not fetch resource:
 - Quota 'SECURITY_POLICIES' exceeded.  Limit: 0.0 globally.

A free trial account has a SECURITY_POLICIES quota of zero. The script now skips Cloud Armor with a warning instead of stopping halfway through creating the load balancer:

TEXT
WARNING: Cloud Armor skipped (no SECURITY_POLICIES quota, e.g. on a free trial account).

Without Cloud Armor, the only limit is the one inside the app (Part 4): 120 requests per minute per IP, per instance, so up to twice that across two instances. For a read-only blog search capped at two F1 instances, that is acceptable. The worst a flood can do is make the server answer 429 and run two instances for a while, and max_instances: 2 caps the bill.

Two more notes for when Cloud Armor is available:

  • enforce-on-key=IP needs the real client IP. If Cloudflare proxied the domain, Cloud Armor would see Cloudflare's IPs and limit all users together. Another reason for DNS only.
  • Edge and app limits work together. The edge stops floods before they wake an instance. The app limit is a second line, and the only line when the edge is missing.

5. The Bots: What They Found

Back to the uninvited guests. The requests in the logs were the standard scanner list: config files, admin panels, framework debug paths. None of them matched a route on my server, so each got Express's small default 404.

Why this was not a problem, by design:

  • Nothing to leak. App Engine only receives what .gcloudignore allows (Part 5): dist/, data/ and package files. There is no .env on the instance, and the server needs no secrets at all.
  • A tiny surface. Three routes: POST /mcp, GET /health, GET /. Everything else is a 404.
  • Read-only tools, no login. There is no password to guess and no data to change. The one write tool, send_event, only writes a log line.
  • Bounded cost. Scanner traffic can wake an instance from zero, but max_instances: 2 caps how many.

What I would add for a service with more at stake: Cloud Armor rules (preconfigured WAF rules and rate limits) on a paid account, a URL map that sends only known paths to the backend, and a log-based alert on the 404 rate so a sudden scan is visible without opening the logs.


6. What It Costs

These are list prices from Google Cloud's pricing pages at the time of writing. Check them before you rely on them.

ItemPriceFor this project
Forwarding rule (global, first five)$0.025 per hourAbout $18 per month, even with zero traffic
Load balancer data processingPer GB, a fraction of a centNegligible for JSON answers of a few KB
Static IP attached to a forwarding ruleNo charge$0
Google-managed certificateNo charge$0
App Engine F128 free F-class instance hours per day per projectmin_instances: 0, at most 2 instances. Light use stays inside the free hours
Cloud Build (deploys)Has a free tierA few deploys stay inside it

The forwarding rule is the line to remember. A load balancer costs money just by existing. At the rate my trial credit was converted (Rp5,455,050 for $300), $0.025 per hour is about Rp11,000 per day, whether anyone calls the server or not.

For real numbers from my account: when I checked, the whole trial account had used Rp79,519 of Rp5,455,050 in credit. That figure covers every project on the account, including other experiments, so the MCP server's own share is smaller. The way to see one project's cost is Billing → Reports, filtered by project and grouped by SKU, after a day or so for the data to arrive.


7. The Simpler Option: A VPS I Already Pay For

Everything above was worth doing to learn how App Engine and a load balancer fit together. For a personal blog search, there is a cheaper answer: the VPS that already serves this website. The repository has the config ready:

NGINX
server {
    listen 80;
    server_name mcp.example.com;
    client_max_body_size 64k;   # JSON-RPC requests are small

    location = /mcp {
        limit_req zone=mcp burst=20 nodelay;
        limit_req_status 429;
        proxy_pass http://127.0.0.1:3400;
        proxy_set_header X-Real-IP $remote_addr;
        # ...
    }
    location = /health { proxy_pass http://127.0.0.1:3400; }
    location = /       { proxy_pass http://127.0.0.1:3400; }
    location /         { return 404; }
}

Node runs under PM2 on 127.0.0.1:3400 with CLIENT_IP_HEADER=x-real-ip, Nginx rate limits at 5 requests per second per IP with a burst of 20, unknown paths never reach Node, and certbot adds TLS.

App Engine + load balancerExisting VPS + Nginx
Extra monthly costAbout $18 for the forwarding rule, plus instances beyond the free hoursAbout $0, the VPS is already paid for
ScalingAutomatic, 0 to 2 instancesOne process, limited by the VPS
Edge protectionCloud Armor (paid accounts)Nginx limit_req, and the VPS firewall
Failure domainSeparate from the websiteShares a machine with the website
Ops workMostly configUpdates, certificates and monitoring are mine

Neither is wrong. The load balancer pays off when you need several services under one domain, managed certificates, edge security, or scale beyond one machine. For 194 articles and a handful of calls a day, a VPS that already exists is hard to beat.


8. Connecting to Claude, and Tearing Down

With the domain working, connecting the server to Claude took one form: Settings → Connectors → Add custom connector, the URL https://mcp.example.com/mcp, and no authentication. The five tools appeared, split into read-only and write tools as Part 2 described. Asking Claude to search my blog for articles about the cache stampede produced a search_content call, answered by App Engine through the load balancer. From the chat, the server worked.

When the experiment is over, the teardown step stops the hourly charge:

BASH
PROJECT=my-project ./deploy/gcp.sh teardown

It deletes the resources in dependency order: forwarding rule, HTTPS proxy, certificate, URL map, backend service, Cloud Armor policy, NEG, and IP. It also sets ingress back to all, so the appspot.com URL works again. Then:

  • Delete the DNS record for the subdomain, so the name does not point at an IP that may be given to someone else.
  • App Engine stays and scales to zero. To stop it fully, disable the application in App Engine's settings, or delete the project.

9. Three Load Balancer Traps

Trap one: proxying the DNS record through a CDN. The managed certificate never becomes active, and later renewals fail. Use DNS only, or bring your own certificate.

Trap two: locking ingress before the domain works. The appspot.com URL stops answering, and nothing else works yet. Lock last.

Trap three: forgetting that idle is not free. The forwarding rule is billed every hour. Tear down experiments, and set a budget alert on the billing account before you start.


Summary

  • The chain: global IP → forwarding rule (443) → HTTPS proxy with a Google-managed certificate → URL map → backend service (EXTERNAL_MANAGED) → serverless NEG → App Engine. Serverless NEGs have no load balancer health check.
  • Certificate: FAILED_NOT_VISIBLE until the domain resolves to the load balancer. In Cloudflare, DNS only. PR_END_OF_FILE_ERROR before ACTIVE is expected.
  • Lock last: --ingress=internal-and-cloud-load-balancing makes appspot.com answer 404. It is a separate step, after the domain works.
  • Cloud Armor: the trial account's SECURITY_POLICIES quota is 0. The script skips it with a warning, and the app's per-IP, per-instance limit remains.
  • Bots arrived without anyone knowing the domain. Nothing to leak, three routes, read-only tools, and max_instances: 2 kept it a non-event.
  • Cost: the forwarding rule is about $18 a month even idle (about Rp11,000 a day). The whole trial account used Rp79,519 of Rp5,455,050 at the time I checked. Per-project cost comes from Billing Reports.
  • VPS alternative: PM2 + Nginx with limit_req, about $0 extra on a VPS I already have. Teardown deletes the load balancer in order, then delete the DNS record.

Closing the Series

At the start of this series, Claude could not read my blog. At the end, it could search 194 articles, read any of them, suggest what to read next, and link back to the source, through a server I wrote, tested, deployed and can tear down with one command.

If I had to sum up the series in one idea, it would be: a remote MCP server is an ordinary public web service whose user is a model.

  • The protocol (Part 1) is small: JSON-RPC, initialize, tools/list, tools/call. Stateless is what makes it scale behind a load balancer.
  • The user is a model (Part 2), so names, descriptions, schemas, errors and annotations are the interface, and they cost context.
  • The quality is in the data (Part 3). A search tool is only as good as its index, and my more_like_this matched templates until I measured it.
  • It is still a web service (Parts 4 to 6): tests through a real client, JSON logs, load tests that count status codes, reserved paths, real client IPs, certificates, bots, and a bill that runs even when nobody calls.

Use this series as refresher material: every part opens with a quiz. If you still get every question right, skip to the summary. If you miss one, you know which section to reread.

Thank you for following along to the end. Grab your coffee, and may your tools always be called with the right arguments!

ShareLinkedInXWhatsApp

Written by Muhammad Fari Madyan

Senior Backend Engineer and co-founder of LampungDev. I write up what I build so others can learn from it.

Work with me
← part 5Deploying to App Engineseries completeBack to all articles →

Muhammad Fari Madyan

Senior Backend Engineer building real-time, high-concurrency systems that hold up in production. Co-founder of LampungDev. Based in Bandar Lampung, Indonesia (UTC+7), working remote.

Work

Case studiesCahTixExam platform, 4 stacksOpen source

© 2026 Muhammad Fari Madyan

Designed and built by Muhammad Fari Madyan