Documentation
¶
Overview ¶
Package mcp provides Model Context Protocol support for Nexus. It enables tools, resources, and prompts to be exposed as MCP endpoints, allowing LLMs to interact with external tools and data sources.
Index ¶
- type Aware
- type Config
- type ContentBlock
- type Middleware
- type Prompt
- type PromptArgument
- type Resource
- type ResourceContent
- type ResourceHandler
- type ResourceHandlerFunc
- type Server
- func (s *Server) ExecuteTool(ctx context.Context, name string, input map[string]any) (*ToolResult, error)
- func (s *Server) ListResources() []Resource
- func (s *Server) ListTools() []Tool
- func (s *Server) ReadResource(ctx context.Context, uri string) (*ResourceContent, error)
- func (s *Server) RegisterResource(resource Resource)
- func (s *Server) RegisterTool(tool Tool)
- type Tool
- type ToolHandler
- type ToolHandlerFunc
- type ToolResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Aware ¶
type Aware interface {
// SupportsMCP returns true if the provider handles MCP tools.
SupportsMCP() bool
// SetTools configures the MCP tools available to this provider.
SetTools(tools []Tool) error
}
Aware marks a provider as supporting MCP tools natively. Providers implementing this interface can pass MCP tools directly to the LLM without Nexus needing to handle tool execution.
type Config ¶
type Config struct {
// Tools are the available MCP tools.
Tools []Tool `json:"tools,omitempty"`
// Resources are the available MCP resources.
Resources []Resource `json:"resources,omitempty"`
// Prompts are the available MCP prompt templates.
Prompts []Prompt `json:"prompts,omitempty"`
}
Config configures MCP server behavior.
type ContentBlock ¶
type ContentBlock struct {
Type string `json:"type"` // "text", "image", "resource"
Text string `json:"text,omitempty"`
}
ContentBlock is a piece of tool output content.
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
Middleware integrates MCP tool handling into the Nexus pipeline. It intercepts tool call responses and routes them to the MCP server for execution, then feeds results back into the conversation.
func NewMiddleware ¶
func NewMiddleware(server *Server) *Middleware
NewMiddleware creates an MCP pipeline middleware.
func (*Middleware) Name ¶
func (m *Middleware) Name() string
func (*Middleware) Priority ¶
func (m *Middleware) Priority() int
type Prompt ¶
type Prompt struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Arguments []PromptArgument `json:"arguments,omitempty"`
}
Prompt defines an MCP prompt template.
type PromptArgument ¶
type PromptArgument struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Required bool `json:"required,omitempty"`
}
PromptArgument defines a parameter for a prompt template.
type Resource ¶
type Resource struct {
URI string `json:"uri"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
MimeType string `json:"mime_type,omitempty"`
Handler ResourceHandler `json:"-"`
}
Resource defines an MCP resource that can be read by LLMs.
type ResourceContent ¶
type ResourceContent struct {
URI string `json:"uri"`
MimeType string `json:"mime_type,omitempty"`
Text string `json:"text,omitempty"`
}
ResourceContent is the content of a resource.
type ResourceHandler ¶
type ResourceHandler interface {
Read(ctx context.Context, uri string) (*ResourceContent, error)
}
ResourceHandler reads an MCP resource.
type ResourceHandlerFunc ¶
type ResourceHandlerFunc func(ctx context.Context, uri string) (*ResourceContent, error)
ResourceHandlerFunc adapts a function to the ResourceHandler interface.
func (ResourceHandlerFunc) Read ¶
func (f ResourceHandlerFunc) Read(ctx context.Context, uri string) (*ResourceContent, error)
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server manages MCP tools, resources, and prompts.
func (*Server) ExecuteTool ¶
func (s *Server) ExecuteTool(ctx context.Context, name string, input map[string]any) (*ToolResult, error)
ExecuteTool invokes a registered tool.
func (*Server) ListResources ¶
ListResources returns all registered resources.
func (*Server) ReadResource ¶
ReadResource reads a registered resource.
func (*Server) RegisterResource ¶
RegisterResource adds a resource to the MCP server.
func (*Server) RegisterTool ¶
RegisterTool adds a tool to the MCP server.
type Tool ¶
type Tool struct {
Name string `json:"name"`
Description string `json:"description"`
InputSchema map[string]any `json:"input_schema"`
Handler ToolHandler `json:"-"`
}
Tool defines an MCP tool that can be invoked by LLMs.
type ToolHandler ¶
type ToolHandler interface {
Execute(ctx context.Context, input map[string]any) (*ToolResult, error)
}
ToolHandler processes an MCP tool invocation.
type ToolHandlerFunc ¶
ToolHandlerFunc adapts a function to the ToolHandler interface.
func (ToolHandlerFunc) Execute ¶
func (f ToolHandlerFunc) Execute(ctx context.Context, input map[string]any) (*ToolResult, error)
type ToolResult ¶
type ToolResult struct {
Content []ContentBlock `json:"content"`
IsError bool `json:"is_error,omitempty"`
}
ToolResult is the result of a tool execution.