Documentation
¶
Overview ¶
Package stdioframe reads and writes JSON-RPC messages on a byte stream in either of the two framings an MCP stdio peer may use.
MCP's stdio transport is newline-delimited: one JSON message per line, no embedded newlines (spec, Transports: stdio). mcpkit originally shipped LSP-style Content-Length framing instead, so the server keeps accepting it and detects which one the client speaks from the first byte (#1517).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Write ¶
Write writes one message to w in the given framing, Auto meaning NewlineDelimited. A newline-delimited message containing a line break is compacted first, since a raw message passed through unmarshalled may carry one and would otherwise split into two lines on the wire. The message goes out in a single Write call; callers sharing w still need their own mutex.
Types ¶
type Framing ¶
type Framing int32
Framing selects how messages are delimited on the stream.
const ( // Auto detects the framing from the first message: a leading '{' or '[' // means NewlineDelimited, anything else ContentLength. Writers treat Auto // as NewlineDelimited until detection has happened. Auto Framing = iota // NewlineDelimited is the MCP spec framing: one JSON message per line. NewlineDelimited // ContentLength is LSP-style framing: "Content-Length: N\r\n\r\n<body>". ContentLength )
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader reads messages in a fixed or detected framing. Read is not safe for concurrent use; Framing is.
func NewReader ¶
NewReader returns a Reader over r. With Auto, the framing is fixed by the first message read and never changes afterwards.