A document automation MCP server for AI-driven workflows using TX Text Control .NET Server.
The server exposes TX Text Control document generation, inspection, editing, template, form-field, table, image, section, header/footer, and export capabilities through stateless MCP HTTP transport. Working documents are stored in InternalUnicodeFormat and can be exported as DOCX, PDF, HTML, Markdown, or TX internal format.
- Create and manage document sessions
- Load documents from base64 (auto format detection, including markdown edge case)
- Export documents as base64 (
tx,docx,pdf,html,md) - Discover the complete AI authoring contract through
get_authoring_guide - Format text by:
- character range (
start,length) - paragraph index (
paragraphIndex)
- character range (
- AI-friendly document operation framework:
- neutral core document model (
Document,Section,Paragraph,Run,Table,Image,Style,HeaderFooter,Field) render_document_modelfor model-first document creationapply_operationsfor semantic incremental editing- external style presets, table style presets, and enabled operations
- first-class capability packs with operation metadata
- text, table, media, field, section, and header/footer operations
- TX-supported image insertion in body, headers, and footers
- template workflows with TX Text Control
MailMerge.MergeJsonData - capability and authoring-guide inspection before authoring
- neutral core document model (
- Admin UI:
- login-protected admin area
- enable/disable capability packs and operations
- edit style presets and table style presets
- inspect MCP endpoint information
- Content utilities:
- read paragraphs
- search by paragraph index
- search by exact ranges (
start,length) - extract full plain text
- Structured MCP tool error payloads
- .NET 10
- C#
- ASP.NET Core Minimal API
- Model Context Protocol (MCP) .NET SDK
- TX Text Control .NET Server
Program.cs- app bootstrap and MCP registrationTools/DocumentTools.cs- session/document lifecycle toolsTools/ContentTools.cs- content/query toolsTools/OperationTools.cs- AI-facing document operation toolsServices/Engines/ServerTextControlDocumentEngine.cs- TX Text Control engine entry pointServices/Engines/ServerTextControlDocumentEngine.Content.cs- content operationsServices/Engines/ServerTextControlDocumentEngine.Operations.cs- operation framework executionServices/Operations/- operation framework, grouped by capability packServices/AuthoringGuideService.cs- self-contained external AI authoring guideModels/DocumentModel/- neutral AI-facing document modelTests/- xUnit test project for framework and model behavior
- Health:
GET / - Admin:
GET /admin - Automation config JSON:
GET /admin/automation - MCP:
POST /mcp
Transport is configured as stateless HTTP.
create_document()load_from_base64(request, sessionId?)get_as_base64(request)get_session(sessionId)delete_session(sessionId)
format_text(sessionId, request)get_paragraphs(sessionId, start?, end?)search_text(sessionId, text?, matchCase?, wholeWord?)search_text_ranges(sessionId, text?, matchCase?, wholeWord?)get_text(sessionId)
get_document_automation_capabilities()get_authoring_guide()render_document_model(request)apply_operations(request)get_document_model(sessionId)get_document_structure(sessionId)get_document_styles(sessionId)get_document_tables(sessionId)get_document_fields(sessionId)get_document_headers_footers(sessionId)get_template_merge_fields(sessionId)get_template_merge_blocks(sessionId)get_template_form_fields(sessionId)merge_template(request)
External AI clients should call get_authoring_guide first. It returns recommended workflows, operation-specific schemas and examples, style/table preset definitions, valid value sets, document model guidance, recipes, best practices, and troubleshooting notes.
Use render_document_model for new model-first draft documents. The model-first path applies configured defaults automatically: document.title is rendered with the configured title role, unstyled paragraphs and headers/footers use the configured body role, and unstyled tables receive the first configured table style preset. It supports simple table cell styles and uniform whole-cell run styles, but clients must inspect warnings for rich content that was flattened or not rendered with full fidelity. Use apply_operations for precise incremental edits, table header/cell formatting, images, fields, merge blocks, form fields, sections, headers/footers, and targeted formatting.
Operation-first document creation also applies semantic defaults: the first unstyled body paragraph receives the configured title role, later unstyled paragraphs receive the configured body role, and append_table applies the first configured table style preset unless a table styleName is explicitly supplied.
Session continuity rule for external AI clients:
- If the user asks to change, modify, update, edit, adjust, make, increase, decrease, replace, or refers to the current/same/that/previous document, reuse the existing
sessionId. - Inspect the existing document first with tools such as
get_document_structure,get_document_tables, orget_document_model. - Do not create a new document/session unless the user explicitly asks for a new document.
Style omission policy for external AI clients:
- If the user prompt does not explicitly mention styling, fonts, colors, sizes, spacing, borders, alignment, or named styles/presets, omit all style-related properties.
- Do not invent
styleName,style,paragraphStyle,paragraph,cellStyle,tableStyleName, font, color, size, border, spacing, or alignment values. - Let the server apply configured defaults automatically.
- Send style information only when the user explicitly asks for it or names a configured style/preset.
- Always inspect
render_document_modelwarnings. If warnings mention table cell content, spans, mixed inline styles, fields, form fields, or images in cells, useapply_operationsfor exact output.
Capability packs are first-class modules represented by ICapabilityPack. A pack declares its name, AI-facing description, and supported operation types. Operation handlers still perform the work, but the registry uses pack metadata to expose enabled modules and reject disabled operations.
The BasicText capability pack includes:
define_styleappend_paragraphapply_style_to_paragraphformat_paragraphsformat_text_occurrencesreplace_text
The Media capability pack includes:
append_image
append_image accepts TX Text Control supported image formats: BMP, TIF/TIFF, WMF, PNG, JPG/JPEG, GIF, EMF, and SVG. Unsupported formats such as WebP are rejected with a structured tool error. Images can be supplied through imagePath, imageBase64, or a data:image/...;base64,... URI. TX runtime sizing uses horizontalScaling and verticalScaling; width and height are retained as neutral-model metadata only.
Use target to choose where the image is inserted. Supported values are body, header, footer, firstPageHeader, firstPageFooter, evenHeader, and evenFooter. The default is body.
The Tables capability pack includes:
append_tableset_table_cell_textformat_table_cellformat_table_header_rowformat_table_columnapply_table_style_presetadd_table_row
Table presets are configured in DocumentAutomation.TableStylePresets. User instructions override defaults, so an explicit request such as “make the table header pink” should be applied after the default table preset.
The Fields capability pack includes:
append_merge_fieldupdate_merge_fieldclear_application_fieldsappend_merge_blockappend_form_fieldupdate_form_fieldclear_form_fields
Form fields support text, selection/dropdown/combobox, checkbox, and date fields. Merge blocks are TX Text Control SubTextPart objects named txmb_<blockName>.
The Sections capability pack includes:
insert_section_breakset_section_layout
Set page size and margins before inserting wide tables because TX Text Control tables do not automatically adapt after page size changes.
The HeaderFooter capability pack includes:
set_header_footer
Build templates with the existing field operations, inspect the real TX Text Control ApplicationFields, then merge data through the TX Text Control MailMerge class:
- Create a template with
apply_operations.- Use
append_merge_fieldfor body fields. - Use
append_merge_fieldwithtableId,rowIndex, andcolumnIndexfor fields inside table cells. - Use
append_merge_blockto wrap a table row as a repeating merge block.
- Use
- Confirm template fields and blocks with
get_template_merge_fields(sessionId)andget_template_merge_blocks(sessionId).- This reads actual TX
MERGEFIELDApplicationFieldsfrom the document, not just the neutral model.
- This reads actual TX
- Merge data with
merge_template.- Provide either
request.jsonDataas a JSON string orrequest.dataas a JSON object/array. - The implementation uses
TXTextControl.DocumentServer.MailMerge.MergeJsonData.
- Provide either
- Export the merged result with
get_as_base64.
Example merge request:
{
"sessionId": "...",
"data": {
"CustomerName": "ACME Corp",
"InvoiceNumber": "INV-1001",
"lineItems": [
{
"ItemName": "TX Fuel",
"Description": "Document automation package",
"Quantity": "2",
"UnitPrice": "199.00",
"LineTotal": "398.00"
}
]
}
}- Create session
create_document,render_document_model, orapply_operationswithcreateIfMissing
- Optional: load content
load_from_base64
- Discover capabilities
get_authoring_guide
- Edit/query content
render_document_model,apply_operations,format_text,search_text,get_text, inspection tools, etc.
- Export
get_as_base64
- Cleanup
delete_session
dotnet build
dotnet run --urls http://localhost:5000Run tests:
dotnet test TxTextControl.McpServer.slnCreate a new document session:
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "create_document",
"arguments": {}
}
}Use the returned sessionId in subsequent tool calls.
format_text(sessionId, request) accepts:
start(int, optional)length(int, optional)paragraphIndex(int, optional)bold(bool)italic(bool)underline(bool)color_hex(string, optional, e.g.#FF0000)font_name(string, optional)font_size(float, optional, points)
Use either
start+lengthorparagraphIndex.
get_authoring_guide() is the safest starting point for external AI clients. The response includes:
recommendedWorkflowtoolMapdocumentModelContractoperationSchemasstyleRolesstylePresetstableStylePresetsstylePolicysessionPolicyvalueSetsrecipesbestPracticestroubleshooting
Create a document from a neutral model:
{
"createIfMissing": true,
"document": {
"styles": [
{
"name": "Title",
"type": "paragraph",
"text": {
"fontName": "Arial",
"fontSize": 30,
"fontSizeUnit": "pt",
"bold": true
}
}
],
"sections": [
{
"pageLayout": {
"pageSize": "Letter",
"orientation": "portrait",
"unit": "in",
"marginLeft": 1,
"marginRight": 1,
"marginTop": 1,
"marginBottom": 1
},
"blocks": [
{
"type": "paragraph",
"paragraph": {
"styleName": "Title",
"runs": [
{ "text": "Quarterly Report" }
]
}
}
]
}
]
}
}Create a styled document in one AI-friendly call:
{
"createIfMissing": true,
"operations": [
{
"type": "define_style",
"style": {
"name": "Heading",
"fontName": "Arial",
"fontSize": 20,
"fontSizeUnit": "px",
"bold": true
}
},
{
"type": "define_style",
"style": {
"name": "Paragraph-Text",
"fontName": "Arial",
"fontSize": 12,
"fontSizeUnit": "px",
"bold": false
}
},
{
"type": "append_paragraph",
"styleName": "Heading",
"text": "This is my title"
},
{
"type": "append_paragraph",
"styleName": "Paragraph-Text",
"text": "This is the paragraph text."
}
]
}The response includes the sessionId and per-operation results. Use get_as_base64 afterward to export the session as docx, pdf, html, md, or tx.
Create and style a table:
{
"createIfMissing": true,
"operations": [
{
"type": "set_section_layout",
"pageSize": "Letter",
"unit": "in",
"marginLeft": 1,
"marginRight": 1,
"marginTop": 1,
"marginBottom": 1
},
{
"type": "append_table",
"tableId": "10",
"rows": [
["Country", "Sales", "Qty"],
["Germany", "$842,000", "1280"],
["USA", "$1,240,000", "1985"]
]
},
{
"type": "apply_table_style_preset",
"tableId": "10",
"styleName": "Professional Blue"
},
{
"type": "format_table_header_row",
"tableId": "10",
"style": {
"bold": true,
"colorHex": "#FFFFFF"
},
"cellStyle": {
"backgroundColorHex": "#D0006F",
"border": {
"width": 10,
"colorHex": "#000000"
}
}
}
]
}Add a TX-supported image:
{
"sessionId": "...",
"operations": [
{
"type": "append_image",
"imagePath": "C:\\Images\\photo.png",
"altText": "Product photo",
"horizontalScaling": 75,
"verticalScaling": 75,
"alignment": "centered",
"insertionMode": "displaceText"
}
]
}Add an embedded base64/data URI image:
{
"sessionId": "...",
"operations": [
{
"type": "append_image",
"imageBase64": "data:image/png;base64,...",
"altText": "Embedded product photo",
"horizontalScaling": 50,
"verticalScaling": 50
}
]
}Insert a floating image at a page location:
{
"sessionId": "...",
"operations": [
{
"type": "append_image",
"imagePath": "C:\\Images\\watermark.png",
"pageNumber": 1,
"locationX": 25,
"locationY": 40,
"locationUnit": "mm",
"insertionMode": "belowText"
}
]
}Add a logo to a header:
{
"sessionId": "...",
"operations": [
{
"type": "set_header_footer",
"headerFooterType": "header",
"text": "Company Report "
},
{
"type": "append_image",
"target": "header",
"imagePath": "C:\\Images\\logo.png",
"altText": "Company logo",
"horizontalScaling": 40,
"verticalScaling": 40
}
]
}Use get_document_model(sessionId) to inspect the neutral document tree captured for the session. The model is intentionally independent from TX Text Control runtime classes so additional operation handlers can target a stable structure first and render through TX Text Control afterward.
appsettings.json contains a DocumentAutomation section:
EnabledCapabilityPackscontrols feature groups such asBasicText,Media,Tables,Fields,Sections, andHeaderFooter.EnabledOperationscontrols individual operation types.DefaultParagraphStyleNamedefines the fallback paragraph style.StyleRolesmaps semantic roles such as title, heading1, heading2, and body to configured style names.StylePresetsdefines reusable paragraph/text style names that AI clients can use without redefining them in every request.TableStylePresetsdefines default table header/body/alternating-row styles, cell backgrounds, and borders. Forrender_document_model, the first configured table preset is applied when a table has no explicitstyleName.
The /admin page exposes editable capability packs, operations, style presets, and table presets. The /admin/automation JSON endpoint exposes the currently configured automation surface.
- TX Text Control licensing is required for full runtime functionality.
- Errors from tools are returned as structured MCP payloads (
code,message,isError).
See repository license terms and TX Text Control licensing terms.