-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
119 lines (108 loc) · 5.89 KB
/
Copy pathProgram.cs
File metadata and controls
119 lines (108 loc) · 5.89 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
using System;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
using TxTextControl.McpServer.Services;
using TxTextControl.McpServer.Options;
using TxTextControl.McpServer.Services.Admin;
using TxTextControl.McpServer.Services.Operations;
using TxTextControl.McpServer.Tools;
var builder = WebApplication.CreateBuilder(args);
builder.Services
.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(options =>
{
options.Cookie.Name = "TxMcpAdmin";
options.LoginPath = "/admin/login";
options.LogoutPath = "/admin/logout";
options.SlidingExpiration = true;
});
builder.Services.AddAuthorization();
builder.Services.AddRazorPages(options =>
{
options.Conventions.AuthorizeFolder("/Admin");
options.Conventions.AllowAnonymousToPage("/Admin/Login");
});
// Use fully qualified names to avoid ambiguity with ModelContextProtocol.Server.McpServerOptions
builder.Services.Configure<TxTextControl.McpServer.Options.McpServerOptions>(
builder.Configuration.GetSection(TxTextControl.McpServer.Options.McpServerOptions.SectionName));
builder.Services.Configure<AdminOptions>(
builder.Configuration.GetSection(AdminOptions.SectionName));
builder.Services.Configure<DocumentAutomationOptions>(
builder.Configuration.GetSection(DocumentAutomationOptions.SectionName));
// Core services for simplified implementation
builder.Services.AddSingleton<TxTextControl.McpServer.Services.PathResolver>();
builder.Services.AddSingleton<DocumentSessionService>();
builder.Services.AddSingleton<ICapabilityPack, BasicTextCapabilityPack>();
builder.Services.AddSingleton<ICapabilityPack, MediaCapabilityPack>();
builder.Services.AddSingleton<ICapabilityPack, TableCapabilityPack>();
builder.Services.AddSingleton<ICapabilityPack, FieldsCapabilityPack>();
builder.Services.AddSingleton<ICapabilityPack, SectionCapabilityPack>();
builder.Services.AddSingleton<ICapabilityPack, HeaderFooterCapabilityPack>();
builder.Services.AddSingleton<IDocumentOperationHandler, DefineStyleOperationHandler>();
builder.Services.AddSingleton<IDocumentOperationHandler, AppendParagraphOperationHandler>();
builder.Services.AddSingleton<IDocumentOperationHandler, ApplyStyleToParagraphOperationHandler>();
builder.Services.AddSingleton<IDocumentOperationHandler, FormatParagraphsOperationHandler>();
builder.Services.AddSingleton<IDocumentOperationHandler, FormatTextOccurrencesOperationHandler>();
builder.Services.AddSingleton<IDocumentOperationHandler, ReplaceTextOperationHandler>();
builder.Services.AddSingleton<IDocumentOperationHandler, AppendImageOperationHandler>();
builder.Services.AddSingleton<IDocumentOperationHandler, AppendTableOperationHandler>();
builder.Services.AddSingleton<IDocumentOperationHandler, SetTableCellTextOperationHandler>();
builder.Services.AddSingleton<IDocumentOperationHandler, FormatTableCellOperationHandler>();
builder.Services.AddSingleton<IDocumentOperationHandler, FormatTableHeaderRowOperationHandler>();
builder.Services.AddSingleton<IDocumentOperationHandler, FormatTableColumnOperationHandler>();
builder.Services.AddSingleton<IDocumentOperationHandler, ApplyTableStylePresetOperationHandler>();
builder.Services.AddSingleton<IDocumentOperationHandler, AddTableRowOperationHandler>();
builder.Services.AddSingleton<IDocumentOperationHandler, AppendMergeFieldOperationHandler>();
builder.Services.AddSingleton<IDocumentOperationHandler, UpdateMergeFieldOperationHandler>();
builder.Services.AddSingleton<IDocumentOperationHandler, ClearApplicationFieldsOperationHandler>();
builder.Services.AddSingleton<IDocumentOperationHandler, AppendMergeBlockOperationHandler>();
builder.Services.AddSingleton<IDocumentOperationHandler, AppendFormFieldOperationHandler>();
builder.Services.AddSingleton<IDocumentOperationHandler, UpdateFormFieldOperationHandler>();
builder.Services.AddSingleton<IDocumentOperationHandler, ClearFormFieldsOperationHandler>();
builder.Services.AddSingleton<IDocumentOperationHandler, InsertSectionBreakOperationHandler>();
builder.Services.AddSingleton<IDocumentOperationHandler, SetSectionLayoutOperationHandler>();
builder.Services.AddSingleton<IDocumentOperationHandler, SetHeaderFooterOperationHandler>();
builder.Services.AddSingleton<DocumentOperationRegistry>();
builder.Services.AddSingleton<AutomationSettingsService>();
builder.Services.AddSingleton<SupportedFontService>();
builder.Services.AddSingleton<AuthoringGuideService>();
builder.Services.AddSingleton<ITxDocumentEngine, ServerTextControlDocumentEngine>();
builder.Services.AddSingleton<DocumentWorkflowService>();
builder.Services.AddHostedService<FileCleanupService>();
// MCP Server tools split by responsibility
builder.Services
.AddMcpServer()
.WithHttpTransport(options =>
{
// Recommended for servers that don't need server-to-client requests.
options.Stateless = true;
})
.WithTools<DocumentTools>()
.WithTools<ContentTools>()
.WithTools<OperationTools>();
var app = builder.Build();
app.UseStaticFiles();
app.UseAuthentication();
app.UseAuthorization();
app.MapGet("/admin/automation", (
IOptions<DocumentAutomationOptions> options,
AutomationSettingsService settings,
DocumentOperationRegistry registry) => Results.Ok(new
{
capabilityPacks = registry.GetCapabilityPacks(),
enabledCapabilityPacks = settings.GetEnabledCapabilityPacks(),
enabledOperations = settings.GetEnabledOperations(),
operations = registry.GetCapabilities(),
defaultParagraphStyleName = options.Value.DefaultParagraphStyleName,
styleRoles = options.Value.StyleRoles,
stylePresets = options.Value.StylePresets,
tableStylePresets = options.Value.TableStylePresets
})).RequireAuthorization();
app.MapRazorPages();
app.MapMcp("/mcp");
app.Run();
public partial class Program;