@@ -24,8 +24,11 @@ It is also possible for clients and servers to implement
2424In the ** stdio** transport:
2525
2626- The client launches the MCP server as a subprocess.
27- - The server receives JSON-RPC messages on its standard input (` stdin ` ) and writes
28- responses to its standard output (` stdout ` ).
27+ - The server reads JSON-RPC messages from its standard input (` stdin ` ) and sends messages
28+ to its standard output (` stdout ` ).
29+ - Messages may be JSON-RPC requests, notifications, responses—or a JSON-RPC
30+ [ batch] ( https://www.jsonrpc.org/specification#batch ) containing one or more requests
31+ and/or notifications.
2932- Messages are delimited by newlines, and ** MUST NOT** contain embedded newlines.
3033- The server ** MAY** write UTF-8 strings to its standard error (` stderr ` ) for logging
3134 purposes. Clients ** MAY** capture, forward, or ignore this logging.
@@ -66,61 +69,72 @@ The server **MUST** provide a single HTTP endpoint path (hereafter referred to a
6669** MCP endpoint** ) that supports both POST and GET methods. For example, this could be a
6770URL like ` https://example.com/mcp ` .
6871
69- ### Message Exchange
70-
71- 1 . Every JSON-RPC message sent from the client ** MUST** be a new HTTP POST request to the
72- MCP endpoint.
73-
74- 2 . When the client sends a JSON-RPC _ request_ to the MCP endpoint via POST:
75-
76- - The client ** MUST** include an ` Accept ` header, listing both ` application/json ` and
77- ` text/event-stream ` as supported content types.
78- - The server ** MUST** either return ` Content-Type: text/event-stream ` , to initiate an
79- SSE stream, or ` Content-Type: application/json ` , to return a single JSON-RPC
80- _ response_ . The client ** MUST** support both these cases.
81- - If the server initiates an SSE stream:
82- - The SSE stream ** SHOULD** eventually include a JSON-RPC _ response_ message.
83- - The server ** MAY** send JSON-RPC _ requests_ and _ notifications_ before sending a
84- JSON-RPC _ response_ . These messages ** SHOULD** relate to the originating client
85- _ request_ .
86- - The server ** SHOULD NOT** close the SSE stream before sending the JSON-RPC
87- _ response_ , unless the [ session] ( #session-management ) expires.
88- - After the JSON-RPC _ response_ has been sent, the server ** MAY** close the SSE
89- stream at any time.
90- - Disconnection ** MAY** occur at any time (e.g., due to network conditions).
91- Therefore:
92- - Disconnection ** SHOULD NOT** be interpreted as the client cancelling its
93- request.
94- - To cancel, the client ** SHOULD** explicitly send an MCP ` CancelledNotification ` .
95- - To avoid message loss due to disconnection, the server ** MAY** make the stream
96- [ resumable] ( #resumability-and-redelivery ) .
97-
98- 3 . When the client sends a JSON-RPC _ notification_ or _ response_ to the MCP endpoint via
99- POST:
100-
101- - If the server accepts the message, it ** MUST** return HTTP status code 202 Accepted
102- with no body.
103- - If the server cannot accept the message, it ** MUST** return an HTTP error status
104- code (e.g., 400 Bad Request). The HTTP response body ** MAY** comprise a JSON-RPC
105- _ error response_ that has no ` id ` .
106-
107- 4 . The client ** MAY** also issue an HTTP GET to the MCP endpoint. This can be used to
108- open an SSE stream, allowing the server to communicate to the client without the
109- client first sending a JSON-RPC _ request_ .
110- - The client ** MUST** include an ` Accept ` header, listing ` text/event-stream ` as a
111- supported content type.
112- - The server ** MUST** either return ` Content-Type: text/event-stream ` in response to
113- this HTTP GET, or else return HTTP 405 Method Not Allowed, indicating that the
114- server does not offer an SSE stream at this endpoint.
115- - If the server initiates an SSE stream:
116- - The server ** MAY** send JSON-RPC _ requests_ and _ notifications_ on the stream.
117- These messages ** SHOULD** be unrelated to any concurrently-running JSON-RPC
118- _ request_ from the client.
119- - The server ** MUST NOT** send a JSON-RPC _ response_ on the stream ** unless**
120- [ resuming] ( #resumability-and-redelivery ) a stream associated with a previous
121- client request.
122- - The server ** MAY** close the SSE stream at any time.
123- - The client ** MAY** close the SSE stream at any time.
72+ ### Sending Messages to the Server
73+
74+ Every JSON-RPC message sent from the client ** MUST** be a new HTTP POST request to the
75+ MCP endpoint.
76+
77+ 1 . The client ** MUST** use HTTP POST to send JSON-RPC messages to the MCP endpoint.
78+ 2 . The client ** MUST** include an ` Accept ` header, listing both ` application/json ` and
79+ ` text/event-stream ` as supported content types.
80+ 3 . The body of the POST request ** MUST** be one of the following:
81+ - A single JSON-RPC _ request_ , _ notification_ , or _ response_
82+ - An array [ batching] ( https://www.jsonrpc.org/specification#batch ) one or more
83+ _ requests and/or notifications_
84+ - An array [ batching] ( https://www.jsonrpc.org/specification#batch ) one or more
85+ _ responses_
86+ 4 . If the input consists solely of (any number of) JSON-RPC _ responses_ or
87+ _ notifications_ :
88+ - If the server accepts the input, the server ** MUST** return HTTP status code 202
89+ Accepted with no body.
90+ - If the server cannot accept the input, it ** MUST** return an HTTP error status code
91+ (e.g., 400 Bad Request). The HTTP response body ** MAY** comprise a JSON-RPC _ error
92+ response_ that has no ` id ` .
93+ 5 . If the input contains any number of JSON-RPC _ requests_ , the server ** MUST** either
94+ return ` Content-Type: text/event-stream ` , to initiate an SSE stream, or
95+ ` Content-Type: application/json ` , to return one JSON object. The client ** MUST**
96+ support both these cases.
97+ 6 . If the server initiates an SSE stream:
98+ - The SSE stream ** SHOULD** eventually include one JSON-RPC _ response_ per each
99+ JSON-RPC _ request_ sent in the POST body. These _ responses_ ** MAY** be
100+ [ batched] ( https://www.jsonrpc.org/specification#batch ) .
101+ - The server ** MAY** send JSON-RPC _ requests_ and _ notifications_ before sending a
102+ JSON-RPC _ response_ . These messages ** SHOULD** relate to the originating client
103+ _ request_ . These _ requests_ and _ notifications_ ** MAY** be
104+ [ batched] ( https://www.jsonrpc.org/specification#batch ) .
105+ - The server ** SHOULD NOT** close the SSE stream before sending a JSON-RPC _ response_
106+ per each received JSON-RPC _ request_ , unless the [ session] ( #session-management )
107+ expires.
108+ - After all JSON-RPC _ responses_ have been sent, the server ** SHOULD** close the SSE
109+ stream.
110+ - Disconnection ** MAY** occur at any time (e.g., due to network conditions).
111+ Therefore:
112+ - Disconnection ** SHOULD NOT** be interpreted as the client cancelling its request.
113+ - To cancel, the client ** SHOULD** explicitly send an MCP ` CancelledNotification ` .
114+ - To avoid message loss due to disconnection, the server ** MAY** make the stream
115+ [ resumable] ( #resumability-and-redelivery ) .
116+
117+ ### Listening for Messages from the Server
118+
119+ 1 . The client ** MAY** issue an HTTP GET to the MCP endpoint. This can be used to open an
120+ SSE stream, allowing the server to communicate to the client, without the client first
121+ sending data via HTTP POST.
122+ 2 . The client ** MUST** include an ` Accept ` header, listing ` text/event-stream ` as a
123+ supported content type.
124+ 3 . The server ** MUST** either return ` Content-Type: text/event-stream ` in response to
125+ this HTTP GET, or else return HTTP 405 Method Not Allowed, indicating that the server
126+ does not offer an SSE stream at this endpoint.
127+ 4 . If the server initiates an SSE stream:
128+ - The server ** MAY** send JSON-RPC _ requests_ and _ notifications_ on the stream. These
129+ _ requests_ and _ notifications_ ** MAY** be
130+ [ batched] ( https://www.jsonrpc.org/specification#batch ) .
131+ - These messages ** SHOULD** be unrelated to any concurrently-running JSON-RPC
132+ _ request_ from the client.
133+ - The server ** MUST NOT** send a JSON-RPC _ response_ on the stream ** unless**
134+ [ resuming] ( #resumability-and-redelivery ) a stream associated with a previous client
135+ request.
136+ - The server ** MAY** close the SSE stream at any time.
137+ - The client ** MAY** close the SSE stream at any time.
124138
125139### Multiple Connections
126140
0 commit comments