mcp

package
v0.0.0-...-93b92dd Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package mcp provides a Go implementation of the Machine Control Protocol (MCP).

The MCP protocol enables bidirectional communication between clients and servers for tool execution, resource access, and prompt handling. This implementation provides a complete framework for building MCP servers and clients.

The package is organized into several sub-packages:

  • protocol: Core protocol types and message definitions
  • server: Server implementation with session management
  • transport: Transport layer implementations (stdio, SSE, WebSocket)

Basic usage example:

func main() {
    // Create a new server
    srv := server.NewServer("Example Server")

    // Add a tool
    srv.AddTool("greet", func(name string) string {
        return "Hello, " + name + "!"
    }, "Greet a person")

    // Create a session
    session := server.NewSession(context.Background(), srv)

    // Create and start a transport
    t := transport.NewStdioTransport(session)
    if err := t.Start(); err != nil {
        log.Fatal(err)
    }
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

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

Context provides access to MCP capabilities during tool and resource execution

func (*Context) Info

func (c *Context) Info(msg string)

Info logs an informational message

func (*Context) ReadResource

func (c *Context) ReadResource(uri string) ([]byte, string, error)

ReadResource reads data from a resource

func (*Context) ReportProgress

func (c *Context) ReportProgress(progress float64)

ReportProgress reports progress of a long-running operation

type Image

type Image struct {
	Data   image.Image
	Format string
}

Image represents an image that can be sent to or received from the LLM

func NewImage

func NewImage(img image.Image, format string) *Image

NewImage creates a new Image instance

type Message

type Message struct {
	Role    string
	Content string
}

Message represents a message in an LLM conversation

func NewAssistantMessage

func NewAssistantMessage(content string) Message

NewAssistantMessage creates a new message with the assistant role

func NewUserMessage

func NewUserMessage(content string) Message

NewUserMessage creates a new message with the user role

type Prompt

type Prompt struct {
	Handler     interface{}
	Description string
}

Prompt represents a template for LLM interactions

type Resource

type Resource struct {
	Handler     interface{}
	Description string
	Pattern     string
}

Resource represents a data source that can be accessed by the LLM

type Server

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

Server represents an MCP server instance

func NewServer

func NewServer(name string, opts ...ServerOption) *Server

NewServer creates a new MCP server instance

func (*Server) AddAsyncTool

func (s *Server) AddAsyncTool(name string, handler interface{}, description string) error

AddAsyncTool adds an asynchronous tool to the server

func (*Server) AddPrompt

func (s *Server) AddPrompt(name string, handler interface{}, description string) error

AddPrompt adds a prompt to the server

func (*Server) AddResource

func (s *Server) AddResource(pattern string, handler interface{}, description string) error

AddResource adds a resource to the server

func (*Server) AddTool

func (s *Server) AddTool(name string, handler interface{}, description string) error

AddTool adds a synchronous tool to the server

func (*Server) Start

func (s *Server) Start() error

Start starts the MCP server

type ServerOption

type ServerOption func(*Server)

ServerOption is a function that configures a Server

func WithDependencies

func WithDependencies(deps []string) ServerOption

WithDependencies configures the server with additional dependencies

type Tool

type Tool struct {
	Handler     interface{}
	Description string
	IsAsync     bool
}

Tool represents a function that can be called by the LLM

Directories

Path Synopsis
Package fastmcp provides a simplified interface for creating MCP servers.
Package fastmcp provides a simplified interface for creating MCP servers.
Package protocol defines the core types and messages used in the MCP protocol.
Package protocol defines the core types and messages used in the MCP protocol.
Package server provides the core server implementation for the MCP protocol.
Package server provides the core server implementation for the MCP protocol.
Package transport provides different transport layer implementations for the MCP protocol.
Package transport provides different transport layer implementations for the MCP protocol.

Jump to

Keyboard shortcuts

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