Help us shape the future of Go! Take the 2026 Go Developer Survey

mcpapi

package
v1.0.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotImplemented = ToolError{Code: "not_implemented", Message: "tool not implemented"}

Functions

func RegisterTools

func RegisterTools(server *mcp.Server, handler Handler, middleware ...Middleware) error

RegisterTools adds every generated tool to an existing SDK server. Call it during startup; names in this specification replace existing tools with the same name.

Types

type CreatePetRequest

type CreatePetRequest struct {
	Kind PetKind `json:"kind"`
	Name string  `json:"name"`
}

type EchoInput

type EchoInput struct {
	Message string `json:"message"`
}

type EchoOutput

type EchoOutput struct {
	Message string `json:"message"`
}

type GetPetInput

type GetPetInput struct {
	PetID string `json:"pet_id"`
}

type HTTPOptions

type HTTPOptions struct {
	Stateless      bool
	JSONResponse   bool
	SessionTimeout time.Duration
}

HTTPOptions configures the Streamable HTTP endpoint.

type Middleware

type Middleware func(ToolHandlerFunc) ToolHandlerFunc

type Pet

type Pet struct {
	ID   string  `json:"id"`
	Kind PetKind `json:"kind"`
	Name string  `json:"name"`
}

type PetKind

type PetKind string

The pet is a cat or a dog.

const (
	PetKindCat PetKind = "cat"
	PetKindDog PetKind = "dog"
)

type SearchInput

type SearchInput struct {
	Filter *SearchInputFilter `json:"filter,omitempty"`
	Limit  *int64             `json:"limit,omitempty"`
	// Case-insensitive name substring.
	Query string           `json:"query"`
	Sort  *SearchInputSort `json:"sort,omitempty"`
}

type SearchInputFilter

type SearchInputFilter struct {
	IDs *[]string `json:"ids,omitempty"`
}

type SearchInputSort

type SearchInputSort string
const (
	SearchInputSortRelevance SearchInputSort = "relevance"
	SearchInputSortCreatedAt SearchInputSort = "created_at"
)

type SearchResult

type SearchResult struct {
	Pets []Pet `json:"pets"`
}

type Server

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

func NewServer

func NewServer(handler Handler, opts ...ServerOption) (*Server, error)

func (*Server) HTTPHandler

func (s *Server) HTTPHandler(opts *HTTPOptions) http.Handler

HTTPHandler creates an endpoint to mount once on an existing HTTP router. A nil options value uses SDK defaults (stateful sessions and SSE responses).

func (*Server) MCP

func (s *Server) MCP() *mcp.Server

MCP provides SDK access for custom transports and integrations.

func (*Server) Run

func (s *Server) Run(ctx context.Context) error

func (*Server) RunStdio

func (s *Server) RunStdio(ctx context.Context) error

type ServerOption

type ServerOption func(*serverConfig)

func WithLogger

func WithLogger(logger *slog.Logger) ServerOption

func WithMiddleware

func WithMiddleware(middleware ...Middleware) ServerOption

WithMiddleware runs middleware in declaration order, after input validation.

type ToolError

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

func NewToolError

func NewToolError(code, message string) ToolError

func (ToolError) Error

func (e ToolError) Error() string

type ToolHandlerFunc

type ToolHandlerFunc func(context.Context, string, any) (any, error)

ToolHandlerFunc receives a tool name and its decoded generated input type. Return the tool's generated output type on success.

type UnimplementedHandler

type UnimplementedHandler struct{}

func (UnimplementedHandler) CreatePet

func (UnimplementedHandler) Echo

func (UnimplementedHandler) GetPet

func (UnimplementedHandler) Search

Jump to

Keyboard shortcuts

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