stdioframe

package
v0.8.23 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func Write(w io.Writer, mode Framing, data []byte) error

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
)

func (Framing) String

func (f Framing) String() string

String returns the framing's name.

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

func NewReader(r io.Reader, mode Framing) *Reader

NewReader returns a Reader over r. With Auto, the framing is fixed by the first message read and never changes afterwards.

func (*Reader) Framing

func (fr *Reader) Framing() Framing

Framing reports the framing in use: the configured one, or for Auto the detected one, or Auto if nothing has been read yet.

func (*Reader) Read

func (fr *Reader) Read() ([]byte, error)

Read returns the next message body. It returns io.EOF on a clean end of stream. In NewlineDelimited mode blank lines are skipped, a trailing "\r" is dropped, and a final line with no terminating newline is still returned.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL