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 session's file-download policy and the user's channel permissions itself.
Index ¶
Constants ¶
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 ¶
var ErrForbidden = errors.New("you do not have permission to access this file")
ErrForbidden is returned when the requesting session is denied the file or the 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.
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 (*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 the requesting session's file policy and the user's channel permission. Documents use the server-extracted text; plain text files fall back to the raw bytes.