> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How the Messages Travel

> Explains how JSON-RPC messages are transported between clients and MCP servers over stdio or streamable HTTP, transport rules, logging practices, authentication, and guidance for choosing transports

When a client talks to an MCP server they exchange JSON-RPC messages sent back and forth over one of two transports: stdio (local subprocess) or streamable HTTP (remote server). This guide explains how those messages are carried, what rules each transport imposes, and how to pick the right transport for your deployment.

Stdout/stdin (stdio)
The stdio transport is used when the client launches the server as a subprocess on the same machine. The client writes JSON-RPC messages to the subprocess's standard input and reads replies from the subprocess's standard output. There is no network port to open and no URL to configure — just two pipes between a parent process and a child process.

![A diagram titled "stdio — Two Pipes" showing a client (plug icon) and server (terminal icon) with numbered arrows: the client spawns a subprocess, sends JSON-RPC to the server's stdin and receives replies from stdout. Actions like opening a port or configuring a URL are shown crossed out.](https://mintcdn.com/kodekloud-c4ac6d9a/0UyWJzvxepsOrybu/images/Model-Context-Protocol-Associate-MCPA-Certification/Fundamentals-of-MCP/How-the-Messages-Travel/stdio-two-pipes-jsonrpc-diagram.jpg?fit=max\&auto=format\&n=0UyWJzvxepsOrybu\&q=85\&s=ac8543a02aa0f8372ee052b221efb4f4)

Key rule for stdio servers
Standard output (stdout) must contain only complete JSON-RPC messages — one JSON object per line. The client reads lines from the server's stdout and parses each line as a complete JSON-RPC message. If any non-protocol text (for example, a log line) is written to stdout, the client will try to parse it as JSON, fail, and the message stream will get out of sync.

Example valid JSON-RPC lines (each line is a complete JSON object):

```json theme={null}
{"jsonrpc":"2.0","id":1,"result":{"tools":[/*…*/]}}
{"jsonrpc":"2.0","id":2,"result":{"content":[/*…*/]}}
{"jsonrpc":"2.0","id":3,"result":{"ok":true}}
```

If a plain log line appears on stdout, the client will encounter a parse error:

```text theme={null}
{"jsonrpc":"2.0","id":3,"result":{"ok":true}}
cache warm 412 shipments   ←  ParseError (client tries to parse this as JSON)
{"jsonrpc":"2.0","id":4,"result":{/*…*/}}  ←  the actual reply that the client never parsed
```

Always send diagnostic logs to standard error (stderr) instead of stdout. stderr is not parsed by the client and is forwarded to the host log.

```python theme={null}
# Python
print("…")                   # writes to stdout — not allowed for logs
import sys
print("…", file=sys.stderr)  # writes to stderr — correct for logs
```

```javascript theme={null}
// Node.js
console.log("…");            // writes to stdout — not allowed for logs
console.error("…");          // writes to stderr — correct for logs
```

Always send diagnostic logs to standard error (stderr). The client does not parse stderr; it forwards it to the host log.

Do not write any non-protocol output (logs, debugging, progress text) to stdout — doing so will break the JSON-RPC message stream.

Streamable HTTP (remote servers)
Streamable HTTP is the transport used when the server runs on a different machine. The client posts each JSON-RPC message to a single HTTP endpoint and receives replies on the same request-scoped connection. Unlike a conventional HTTP response that arrives all at once and then closes, a streamable response keeps the connection open and sends incremental pieces (progress updates and partial results) as they become available until the server closes the stream.

Because streamable HTTP exposes a network endpoint, remote servers must validate the HTTP Origin header on incoming requests to protect against untrusted web pages attempting to call the server from a user's browser. The Origin header indicates which website initiated the request; the server should reject requests from untrusted origins.

![Diagram titled "Streamable HTTP" showing a client and an untrusted page on the left with arrows toward a remote server on the right; the client's connection reaches the server while the untrusted page's direct request is blocked (red X).](https://mintcdn.com/kodekloud-c4ac6d9a/0UyWJzvxepsOrybu/images/Model-Context-Protocol-Associate-MCPA-Certification/Fundamentals-of-MCP/How-the-Messages-Travel/streamable-http-client-untrusted-request-blocked.jpg?fit=max\&auto=format\&n=0UyWJzvxepsOrybu\&q=85\&s=666b3cbb2bfdd0f4d213c032e1d909e3)

Streamable HTTP response modes

* Plain JSON: If the full result is available immediately, the server can return a normal HTTP response containing the complete JSON-RPC reply.
* Stream: If the server needs to produce progress updates or partial results, it keeps the connection open and sends multiple JSON messages over the same request-scoped connection until the operation completes.

Which transport should you choose?
Choose based on where the server runs and how credentials are issued:

* Local-only services (same machine): use stdio. The client typically uses local environment variables or runtime credentials. stdio servers should not implement OAuth.
* Remote/shared services: use streamable HTTP behind proper authorization and access controls.

The specification requires that HTTP transports use OAuth for authentication/authorization, while stdio transports should not use OAuth. OAuth is a standard mechanism for web services to verify who is calling. Regardless of transport, the messages themselves remain the same JSON-RPC structure.

![A slide titled "Who Proves Who Is Calling" showing two options: a checked HTTP icon labeled "OAuth 2.1" on the left and a rejected stdio icon labeled "no OAuth" on the right.](https://mintcdn.com/kodekloud-c4ac6d9a/0UyWJzvxepsOrybu/images/Model-Context-Protocol-Associate-MCPA-Certification/Fundamentals-of-MCP/How-the-Messages-Travel/who-proves-who-calling-oauth-choice.jpg?fit=max\&auto=format\&n=0UyWJzvxepsOrybu\&q=85\&s=2127a13f6f2ae7f38460fefa72a5cea9)

Transport comparison

| Transport | Typical use case | Authentication / Notes |
| - | - | - |
| stdio (stdin/stdout) | Local subprocess integration; no network exposure | Use local credentials; do not implement OAuth; write logs to `stderr` |
| streamable HTTP | Remote servers and shared services; supports progress streaming | Use OAuth 2.1 for auth; validate the `Origin` header; supports partial/progress responses |

Useful links and references

* [JSON-RPC specification](https://www.jsonrpc.org/specification)
* [Origin header documentation](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Origin)
* [OAuth 2.1 overview](https://oauth.net/2.1/)

Now let's talk about what those messages contain.

> [card] [Watch Video](https://learn.kodekloud.com/user/courses/model-context-protocol-associate-mcpa-certification/module/1876cd42-7885-48d4-8c36-4c15b23a4bd2/lesson/d8ec7e72-923b-4b6c-bd18-ff101b4872ca)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.