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

Building a Remote MCP Server on GCP Part 1: MCP Basics — Tools, Resources, Prompts, JSON-RPC & a Stateless Server

Part one of a Building a Remote MCP Server on GCP series that opens with a quiz: hosts, clients and servers, the three MCP primitives, the real initialize, tools/list and tools/call messages, stdio vs Streamable HTTP, the Accept and Origin rules, and why a stateless server with a new McpServer per request (0.42 ms) fits behind a load balancer.

Muhammad Fari Madyan

· 12 min read

Baca dalam Bahasa Indonesia →

Opening: 194 Articles That Claude Could Not Read

This blog has 194 articles: 98 in English and 96 in Indonesian, spread across 11 series. When I asked Claude something like "which of my articles explains the cache stampede?", it could only guess, or I had to paste the article into the chat myself. Pasting works for one article. It does not work for 4.2 MB of Markdown.

The Model Context Protocol (MCP) solves exactly this problem: it is a standard way for an AI application to call tools that someone else wrote. So I built one: an MCP server that lets Claude search and read this blog, deployed to App Engine behind a load balancer, and connected to Claude as a custom connector. It worked, and I called it live from a chat.

This series is the write-up of that project, from the protocol to the bill. This first part covers the foundation: what MCP is, what actually travels over the wire, and why I chose a stateless server.


Warm-Up Quiz: Do You Still Remember?

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

Question 1. In MCP, who decides when a tool is called?

  • A. The user, by clicking a button in the app
  • B. The model, based on the tool's name, description and schema
  • C. The server, by pushing the result to the client
Show the answer to question 1

B. Tools are model-controlled: the model reads the list from tools/list and decides when to call which tool. Resources are application-controlled and prompts are user-controlled. Section 2 explains all three.

Question 2. What message format does MCP use?

  • A. JSON-RPC 2.0
  • B. gRPC with Protocol Buffers
  • C. REST with one endpoint per tool
Show the answer to question 2

A. Every message is a JSON-RPC 2.0 request, response or notification. Over HTTP, they are all sent to one endpoint, usually POST /mcp.

Question 3. A remote MCP server runs behind a load balancer with two instances. Why is a stateful server with sessions in memory risky?

  • A. JSON-RPC does not support sessions
  • B. The next request with the same session ID can land on the other instance, which does not know that session
  • C. Load balancers block the Mcp-Session-Id header
Show the answer to question 3

B. Without sticky sessions or shared session storage, the second instance answers "unknown session". A stateless server does not have this problem: every request carries everything it needs. Section 5 has the details.

Question 4. What are the two standard MCP transports?

  • A. WebSocket and gRPC
  • B. stdio and Streamable HTTP
  • C. TCP and UDP
Show the answer to question 4

B. stdio for a server that runs as a local process, Streamable HTTP for a server that runs over the network. The older HTTP+SSE transport is deprecated.

Question 5. A client sends a request with Accept: application/json only. My server answers 406. Why?

  • A. The server is broken
  • B. Streamable HTTP requires the client to accept both application/json and text/event-stream
  • C. 406 means the rate limit was hit
Show the answer to question 5

B. The server may answer with plain JSON or with an SSE stream, so the client must accept both. The SDK enforces this rule. Section 4 shows the real response.


1. What MCP Is, in One Paragraph

MCP is a contract between three parties:

PartyExampleRole
HostClaude (web, desktop, Cowork), an IDEThe AI application the user talks to
ClientThe connector inside the hostKeeps one connection to one server
ServerMy mfarim-blog serverOffers tools, resources and prompts

Before MCP, every AI application needed its own integration for every service. With MCP, I write the server once, and any host that speaks MCP can use it. It is the same idea as an API standard, but the "user" of the API is a model.

The architecture of the blog MCP server: Claude with a custom connector sends JSON-RPC over HTTPS to a load balancer, which forwards to App Engine, where an in-memory search index serves five tools


2. Three Primitives: Tools, Resources, Prompts

An MCP server can offer three kinds of things. The difference is who controls them:

PrimitiveControlled byExampleUsed by my server?
ToolsThe modelsearch_content, get_articleYes, five tools
ResourcesThe applicationA file or document the app attaches as contextNo
PromptsThe userA template the user picks from a menu ("summarize this article")No

I only use tools, and that was deliberate. The question I wanted answered was "find the right article for this question". The model is in the best position to decide when that is needed, so a tool is the right primitive. A resource would have required the user to pick which of 194 articles to attach, which is the very problem I was trying to remove.

A rule of thumb that helped me:

  • If the model should decide when to fetch it, it is a tool.
  • If the app or user already knows which data is needed, it is a resource.
  • If it is a workflow the user starts on purpose, it is a prompt.

3. What Travels Over the Wire

Every MCP message is JSON-RPC 2.0. Here is the real conversation between a client and my server, recreated against a local copy (the URL is shortened, nothing else is changed).

Step 1: initialize. The client says which protocol version it speaks and what it can do:

BASH
curl -s http://localhost:3400/mcp \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json, text/event-stream' \
  -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{
        "protocolVersion":"2025-11-25","capabilities":{},
        "clientInfo":{"name":"curl","version":"1"}}}'
JSON
{
  "result": {
    "protocolVersion": "2025-11-25",
    "capabilities": { "tools": { "listChanged": true } },
    "serverInfo": { "name": "mfarim-blog", "title": "mfarim.com blog", "version": "0.1.0" },
    "instructions": "Search and read Muhammad Fari Madyan's engineering blog (mfarim.com) ... Use search_content first, then get_article for the full text. Always link the article URL when you use it."
  },
  "jsonrpc": "2.0",
  "id": 1
}

Note the instructions field. It is text the host may give to the model as a hint about how to use this server as a whole. I use it to say "search first, then read, and always link the article".

Step 2: tools/list. The client asks what tools exist. My server answers with five tools, each with a name, description, input schema, output schema and annotations. The whole answer is 7,693 bytes. That number matters, and Part 2 explains why.

Step 3: tools/call. The model picks a tool and arguments:

JSON
{"jsonrpc":"2.0","id":3,"method":"tools/call",
 "params":{"name":"search_content","arguments":{"query":"cache stampede","limit":3}}}

The answer contains two forms of the same result: content (text for the model to read) and structuredContent (JSON that matches the output schema):

TEXT
11 article(s) for "cache stampede":
1. GCP untuk Backend Engineer Part 6: Skala dan Biaya — Hitung Kasar, Little's Law, Cache Stampede & Budget Alert (id, 2026-11-29 · GCP untuk Backend Engineer part 6/6)
   https://www.mfarim.com/blog/id/gcp-backend-part-6-scale-and-cost
   ...
More results: call again with offset 3.

That is the whole protocol for my use case: initialize, list, call. Everything else in this series is about making those three steps good, fast, safe and cheap.


4. Two Transports: stdio and Streamable HTTP

stdioStreamable HTTP
Where the server runsA process on the user's machineAnywhere on the network
How messages travelstdin and stdout, one JSON message per linePOST /mcp, the answer is JSON or an SSE stream
Who can use itOnly that machineAnyone who can reach the URL
AuthenticationNot needed (local process)Your job (OAuth, or a public read-only server)
Fits forLocal files, local toolsA shared service, like a blog search

I chose Streamable HTTP because the point was a server that Claude can reach from any device, not just my laptop.

Streamable HTTP has a few rules worth remembering:

  • One endpoint. All messages go to POST /mcp. GET /mcp may open a stream for server-to-client messages, and DELETE /mcp ends a session.
  • The client must accept two formats. The server may answer with application/json or with text/event-stream (SSE). If the client does not accept both, the SDK refuses. This is the real answer from my server:
TEXT
HTTP/1.1 406 Not Acceptable
{"jsonrpc":"2.0","error":{"code":-32000,"message":"Not Acceptable: Client must accept both application/json and text/event-stream"},"id":null}
  • The Origin header must be validated. The spec says a server MUST validate Origin and answer 403 for an invalid one, to prevent DNS rebinding attacks against servers on localhost. My server is public, read-only and uses no cookies, so a rebinding attack gains nothing that a direct call does not already give. Still, an allowlist of origins is the compliant choice, and it is on my list.

5. Stateful or Stateless?

This was the most important design decision, and it comes from deployment, not from MCP.

In the stateful mode, the server creates a session at initialize and returns an Mcp-Session-Id header. The client sends that ID with every following request, and the server keeps the session in memory.

That is fine with one process. Behind a load balancer with two instances, it breaks:

  1. initialize lands on instance A. A creates session abc in its memory.
  2. tools/call with session abc lands on instance B.
  3. B has never heard of abc and rejects the request.

There are three ways out: sticky sessions on the load balancer, session storage in Redis, or no sessions at all. My tools do not need memory between calls: a search depends only on its arguments. So I chose stateless:

TS
app.post("/mcp", rateLimiter(rateLimitPerMinute, clientIp), express.json({ limit: "64kb" }), async (req, res) => {
  // Stateless: a fresh server and transport per request, no session ID, so any instance
  // behind the load balancer can answer any request.
  const server = createMcpServer(search, log);
  const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: undefined, enableJsonResponse: true });
  res.on("close", () => {
    void transport.close();
    void server.close();
  });
  await server.connect(transport);
  await transport.handleRequest(req, res, req.body);
});

Three details:

  • sessionIdGenerator: undefined turns sessions off. No Mcp-Session-Id header is ever sent.
  • enableJsonResponse: true answers with plain JSON instead of an SSE stream. My tools answer in milliseconds and never send progress notifications, so a stream adds nothing. Plain JSON is also easier to debug with curl and to log at the load balancer.
  • A new McpServer per request sounds wasteful, but I measured it: creating the server and registering five tools takes a p50 of 0.42 ms. The search itself takes 0.34 ms. Both are tiny compared to the network.

Because there is no session, GET /mcp and DELETE /mcp have nothing to do. My server answers them with a clear 405:

TEXT
HTTP/1.1 405 Method Not Allowed
{"jsonrpc":"2.0","error":{"code":-32000,"message":"Method not allowed. Send JSON-RPC requests with POST."},"id":null}

The protocol itself is moving the same way. The newer revision of the specification, 2026-07-28, removes protocol-level sessions and the initialize handshake entirely: every request carries its protocol version and client capabilities. My server speaks 2025-11-25 through SDK 1.32.2, but because it was already stateless, the move should be small.


6. Why a Blog Search Is a Good First MCP Project

If you want to learn MCP by building something, a search over your own content is a good choice:

  • The data is yours. No API keys, no permissions, no personal data.
  • It is read-only. The worst a bad call can do is return a poor result.
  • Quality is measurable. Part 3 shows how a bad more_like_this result was found and measured.
  • It touches real production concerns. Rate limits, logs, cold starts, certificates and cost all show up, as Parts 4 to 6 show.

The design ended up like this:

PartChoice
RuntimeNode.js 22 + TypeScript, @modelcontextprotocol/sdk 1.32.2, Express 5, zod 4
Datadata/articles.json built from the blog's Markdown at build time, 4.2 MB
SearchMiniSearch (BM25-style) in memory, no database
TransportStreamable HTTP, stateless, JSON answers
Toolssearch_content, get_article, more_like_this, list_series, send_event
HostingApp Engine Standard (F1) behind an External Application Load Balancer

7. Three Traps When Starting with MCP

Trap one: building a REST API and calling it MCP. Tools are read by a model, not a programmer. A tool named getData with a one-word description works in Postman and fails with a model. Part 2 is entirely about this.

Trap two: sessions without a plan for scaling. The stateful mode is the SDK's first example, and it works until the second instance arrives. Decide on stateless or shared sessions before you deploy.

Trap three: forgetting that the server is public. A remote MCP server is a public HTTP endpoint. Bots will find it. Part 6 shows how fast that happened.


Summary

  • MCP is a standard contract between a host (Claude), a client (connector) and a server (my blog search).
  • Three primitives: tools are model-controlled, resources app-controlled, prompts user-controlled. My server only needs tools.
  • On the wire: JSON-RPC 2.0. The core flow is initialize, tools/list, tools/call. Results carry content (text) and structuredContent (JSON).
  • Transports: stdio for local processes, Streamable HTTP for remote servers. The client must accept JSON and SSE, and the server must validate Origin.
  • Stateless fits a load balancer: a new server per request (0.42 ms), no Mcp-Session-Id, JSON answers, 405 for GET and DELETE. The 2026-07-28 spec moves the whole protocol in that direction.

Next

The protocol is the easy part. The hard part is that the "user" of my API is a model that only knows what my descriptions and schemas tell it. In Part 2, we design the five tools: names, descriptions, input limits, structured output, errors that help the model recover, and annotations that change how Claude asks for permission.

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
more writingBack to all articles →part 2 →Designing Tools for a Model

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