MCP takes markdown input for document version content
Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
@@ -18,11 +18,14 @@ package mcp_v1
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"go.gearno.de/kit/log"
|
||||
"go.probo.inc/probo/pkg/gid"
|
||||
"go.probo.inc/probo/pkg/iam"
|
||||
"go.probo.inc/probo/pkg/probo"
|
||||
"go.probo.inc/probo/pkg/prosemirror"
|
||||
"go.probo.inc/probo/pkg/server/api/authn"
|
||||
)
|
||||
|
||||
@@ -32,6 +35,20 @@ type Resolver struct {
|
||||
logger *log.Logger
|
||||
}
|
||||
|
||||
func markdownToProseMirrorJSON(markdown string) (string, error) {
|
||||
node, err := prosemirror.ParseMarkdown(markdown)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("cannot parse markdown: %w", err)
|
||||
}
|
||||
|
||||
out, err := json.Marshal(node)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("cannot marshal prosemirror node: %w", err)
|
||||
}
|
||||
|
||||
return string(out), nil
|
||||
}
|
||||
|
||||
func (r *Resolver) MustAuthorize(ctx context.Context, entityID gid.GID, action iam.Action) {
|
||||
identity := authn.IdentityFromContext(ctx)
|
||||
|
||||
|
||||
@@ -2170,6 +2170,24 @@ func (r *Resolver) CreateDraftDocumentVersionTool(ctx context.Context, req *mcp.
|
||||
panic(fmt.Errorf("cannot create draft document version: %w", err))
|
||||
}
|
||||
|
||||
if input.Content != nil {
|
||||
content, err := markdownToProseMirrorJSON(*input.Content)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot convert markdown to prosemirror: %w", err))
|
||||
}
|
||||
|
||||
draftVersion, err = svc.Documents.UpdateVersion(
|
||||
ctx,
|
||||
probo.UpdateDocumentVersionRequest{
|
||||
ID: draftVersion.ID,
|
||||
Content: &content,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot update draft document version content: %w", err))
|
||||
}
|
||||
}
|
||||
|
||||
return nil, types.CreateDraftDocumentVersionOutput{
|
||||
DocumentVersion: types.NewDocumentVersion(draftVersion),
|
||||
}, nil
|
||||
@@ -2180,11 +2198,20 @@ func (r *Resolver) UpdateDocumentVersionTool(ctx context.Context, req *mcp.CallT
|
||||
|
||||
svc := r.ProboService(ctx, input.DocumentVersionID)
|
||||
|
||||
var content *string
|
||||
if input.Content != nil {
|
||||
c, err := markdownToProseMirrorJSON(*input.Content)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot convert markdown to prosemirror: %w", err))
|
||||
}
|
||||
content = &c
|
||||
}
|
||||
|
||||
documentVersion, err := svc.Documents.UpdateVersion(
|
||||
ctx,
|
||||
probo.UpdateDocumentVersionRequest{
|
||||
ID: input.DocumentVersionID,
|
||||
Content: input.Content,
|
||||
Content: content,
|
||||
Classification: input.Classification,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -5565,6 +5565,9 @@ components:
|
||||
document_id:
|
||||
$ref: "#/components/schemas/GID"
|
||||
description: Document ID
|
||||
content:
|
||||
type: string
|
||||
description: Document content in markdown format
|
||||
|
||||
CreateDraftDocumentVersionOutput:
|
||||
type: object
|
||||
@@ -5584,7 +5587,7 @@ components:
|
||||
description: Document version ID
|
||||
content:
|
||||
type: string
|
||||
description: Document content
|
||||
description: Document content in markdown format
|
||||
classification:
|
||||
$ref: "#/components/schemas/DocumentClassification"
|
||||
description: Document classification
|
||||
|
||||
Reference in New Issue
Block a user