Documentation
¶
Overview ¶
Package tools provides MCP tool implementations for S3 operations.
Index ¶
- Constants
- Variables
- func DefaultAnnotations(name ToolName) *mcp.ToolAnnotations
- func DefaultDescription(name ToolName) string
- func DefaultIcons() []mcp.Icon
- func ErrorResult(message string) *mcp.CallToolResult
- func ErrorResultf(format string, args ...any) *mcp.CallToolResult
- func IsWriteTool(name ToolName) bool
- func JSONResult(data any) (*mcp.CallToolResult, error)
- func TextResult(text string) *mcp.CallToolResult
- func WithToolContext(ctx context.Context, tc *ToolContext) context.Context
- type BucketResult
- type ConnectionInfo
- type CopyObjectInput
- type CopyObjectResult
- type DeleteObjectInput
- type DeleteObjectResult
- type GetObjectInput
- type GetObjectMetadataInput
- type GetObjectMetadataResult
- type GetObjectResult
- type InterceptResult
- type InterceptorChain
- type ListBucketsInput
- type ListBucketsResult
- type ListConnectionsInput
- type ListConnectionsResult
- type ListObjectsInput
- type ListObjectsResult
- type MiddlewareChain
- func (c *MiddlewareChain) Add(m ToolMiddleware)
- func (c *MiddlewareChain) After(ctx context.Context, tc *ToolContext, result *mcp.CallToolResult, ...) (*mcp.CallToolResult, error)
- func (c *MiddlewareChain) All() []ToolMiddleware
- func (c *MiddlewareChain) Before(ctx context.Context, tc *ToolContext) (context.Context, error)
- func (c *MiddlewareChain) Clear()
- func (c *MiddlewareChain) Register(m ToolMiddleware)
- type MiddlewareFunc
- type ObjectResult
- type Option
- func DisableTool(names ...ToolName) Option
- func EnableOnlyTools(names ...ToolName) Option
- func WithAnnotations(anns map[ToolName]*mcp.ToolAnnotations) Option
- func WithClientProvider(provider func(name string) (S3Client, error)) Option
- func WithDefaultConnection(name string) Option
- func WithDescriptions(descs map[ToolName]string) Option
- func WithIcons(icons map[ToolName][]mcp.Icon) Option
- func WithInterceptor(i ...RequestInterceptor) Option
- func WithLogger(logger *slog.Logger) Option
- func WithMaxGetSize(size int64) Option
- func WithMaxPutSize(size int64) Option
- func WithMiddleware(m ...ToolMiddleware) Option
- func WithReadOnly(readOnly bool) Option
- func WithToolMiddleware(name ToolName, m ...ToolMiddleware) Option
- func WithToolPrefix(prefix string) Option
- func WithTransformer(tr ...ResultTransformer) Option
- type PresignURLInput
- type PresignURLResult
- type PutObjectInput
- type PutObjectResult
- type RequestInterceptor
- type RequestInterceptorFunc
- type ResultTransformer
- type ResultTransformerFunc
- type S3Client
- type ToolContext
- func (tc *ToolContext) Clone() *ToolContext
- func (tc *ToolContext) Delete(key string)
- func (tc *ToolContext) Duration() time.Duration
- func (tc *ToolContext) Get(key string) any
- func (tc *ToolContext) GetBool(key string) bool
- func (tc *ToolContext) GetInt(key string) int
- func (tc *ToolContext) GetString(key string) string
- func (tc *ToolContext) Has(key string) bool
- func (tc *ToolContext) Set(key string, value any)
- type ToolMiddleware
- type ToolMiddlewareRegistry
- type ToolName
- type ToolOption
- type Toolkit
- func (t *Toolkit) AddClient(name string, client S3Client)
- func (t *Toolkit) Close() error
- func (t *Toolkit) GetClient(name string) (S3Client, error)
- func (t *Toolkit) IsReadOnly() bool
- func (t *Toolkit) ListConnections() []string
- func (t *Toolkit) MaxGetSize() int64
- func (t *Toolkit) MaxPutSize() int64
- func (t *Toolkit) Register(server *mcp.Server, names ...ToolName)
- func (t *Toolkit) RegisterAll(server *mcp.Server)
- func (t *Toolkit) RegisterTools(s *mcp.Server)
- func (t *Toolkit) RegisterWith(server *mcp.Server, name ToolName, opts ...ToolOption)
- type TransformerChain
Constants ¶
const ( // DefaultMaxGetSize is the default maximum size for object retrieval (10MB). DefaultMaxGetSize = 10 * 1024 * 1024 // DefaultMaxPutSize is the default maximum size for object uploads (100MB). DefaultMaxPutSize = 100 * 1024 * 1024 )
Default size limits.
Variables ¶
var ( // ErrReadOnly is returned when a write operation is attempted in read-only mode. ErrReadOnly = errors.New("operation not permitted: server is in read-only mode") // ErrSizeLimitExceeded is returned when an object exceeds the size limit. ErrSizeLimitExceeded = errors.New("object size exceeds limit") // ErrMissingParameter is returned when a required parameter is missing. ErrMissingParameter = errors.New("missing required parameter") // ErrInvalidParameter is returned when a parameter has an invalid value. ErrInvalidParameter = errors.New("invalid parameter value") // ErrConnectionNotFound is returned when a requested connection doesn't exist. ErrConnectionNotFound = errors.New("connection not found") // ErrNotFound is returned when a requested resource doesn't exist. ErrNotFound = errors.New("resource not found") )
Common error types for S3 tools.
Functions ¶
func DefaultAnnotations ¶ added in v0.2.0
func DefaultAnnotations(name ToolName) *mcp.ToolAnnotations
DefaultAnnotations returns the default annotations for a tool. Returns nil for unknown tool names.
func DefaultDescription ¶ added in v0.2.0
DefaultDescription returns the default description for a tool. Returns an empty string for unknown tool names.
func DefaultIcons ¶ added in v0.2.1
DefaultIcons returns the default icons for S3 tools.
func ErrorResult ¶
func ErrorResult(message string) *mcp.CallToolResult
ErrorResult creates an MCP CallToolResult with an error message.
func ErrorResultf ¶
func ErrorResultf(format string, args ...any) *mcp.CallToolResult
ErrorResultf creates an MCP CallToolResult with a formatted error message.
func IsWriteTool ¶
IsWriteTool returns true if the tool name is a write operation.
func JSONResult ¶
func JSONResult(data any) (*mcp.CallToolResult, error)
JSONResult creates an MCP CallToolResult with JSON-encoded data.
func TextResult ¶
func TextResult(text string) *mcp.CallToolResult
TextResult creates an MCP CallToolResult with a text message.
func WithToolContext ¶
func WithToolContext(ctx context.Context, tc *ToolContext) context.Context
WithToolContext returns a new context with the ToolContext attached.
Types ¶
type BucketResult ¶
type BucketResult struct {
Name string `json:"name"`
CreationDate string `json:"creation_date,omitempty"`
}
BucketResult represents a bucket in the list results.
type ConnectionInfo ¶
type ConnectionInfo struct {
Name string `json:"name"`
Region string `json:"region,omitempty"`
Endpoint string `json:"endpoint,omitempty"`
}
ConnectionInfo represents information about an S3 connection.
type CopyObjectInput ¶ added in v0.1.4
type CopyObjectInput struct {
SourceBucket string `json:"source_bucket" jsonschema_description:"Name of the source S3 bucket."`
SourceKey string `json:"source_key" jsonschema_description:"Key (path) of the source object."`
DestBucket string `json:"dest_bucket" jsonschema_description:"Name of the destination S3 bucket."`
DestKey string `json:"dest_key" jsonschema_description:"Key (path) for the destination object."`
Metadata map[string]string `` /* 134-byte string literal not displayed */
Connection string `` /* 133-byte string literal not displayed */
}
CopyObjectInput defines the input parameters for the copy_object tool.
type CopyObjectResult ¶
type CopyObjectResult struct {
SourceBucket string `json:"source_bucket"`
SourceKey string `json:"source_key"`
DestBucket string `json:"dest_bucket"`
DestKey string `json:"dest_key"`
ETag string `json:"etag,omitempty"`
LastModified string `json:"last_modified,omitempty"`
VersionID string `json:"version_id,omitempty"`
}
CopyObjectResult represents the result of copying an object.
type DeleteObjectInput ¶ added in v0.1.4
type DeleteObjectInput struct {
Bucket string `json:"bucket" jsonschema_description:"Name of the S3 bucket containing the object to delete."`
Key string `json:"key" jsonschema_description:"Key (path) of the object to delete."`
Connection string `` /* 133-byte string literal not displayed */
}
DeleteObjectInput defines the input parameters for the delete_object tool.
type DeleteObjectResult ¶
type DeleteObjectResult struct {
Bucket string `json:"bucket"`
Key string `json:"key"`
Deleted bool `json:"deleted"`
}
DeleteObjectResult represents the result of deleting an object.
type GetObjectInput ¶ added in v0.1.4
type GetObjectInput struct {
Bucket string `json:"bucket" jsonschema_description:"Name of the S3 bucket containing the object."`
Key string `json:"key" jsonschema_description:"Key (path) of the object to retrieve."`
Connection string `` /* 133-byte string literal not displayed */
}
GetObjectInput defines the input parameters for the get_object tool.
type GetObjectMetadataInput ¶ added in v0.1.4
type GetObjectMetadataInput struct {
Bucket string `json:"bucket" jsonschema_description:"Name of the S3 bucket containing the object."`
Key string `json:"key" jsonschema_description:"Key (path) of the object to get metadata for."`
Connection string `` /* 133-byte string literal not displayed */
}
GetObjectMetadataInput defines the input parameters for the get_object_metadata tool.
type GetObjectMetadataResult ¶
type GetObjectMetadataResult struct {
Bucket string `json:"bucket"`
Key string `json:"key"`
Size int64 `json:"size"`
ContentType string `json:"content_type,omitempty"`
ContentLength int64 `json:"content_length"`
LastModified string `json:"last_modified,omitempty"`
ETag string `json:"etag,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
}
GetObjectMetadataResult represents the result of getting object metadata.
type GetObjectResult ¶
type GetObjectResult struct {
Bucket string `json:"bucket"`
Key string `json:"key"`
Size int64 `json:"size"`
ContentType string `json:"content_type,omitempty"`
LastModified string `json:"last_modified,omitempty"`
ETag string `json:"etag,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
Content string `json:"content"`
IsBase64 bool `json:"is_base64"`
Truncated bool `json:"truncated"`
}
GetObjectResult represents the result of getting an object.
type InterceptResult ¶
type InterceptResult struct {
// Allow indicates whether the request should proceed.
Allow bool
// Reason provides an explanation if the request was blocked.
Reason string
// ModifiedRequest is an optional modified version of the request.
// If nil, the original request is used.
ModifiedRequest *mcp.CallToolRequest
}
InterceptResult represents the result of a request interception.
func Allowed ¶
func Allowed() InterceptResult
Allowed returns an InterceptResult that allows the request to proceed.
func AllowedWithModification ¶
func AllowedWithModification(req *mcp.CallToolRequest) InterceptResult
AllowedWithModification returns an InterceptResult that allows with a modified request.
func Blocked ¶
func Blocked(reason string) InterceptResult
Blocked returns an InterceptResult that blocks the request.
type InterceptorChain ¶
type InterceptorChain struct {
// contains filtered or unexported fields
}
InterceptorChain manages a collection of request interceptors.
func NewInterceptorChain ¶
func NewInterceptorChain() *InterceptorChain
NewInterceptorChain creates a new interceptor chain.
func (*InterceptorChain) Add ¶
func (c *InterceptorChain) Add(i RequestInterceptor)
Add adds an interceptor to the chain.
func (*InterceptorChain) All ¶
func (c *InterceptorChain) All() []RequestInterceptor
All returns all registered interceptors.
func (*InterceptorChain) Clear ¶
func (c *InterceptorChain) Clear()
Clear removes all interceptors from the chain.
func (*InterceptorChain) Intercept ¶
func (c *InterceptorChain) Intercept(ctx context.Context, tc *ToolContext, request *mcp.CallToolRequest) InterceptResult
Intercept runs all interceptors in order. Returns the first blocking result, or allows if all pass.
type ListBucketsInput ¶ added in v0.1.4
type ListBucketsInput struct {
Connection string `` /* 133-byte string literal not displayed */
}
ListBucketsInput defines the input parameters for the list_buckets tool.
type ListBucketsResult ¶
type ListBucketsResult struct {
Buckets []BucketResult `json:"buckets"`
Count int `json:"count"`
}
ListBucketsResult represents the result of listing buckets.
type ListConnectionsInput ¶ added in v0.1.4
type ListConnectionsInput struct {
}
ListConnectionsInput defines the input parameters for the list_connections tool.
type ListConnectionsResult ¶
type ListConnectionsResult struct {
Connections []ConnectionInfo `json:"connections"`
DefaultConnection string `json:"default_connection"`
Count int `json:"count"`
}
ListConnectionsResult represents the result of listing connections.
type ListObjectsInput ¶ added in v0.1.4
type ListObjectsInput struct {
Bucket string `json:"bucket" jsonschema_description:"Name of the S3 bucket to list objects from."`
Prefix string `` /* 141-byte string literal not displayed */
Delimiter string `` /* 156-byte string literal not displayed */
MaxKeys int32 `json:"max_keys,omitempty" jsonschema_description:"Maximum number of objects to return (1-1000). Default: 1000."`
ContinuationToken string `` /* 136-byte string literal not displayed */
Connection string `` /* 133-byte string literal not displayed */
}
ListObjectsInput defines the input parameters for the list_objects tool.
type ListObjectsResult ¶
type ListObjectsResult struct {
Bucket string `json:"bucket"`
Prefix string `json:"prefix,omitempty"`
Delimiter string `json:"delimiter,omitempty"`
Objects []ObjectResult `json:"objects"`
CommonPrefixes []string `json:"common_prefixes,omitempty"`
Count int `json:"count"`
IsTruncated bool `json:"is_truncated"`
NextContinueToken string `json:"next_continuation_token,omitempty"`
}
ListObjectsResult represents the result of listing objects.
type MiddlewareChain ¶ added in v0.1.4
type MiddlewareChain struct {
// contains filtered or unexported fields
}
MiddlewareChain manages a collection of middleware.
func NewMiddlewareChain ¶ added in v0.1.4
func NewMiddlewareChain() *MiddlewareChain
NewMiddlewareChain creates a new middleware chain.
func (*MiddlewareChain) Add ¶ added in v0.1.4
func (c *MiddlewareChain) Add(m ToolMiddleware)
Add adds middleware to the chain.
func (*MiddlewareChain) After ¶ added in v0.1.4
func (c *MiddlewareChain) After( ctx context.Context, tc *ToolContext, result *mcp.CallToolResult, handlerErr error, ) (*mcp.CallToolResult, error)
After runs all After hooks in reverse order (like defer).
func (*MiddlewareChain) All ¶ added in v0.1.4
func (c *MiddlewareChain) All() []ToolMiddleware
All returns all registered middleware.
func (*MiddlewareChain) Before ¶ added in v0.1.4
func (c *MiddlewareChain) Before(ctx context.Context, tc *ToolContext) (context.Context, error)
Before runs all Before hooks in order.
func (*MiddlewareChain) Clear ¶ added in v0.1.4
func (c *MiddlewareChain) Clear()
Clear removes all middleware from the chain.
func (*MiddlewareChain) Register ¶ added in v0.1.4
func (c *MiddlewareChain) Register(m ToolMiddleware)
Register adds middleware to the registry.
type MiddlewareFunc ¶
type MiddlewareFunc struct {
// contains filtered or unexported fields
}
MiddlewareFunc is a function-based implementation of ToolMiddleware.
func AfterFunc ¶ added in v0.1.4
func AfterFunc(fn func(context.Context, *ToolContext, *mcp.CallToolResult, error) (*mcp.CallToolResult, error)) *MiddlewareFunc
AfterFunc creates a middleware that only runs after the handler.
func BeforeFunc ¶ added in v0.1.4
func BeforeFunc(fn func(context.Context, *ToolContext) (context.Context, error)) *MiddlewareFunc
BeforeFunc creates a middleware that only runs before the handler.
func NewMiddlewareFunc ¶
func NewMiddlewareFunc( name string, beforeFn func(context.Context, *ToolContext) (context.Context, error), afterFn func(context.Context, *ToolContext, *mcp.CallToolResult, error) (*mcp.CallToolResult, error), ) *MiddlewareFunc
NewMiddlewareFunc creates a new MiddlewareFunc with the given name and functions.
func (*MiddlewareFunc) After ¶ added in v0.1.4
func (m *MiddlewareFunc) After( ctx context.Context, tc *ToolContext, result *mcp.CallToolResult, handlerErr error, ) (*mcp.CallToolResult, error)
After calls the after function if set.
func (*MiddlewareFunc) Before ¶ added in v0.1.4
func (m *MiddlewareFunc) Before(ctx context.Context, tc *ToolContext) (context.Context, error)
Before calls the before function if set.
func (*MiddlewareFunc) Name ¶
func (m *MiddlewareFunc) Name() string
Name returns the middleware name.
type ObjectResult ¶
type ObjectResult struct {
Key string `json:"key"`
Size int64 `json:"size"`
LastModified string `json:"last_modified,omitempty"`
ETag string `json:"etag,omitempty"`
StorageClass string `json:"storage_class,omitempty"`
}
ObjectResult represents an object in the list results.
type Option ¶
type Option func(*Toolkit)
Option is a functional option for configuring a Toolkit.
func DisableTool ¶
DisableTool disables specific tools from being registered.
func EnableOnlyTools ¶
EnableOnlyTools enables only the specified tools, disabling all others.
func WithAnnotations ¶ added in v0.2.0
func WithAnnotations(anns map[ToolName]*mcp.ToolAnnotations) Option
WithAnnotations sets toolkit-level annotation overrides for tools. These take priority over default annotations but can be overridden by per-registration WithAnnotation options.
func WithClientProvider ¶
WithClientProvider sets a function that provides S3 clients by connection name.
func WithDefaultConnection ¶
WithDefaultConnection sets the default connection name.
func WithDescriptions ¶ added in v0.2.0
WithDescriptions sets toolkit-level description overrides for tools. These take priority over default descriptions but can be overridden by per-registration WithDescription options.
func WithIcons ¶ added in v0.2.1
WithIcons sets toolkit-level icon overrides for tools. These take priority over default icons but can be overridden by per-registration WithIcon options.
func WithInterceptor ¶
func WithInterceptor(i ...RequestInterceptor) Option
WithInterceptor adds a request interceptor to the toolkit.
func WithLogger ¶
WithLogger sets the logger for the toolkit.
func WithMaxGetSize ¶
WithMaxGetSize sets the maximum size for object retrieval.
func WithMaxPutSize ¶
WithMaxPutSize sets the maximum size for object uploads.
func WithMiddleware ¶
func WithMiddleware(m ...ToolMiddleware) Option
WithMiddleware adds middleware to the toolkit.
func WithReadOnly ¶
WithReadOnly enables read-only mode, blocking all write operations.
func WithToolMiddleware ¶ added in v0.1.4
func WithToolMiddleware(name ToolName, m ...ToolMiddleware) Option
WithToolMiddleware adds middleware for specific tools.
func WithToolPrefix ¶
WithToolPrefix sets a prefix for all tool names. This is useful when composing multiple toolkits.
func WithTransformer ¶
func WithTransformer(tr ...ResultTransformer) Option
WithTransformer adds a result transformer to the toolkit.
type PresignURLInput ¶ added in v0.1.4
type PresignURLInput struct {
Bucket string `json:"bucket" jsonschema_description:"Name of the S3 bucket containing the object."`
Key string `json:"key" jsonschema_description:"Key (path) of the object to generate a URL for."`
Method string `` /* 139-byte string literal not displayed */
ExpiresIn int `` /* 134-byte string literal not displayed */
Connection string `` /* 133-byte string literal not displayed */
}
PresignURLInput defines the input parameters for the presign_url tool.
type PresignURLResult ¶
type PresignURLResult struct {
Bucket string `json:"bucket"`
Key string `json:"key"`
URL string `json:"url"`
Method string `json:"method"`
ExpiresIn int `json:"expires_in_seconds"`
ExpiresAt string `json:"expires_at"`
}
PresignURLResult represents the result of generating a presigned URL.
type PutObjectInput ¶ added in v0.1.4
type PutObjectInput struct {
Bucket string `json:"bucket" jsonschema_description:"Name of the S3 bucket to upload to."`
Key string `json:"key" jsonschema_description:"Key (path) for the object in the bucket."`
Content string `` /* 130-byte string literal not displayed */
ContentType string `` /* 161-byte string literal not displayed */
IsBase64 bool `json:"is_base64,omitempty" jsonschema_description:"Set to true if the content is base64-encoded binary data."`
Metadata map[string]string `json:"metadata,omitempty" jsonschema_description:"Custom metadata key-value pairs to attach to the object."`
Connection string `` /* 133-byte string literal not displayed */
}
PutObjectInput defines the input parameters for the put_object tool.
type PutObjectResult ¶
type PutObjectResult struct {
Bucket string `json:"bucket"`
Key string `json:"key"`
Size int64 `json:"size"`
ETag string `json:"etag,omitempty"`
VersionID string `json:"version_id,omitempty"`
}
PutObjectResult represents the result of putting an object.
type RequestInterceptor ¶
type RequestInterceptor interface {
// Name returns a unique identifier for this interceptor.
Name() string
// Intercept examines the request and returns an InterceptResult.
// Called before the tool handler executes.
Intercept(ctx context.Context, tc *ToolContext, request *mcp.CallToolRequest) InterceptResult
}
RequestInterceptor allows inspection and modification of requests before execution. Unlike middleware, interceptors focus on request validation and access control.
type RequestInterceptorFunc ¶
type RequestInterceptorFunc struct {
// contains filtered or unexported fields
}
RequestInterceptorFunc is a function type that implements RequestInterceptor.
func NewRequestInterceptorFunc ¶
func NewRequestInterceptorFunc( name string, fn func(context.Context, *ToolContext, *mcp.CallToolRequest) InterceptResult, ) *RequestInterceptorFunc
NewRequestInterceptorFunc creates a new RequestInterceptorFunc.
func (*RequestInterceptorFunc) Intercept ¶
func (i *RequestInterceptorFunc) Intercept(ctx context.Context, tc *ToolContext, request *mcp.CallToolRequest) InterceptResult
Intercept calls the underlying function.
func (*RequestInterceptorFunc) Name ¶
func (i *RequestInterceptorFunc) Name() string
Name returns the interceptor name.
type ResultTransformer ¶
type ResultTransformer interface {
// Name returns a unique identifier for this transformer.
Name() string
// Transform modifies the result and returns the transformed version.
Transform(ctx context.Context, tc *ToolContext, result *mcp.CallToolResult) (*mcp.CallToolResult, error)
}
ResultTransformer allows modification of tool results after execution. Transformers can add metadata, filter content, or format output.
type ResultTransformerFunc ¶
type ResultTransformerFunc struct {
// contains filtered or unexported fields
}
ResultTransformerFunc is a function type that implements ResultTransformer.
func NewResultTransformerFunc ¶
func NewResultTransformerFunc( name string, fn func(context.Context, *ToolContext, *mcp.CallToolResult) (*mcp.CallToolResult, error), ) *ResultTransformerFunc
NewResultTransformerFunc creates a new ResultTransformerFunc.
func (*ResultTransformerFunc) Name ¶
func (t *ResultTransformerFunc) Name() string
Name returns the transformer name.
func (*ResultTransformerFunc) Transform ¶
func (t *ResultTransformerFunc) Transform(ctx context.Context, tc *ToolContext, result *mcp.CallToolResult) (*mcp.CallToolResult, error)
Transform calls the underlying function.
type S3Client ¶
type S3Client interface {
// ConnectionName returns the configured connection name.
ConnectionName() string
// Config returns a copy of the client configuration.
Config() *client.Config
// ListBuckets returns a list of all buckets accessible to the client.
ListBuckets(ctx context.Context) ([]client.BucketInfo, error)
// ListObjects lists objects in a bucket with optional prefix, delimiter, and pagination.
ListObjects(ctx context.Context, bucket, prefix, delimiter string, maxKeys int32, continueToken string) (*client.ListObjectsOutput, error)
// GetObject retrieves an object's content from S3.
GetObject(ctx context.Context, bucket, key string) (*client.ObjectContent, error)
// GetObjectMetadata retrieves an object's metadata without downloading the content.
GetObjectMetadata(ctx context.Context, bucket, key string) (*client.ObjectMetadata, error)
// PutObject uploads an object to S3.
PutObject(ctx context.Context, input *client.PutObjectInput) (*client.PutObjectOutput, error)
// DeleteObject deletes an object from S3.
DeleteObject(ctx context.Context, bucket, key string) error
// CopyObject copies an object within or between buckets.
CopyObject(ctx context.Context, input *client.CopyObjectInput) (*client.CopyObjectOutput, error)
// PresignGetURL generates a presigned URL for downloading an object.
PresignGetURL(ctx context.Context, bucket, key string, expires time.Duration) (*client.PresignedURL, error)
// PresignPutURL generates a presigned URL for uploading an object.
PresignPutURL(ctx context.Context, bucket, key string, expires time.Duration) (*client.PresignedURL, error)
// Close closes the S3 client and releases resources.
Close() error
}
S3Client defines the interface for S3 operations used by MCP tools. This interface allows for easy mocking in tests.
type ToolContext ¶
type ToolContext struct {
// ToolName is the name of the tool being executed.
ToolName ToolName
// ConnectionName is the name of the S3 connection being used.
ConnectionName string
// RequestID is a unique identifier for this request.
RequestID string
// StartTime is when the tool execution started.
StartTime time.Time
// contains filtered or unexported fields
}
ToolContext provides contextual information and state for tool execution. It allows middleware, interceptors, and tools to share data during a request.
func GetToolContext ¶
func GetToolContext(ctx context.Context) *ToolContext
GetToolContext retrieves the ToolContext from a context. Returns nil if no ToolContext is present.
func NewToolContext ¶
func NewToolContext(toolName ToolName, connectionName string) *ToolContext
NewToolContext creates a new ToolContext with the given tool and connection names.
func (*ToolContext) Clone ¶
func (tc *ToolContext) Clone() *ToolContext
Clone creates a shallow copy of the ToolContext.
func (*ToolContext) Delete ¶
func (tc *ToolContext) Delete(key string)
Delete removes a value from the context by key.
func (*ToolContext) Duration ¶ added in v0.1.4
func (tc *ToolContext) Duration() time.Duration
Duration returns the time elapsed since the tool started executing.
func (*ToolContext) Get ¶
func (tc *ToolContext) Get(key string) any
Get retrieves a value from the context by key. Returns nil if the key doesn't exist.
func (*ToolContext) GetBool ¶
func (tc *ToolContext) GetBool(key string) bool
GetBool retrieves a boolean value from the context by key. Returns false if the key doesn't exist or isn't a boolean.
func (*ToolContext) GetInt ¶
func (tc *ToolContext) GetInt(key string) int
GetInt retrieves an integer value from the context by key. Returns 0 if the key doesn't exist or isn't an integer.
func (*ToolContext) GetString ¶
func (tc *ToolContext) GetString(key string) string
GetString retrieves a string value from the context by key. Returns an empty string if the key doesn't exist or isn't a string.
func (*ToolContext) Has ¶
func (tc *ToolContext) Has(key string) bool
Has returns true if the context has a value for the given key.
func (*ToolContext) Set ¶
func (tc *ToolContext) Set(key string, value any)
Set stores a value in the context with the given key.
type ToolMiddleware ¶
type ToolMiddleware interface {
// Name returns a unique identifier for this middleware.
Name() string
// Before is called before the tool handler executes.
// It can modify the context or return an error to stop execution.
Before(ctx context.Context, tc *ToolContext) (context.Context, error)
// After is called after the tool handler executes (in reverse order).
// It can modify the result or handle errors.
After(ctx context.Context, tc *ToolContext, result *mcp.CallToolResult, handlerErr error) (*mcp.CallToolResult, error)
}
ToolMiddleware provides hooks for tool execution. Before is called before the handler, After is called after (in reverse order).
type ToolMiddlewareRegistry ¶
type ToolMiddlewareRegistry = MiddlewareChain
ToolMiddlewareRegistry manages a collection of middleware (alias for backward compatibility).
func NewToolMiddlewareRegistry ¶
func NewToolMiddlewareRegistry() *ToolMiddlewareRegistry
NewToolMiddlewareRegistry creates a new middleware registry.
type ToolName ¶ added in v0.1.4
type ToolName string
ToolName is a type-safe representation of S3 MCP tool names.
const ( // ToolListBuckets lists all accessible S3 buckets. ToolListBuckets ToolName = "s3_list_buckets" // ToolListObjects lists objects in a bucket with optional prefix/delimiter. ToolListObjects ToolName = "s3_list_objects" // ToolGetObject retrieves object content from S3. ToolGetObject ToolName = "s3_get_object" // ToolGetObjectMetadata retrieves object metadata without downloading content. ToolGetObjectMetadata ToolName = "s3_get_object_metadata" // ToolPutObject uploads an object to S3. ToolPutObject ToolName = "s3_put_object" // ToolDeleteObject deletes an object from S3. ToolDeleteObject ToolName = "s3_delete_object" // ToolCopyObject copies an object within or between buckets. ToolCopyObject ToolName = "s3_copy_object" // ToolPresignURL generates presigned URLs for GET or PUT operations. ToolPresignURL ToolName = "s3_presign_url" // ToolListConnections lists configured S3 connections. ToolListConnections ToolName = "s3_list_connections" )
Tool name constants for all S3 MCP tools.
func ReadTools ¶
func ReadTools() []ToolName
ReadTools returns a list of tool names that perform read operations.
func WriteTools ¶
func WriteTools() []ToolName
WriteTools returns a list of tool names that perform write operations.
type ToolOption ¶ added in v0.1.4
type ToolOption func(*toolConfig)
ToolOption configures a single tool registration.
func WithAnnotation ¶ added in v0.2.0
func WithAnnotation(ann *mcp.ToolAnnotations) ToolOption
WithAnnotation sets a per-registration annotation override for a single tool. This has the highest priority in the annotation resolution chain.
func WithDescription ¶ added in v0.2.0
func WithDescription(desc string) ToolOption
WithDescription sets a per-registration description override for a single tool. This has the highest priority in the description resolution chain.
func WithIcon ¶ added in v0.2.1
func WithIcon(icons []mcp.Icon) ToolOption
WithIcon sets a per-registration icon override for a single tool. This has the highest priority in the icon resolution chain.
func WithPerToolMiddleware ¶ added in v0.1.4
func WithPerToolMiddleware(m ...ToolMiddleware) ToolOption
WithPerToolMiddleware adds middleware specific to this tool registration.
type Toolkit ¶
type Toolkit struct {
// contains filtered or unexported fields
}
Toolkit provides a collection of S3 MCP tools with extensibility support.
func NewToolkit ¶
NewToolkit creates a new Toolkit with the given S3 client and options.
func (*Toolkit) GetClient ¶
GetClient returns the S3 client for the given connection name. If name is empty, returns the default connection.
func (*Toolkit) IsReadOnly ¶
IsReadOnly returns true if the toolkit is in read-only mode.
func (*Toolkit) ListConnections ¶
ListConnections returns a list of available connection names.
func (*Toolkit) MaxGetSize ¶
MaxGetSize returns the maximum size for object retrieval.
func (*Toolkit) MaxPutSize ¶
MaxPutSize returns the maximum size for object uploads.
func (*Toolkit) RegisterAll ¶ added in v0.1.4
RegisterAll adds all S3 tools to the given MCP server.
func (*Toolkit) RegisterTools ¶
RegisterTools registers all S3 tools with the MCP server (backward compatibility).
func (*Toolkit) RegisterWith ¶ added in v0.1.4
func (t *Toolkit) RegisterWith(server *mcp.Server, name ToolName, opts ...ToolOption)
RegisterWith adds a tool with per-registration options.
type TransformerChain ¶
type TransformerChain struct {
// contains filtered or unexported fields
}
TransformerChain manages a collection of result transformers.
func NewTransformerChain ¶
func NewTransformerChain() *TransformerChain
NewTransformerChain creates a new transformer chain.
func (*TransformerChain) Add ¶
func (c *TransformerChain) Add(t ResultTransformer)
Add adds a transformer to the chain.
func (*TransformerChain) All ¶
func (c *TransformerChain) All() []ResultTransformer
All returns all registered transformers.
func (*TransformerChain) Clear ¶
func (c *TransformerChain) Clear()
Clear removes all transformers from the chain.
func (*TransformerChain) Transform ¶
func (c *TransformerChain) Transform(ctx context.Context, tc *ToolContext, result *mcp.CallToolResult) (*mcp.CallToolResult, error)
Transform applies all transformers in order.