files

package
v2.5.1 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package files serves the text contents of Mattermost file attachments to the LLM on demand. It exists because the server-extracted text (FileInfo.Content, used for PDFs and Office documents) is tagged json:"-" and is never returned over the REST API, so the MCP server's user-scoped client cannot read it. This service reaches that content through the admin plugin API and therefore must enforce the requesting user's channel permissions itself.

Index

Constants

View Source
const (
	// DefaultReadRunes is the window size returned when a caller omits a limit.
	DefaultReadRunes = 6000
	// MaxReadRunes caps a single read so one tool call cannot re-blow the
	// context window the lazy-loading design is meant to protect.
	MaxReadRunes = 20000
)

Variables

View Source
var ErrForbidden = errors.New("you do not have permission to access this file")

ErrForbidden is returned when the requesting user lacks permission to read the file's channel. Callers map it to a 403 / access-denied tool result.

Functions

This section is empty.

Types

type Content

type Content struct {
	Name       string
	MimeType   string
	TotalRunes int
	Offset     int
	Returned   int
	HasMore    bool
	HasText    bool // false means the file has no extractable text (e.g. a binary with no server-side extraction)
	Text       string
}

Content is a ranged slice of a file's text plus the metadata needed to page through the rest of it. Offsets are measured in runes, not bytes, so a multi-byte character is never split across reads.

func Slice

func Slice(name, mimeType, text string, offset, limit int) Content

Slice returns the [offset, offset+limit) rune window of text as a Content, applying the default and maximum read sizes. Offsets are measured in runes so a multibyte character is never split, and they are clamped into range.

type Service

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

Service is the shared plugin-side file reader behind both the embedded read_file tool and the /files/content HTTP endpoint.

func New

func New(mm mmapi.Client) *Service

New creates a file content service backed by the given Mattermost client.

func (*Service) GetContent

func (s *Service) GetContent(ctx context.Context, userID, fileID string, offset, limit int) (Content, error)

GetContent returns the [offset, offset+limit) rune window of a file's text for userID, after verifying that user may read the file's channel. Documents use the server-extracted text; plain text files fall back to the raw bytes.

Jump to

Keyboard shortcuts

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