mcp

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 3 Imported by: 0

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

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

func (*Middleware) Process

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

type Server

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

Server manages MCP tools, resources, and prompts.

func NewServer

func NewServer(config *Config) *Server

NewServer creates a new MCP server.

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

func (s *Server) ListResources() []Resource

ListResources returns all registered resources.

func (*Server) ListTools

func (s *Server) ListTools() []Tool

ListTools returns all registered tools.

func (*Server) ReadResource

func (s *Server) ReadResource(ctx context.Context, uri string) (*ResourceContent, error)

ReadResource reads a registered resource.

func (*Server) RegisterResource

func (s *Server) RegisterResource(resource Resource)

RegisterResource adds a resource to the MCP server.

func (*Server) RegisterTool

func (s *Server) RegisterTool(tool Tool)

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

type ToolHandlerFunc func(ctx context.Context, input map[string]any) (*ToolResult, error)

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.

Jump to

Keyboard shortcuts

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