transport

package
v0.3.8 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package transport contains implementatations for different transport options for MCP.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error added in v0.0.2

type Error struct {
	Message string `json:"message"`
	Code    int    `json:"code"`
}

Error represents a JSON-RPC 2.0 error.

type HTTP added in v0.0.2

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

HTTP implements the Transport interface by communicating with a MCP server over HTTP using JSON-RPC.

func NewHTTP

func NewHTTP(address string) (*HTTP, error)

NewHTTP creates a new Http transport that will execute the given command. It communicates with the command using JSON-RPC over HTTP. Currently Http transport is implements MCP's Final draft version 2024-11-05, https://spec.modelcontextprotocol.io/specification/2024-11-05/basic/transports/#http-with-sse

func (*HTTP) Execute added in v0.0.2

func (t *HTTP) Execute(method string, params any) (map[string]any, error)

Execute implements the Transport via JSON-RPC over HTTP.

type Request added in v0.0.2

type Request struct {
	Params  any    `json:"params,omitempty"`
	JSONRPC string `json:"jsonrpc"`
	Method  string `json:"method"`
	ID      int    `json:"id,omitempty"`
}

Request represents a JSON-RPC 2.0 request.

type Response added in v0.0.2

type Response struct {
	Result  map[string]any `json:"result,omitempty"`
	Error   *Error         `json:"error,omitempty"`
	JSONRPC string         `json:"jsonrpc"`
	ID      int            `json:"id"`
}

Response represents a JSON-RPC 2.0 response.

func ParseResponse added in v0.0.2

func ParseResponse(r io.Reader) (*Response, error)

ParseResponse reads and parses a JSON-RPC response from a reader.

type Stdio added in v0.0.2

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

Stdio implements the Transport interface by executing a command and communicating with it via stdin/stdout using JSON-RPC.

func NewStdio

func NewStdio(command []string) *Stdio

NewStdio creates a new Stdio transport that will execute the given command. It communicates with the command using JSON-RPC over stdin/stdout.

func (*Stdio) Execute added in v0.0.2

func (t *Stdio) Execute(method string, params any) (map[string]any, error)

Execute implements the Transport interface by spawning a subprocess and communicating with it via JSON-RPC over stdin/stdout.

type Transport

type Transport interface {
	Execute(method string, params any) (map[string]any, error)
}

Transport defines the interface for communicating with MCP servers. Implementations should handle the specifics of communication protocols.

Jump to

Keyboard shortcuts

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