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 ¶
- type Context
- type Image
- type Message
- type Prompt
- type Resource
- type Server
- func (s *Server) AddAsyncTool(name string, handler interface{}, description string) error
- func (s *Server) AddPrompt(name string, handler interface{}, description string) error
- func (s *Server) AddResource(pattern string, handler interface{}, description string) error
- func (s *Server) AddTool(name string, handler interface{}, description string) error
- func (s *Server) Start() error
- type ServerOption
- type Tool
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) ReadResource ¶
ReadResource reads data from a resource
func (*Context) ReportProgress ¶
ReportProgress reports progress of a long-running operation
type Message ¶
Message represents a message in an LLM conversation
func NewAssistantMessage ¶
NewAssistantMessage creates a new message with the assistant role
func NewUserMessage ¶
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 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 ¶
AddAsyncTool adds an asynchronous tool to the server
func (*Server) AddResource ¶
AddResource adds a resource to the 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
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. |