-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDocumentTools.cs
More file actions
102 lines (94 loc) · 3.61 KB
/
Copy pathDocumentTools.cs
File metadata and controls
102 lines (94 loc) · 3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using System;
using ModelContextProtocol.Server;
using System.ComponentModel;
using TxTextControl.McpServer.Models.Requests;
using TxTextControl.McpServer.Services;
namespace TxTextControl.McpServer.Tools;
/// <summary>
/// Document/session lifecycle tools for the MCP server.
/// </summary>
[McpServerToolType]
public sealed class DocumentTools
{
private readonly DocumentWorkflowService _workflow;
public DocumentTools(DocumentWorkflowService workflow)
{
_workflow = workflow;
}
/// <summary>
/// Create a new, empty document session.
/// </summary>
[McpServerTool, Description("Creates a new document session and initializes an empty document in TX internal format. Returns a generated sessionId that must be used in subsequent tools (for example format_text, get_text, search_text, get_as_base64, and delete_session). Use this as the starting point when you do not already have document content to load.")]
public object CreateDocument()
{
try
{
return _workflow.CreateDocument();
}
catch (Exception ex)
{
return ToolErrorMapper.Map(ex);
}
}
/// <summary>
/// Load base64 document content into a session.
/// </summary>
[McpServerTool, Description("Loads a base64-encoded document into a session. If sessionId is provided, the existing session document is overwritten. If sessionId is omitted, a new session is created automatically. Request body must provide request.data (base64 content). Returns the target sessionId to continue with content tools.")]
public object LoadFromBase64(LoadFromBase64Request request, string? sessionId = null)
{
try
{
return _workflow.LoadFromBase64(request, sessionId);
}
catch (Exception ex)
{
return ToolErrorMapper.Map(ex);
}
}
/// <summary>
/// Export a session document as base64 in a requested output format.
/// </summary>
[McpServerTool, Description("Exports the current session document as base64. Required fields: request.sessionId and request.format. Supported formats: tx, docx, pdf, html, md. Returns sessionId, normalized format, and base64Document. Use this tool as the final step when the caller needs downloadable file data.")]
public object GetAsBase64(GetAsBase64Request request)
{
try
{
return _workflow.GetAsBase64(request);
}
catch (Exception ex)
{
return ToolErrorMapper.Map(ex);
}
}
/// <summary>
/// Get basic session information.
/// </summary>
[McpServerTool, Description("Validates that a session exists and returns its sessionId. Useful for guard checks before content operations. If the session does not exist, a not_found error is returned.")]
public object GetSession(string sessionId)
{
try
{
return _workflow.GetSession(sessionId);
}
catch (Exception ex)
{
return ToolErrorMapper.Map(ex);
}
}
/// <summary>
/// Delete a session and all associated files.
/// </summary>
[McpServerTool, Description("Deletes a session and removes all related session files from disk. Input: sessionId. Returns { deleted, sessionId } where deleted indicates whether a session directory was removed.")]
public object DeleteSession(string sessionId)
{
try
{
var deleted = _workflow.DeleteSession(sessionId);
return new { deleted, sessionId };
}
catch (Exception ex)
{
return ToolErrorMapper.Map(ex);
}
}
}