stdio

package
v1.0.178 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package stdio implements the MCP stdio transport, used by servers that are launched as a subprocess by an MCP host and exchange newline-delimited JSON-RPC frames over standard input and output.

tr := stdio.NewStdioServerTransport()
srv := mcp.NewServer(tr)
if err := srv.Serve(); err != nil {
    return err
}
// Start blocks, reading frames until the context is cancelled or stdin closes.
if err := tr.Start(ctx); err != nil {
    return err
}

Use NewStdioServerTransportWithIO to read and write arbitrary streams, which is how the transport is driven in tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type StdioServerTransport

type StdioServerTransport struct {
	// contains filtered or unexported fields
}

StdioServerTransport implements server-side transport for stdio communication

func NewStdioServerTransport

func NewStdioServerTransport() *StdioServerTransport

NewStdioServerTransport creates a new StdioServerTransport using os.Stdin and os.Stdout

func NewStdioServerTransportWithIO

func NewStdioServerTransportWithIO(in io.Reader, out io.Writer) *StdioServerTransport

NewStdioServerTransportWithIO creates a new StdioServerTransport with custom io.Reader and io.Writer

func (*StdioServerTransport) Close

func (t *StdioServerTransport) Close() error

Close stops the transport and cleans up resources. The close handler runs once per Start, after the transport lock is released, so it may call back into the transport; closing a transport that is not started does nothing.

func (*StdioServerTransport) Send

Send sends a JSON-RPC message

func (*StdioServerTransport) SetCloseHandler

func (t *StdioServerTransport) SetCloseHandler(handler func())

SetCloseHandler sets the handler for close events

func (*StdioServerTransport) SetErrorHandler

func (t *StdioServerTransport) SetErrorHandler(handler func(error))

SetErrorHandler sets the handler for error events

func (*StdioServerTransport) SetMessageHandler

func (t *StdioServerTransport) SetMessageHandler(handler func(ctx context.Context, message *transport.BaseJsonRpcMessage))

SetMessageHandler sets the handler for incoming messages

func (*StdioServerTransport) Start

func (t *StdioServerTransport) Start(ctx context.Context) error

Start begins listening for messages on stdin

Directories

Path Synopsis
internal
stdio
This file implements the stdio transport layer for JSON-RPC communication.
This file implements the stdio transport layer for JSON-RPC communication.

Jump to

Keyboard shortcuts

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