feat: attach material files over MCP as base64
- storeMaterialFile: the one attach.Store call of the management API,
shared by the multipart route and the new inline route
- POST /api/v1/bm/materials/{id}/files/inline: JSON {name, mime?,
content_base64}, at most 3000000 bytes decoded, body.limit 4300000
- bm_manage_attach_material_file and bm_manage_detach_material_file,
both warning that material files are public to anyone with the link
This commit is contained in:
42
mcp_files.go
Normal file
42
mcp_files.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package bm
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"git.golem15.com/golem15/summercms/modules/pact"
|
||||
"git.golem15.com/jakub/sm-bm-plugin/controllers/api"
|
||||
)
|
||||
|
||||
// attachMaterialFileInput is the input of bm_manage_attach_material_file.
|
||||
type attachMaterialFileInput struct {
|
||||
ID uint `json:"id" path:"id" jsonschema:"the material id"`
|
||||
Name string `json:"name" jsonschema:"file name with extension, for example notatki.pdf"`
|
||||
Mime string `json:"mime,omitempty" jsonschema:"optional MIME type; the stored type must match"`
|
||||
ContentBase64 string `json:"content_base64" jsonschema:"standard base64, at most 3000000 bytes decoded; use bm_manage_create_material_upload for larger files"`
|
||||
}
|
||||
|
||||
// detachMaterialFileInput is the input of bm_manage_detach_material_file.
|
||||
type detachMaterialFileInput struct {
|
||||
ID uint `json:"id" path:"id" jsonschema:"the material id"`
|
||||
File uint `json:"file" path:"file" jsonschema:"the file id, as listed in the files of bm_manage_show_material"`
|
||||
}
|
||||
|
||||
// fileTools are the material file tools over the management API (D-10,
|
||||
// D-11, D-17): attach a small file as base64 and detach a file. Every
|
||||
// description carries the public-file warning and says no file contents
|
||||
// are returned.
|
||||
func fileTools() []pact.MCPTool {
|
||||
tool := func(name, title, desc, method, path string, input any) pact.MCPTool {
|
||||
return pact.MCPTool{Name: name, Title: title, Description: desc, Guard: "user", Method: method, Path: ManagePrefix + path, Input: input}
|
||||
}
|
||||
return []pact.MCPTool{
|
||||
tool("manage_attach_material_file", "Attach a file to a material",
|
||||
"Attaches one file sent as standard base64 (at most 3000000 bytes decoded; for larger files use bm_manage_create_material_upload) to a material, after its files; a material holds at most 20. The extension and the content are checked; a sent mime must match the content. Returns the material with its files (id, absolute link, name, size and type) and a warning; 404 when the material is unknown, 422 when the file is refused. "+
|
||||
api.MaterialFileWarning+" "+MCPMaterialPrivacy+writeMaterials,
|
||||
http.MethodPost, "/materials/{id}/files/inline", attachMaterialFileInput{}),
|
||||
tool("manage_detach_material_file", "Detach a file from a material",
|
||||
"Deletes one file of a material, its row and its stored blob, so its link stops working; 404 when the material or the file is unknown or the file belongs to another material."+deleteForever+" "+
|
||||
api.MaterialFileWarning+" "+MCPMaterialPrivacy+writeMaterials,
|
||||
http.MethodDelete, "/materials/{id}/files/{file}", detachMaterialFileInput{}),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user