
Word
io.github.trsdn由 GitHub 账号 trsdn 发布v0.1.0更新于 Nov 3, 2026
Microsoft Word automation for AI assistants. Requires Word for Windows.
概览
通过 COM 自动化驱动 Windows 版 Microsoft Word,让助手打开、编辑、排版并导出真实的 Word 文档。
- 可以做什么
- 打开、新建、保存、关闭和列出文档会话,并检测本机能否自动化 Word
- 读取、追加、查找、替换和格式化文本;列出、添加、插入、删除段落并设置样式
- 列出、创建、读取和编辑表格、行与单元格;列出、插入、缩放、替换和删除内嵌图片
- 管理文档属性与统计、导出 PDF、另存为;插入和更新域、目录与页码
- 设置节、页边距、方向和纸张大小;读取、写入和清空页眉页脚
- 处理样式、项目符号与编号、批注、修订、书签、脚注尾注和内容控件,并把页面渲染为 PNG 截图
- 适用场景
- 适合需要在 Windows 桌面上处理真实 Word 文档的场景,例如撰写和排版报告、填写模板内容控件、审阅批注与修订,或通过渲染页面检查版式。它不是 .docx 解析器,只有安装了 Word 本体的机器才值得添加。
- 运行要求
- Windows 10/11,需安装桌面版 Microsoft Word 2016 或更新版本(Microsoft Store 版本无法自动化),并需要 .NET 9 SDK 或运行时。以本地 stdio 进程运行,可安装为 WordMcp.McpServer .NET 工具或通过 dnx 启动;未声明任何账号、API 密钥或环境变量。文档须先在 Word 中关闭,并使用绝对路径。可选设置 WORDMCP_SERVICE_MODE=daemon,把会话交给后台服务保存。
安装
在 SourceWeft 中
- 打开 控制台中的 Word,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
WordMcp — Microsoft Word MCP Server
An MCP server that lets AI assistants drive Microsoft Word for Windows through COM automation: open documents, read and edit text, manage paragraphs and tables, set document properties and export to PDF.
Windows only. A local installation of Microsoft Word is required — this server automates the real application, it does not parse
.docxfiles.
Requirements
Installation
VS Code
A thin extension in vscode-extension/ registers the server with VS Code, so
there is nothing to configure by hand. It does not bundle the server; it launches it through dnx,
which means the server updates without a new extension release.
Build and install it from a checkout:
Then run MCP: List Servers from the Command Palette and start Word.
As a .NET tool
The tool is then available as mcp-word.
To update or remove it later:
To run an unreleased build instead, pack it locally and install from the output folder:
Without installing
The server is listed in the MCP registry as io.github.trsdn/mcp-server-word. Clients that resolve packages themselves can run it through dnx, which fetches the version on demand instead of keeping a global tool around:
Client configuration
The server speaks stdio.
VS Code / GitHub Copilot
.vscode/mcp.json:
Claude Desktop
%APPDATA%\Claude\claude_desktop_config.json:
Copilot CLI
Concepts
Every operation runs inside a session. A session owns one Word instance and one open document, identified by a session_id such as word-a1b2c3d4e5f6g.
- Paths must be absolute (
C:\Users\me\Documents\report.docx). - Supported input formats:
.docx,.docm,.doc,.dotx,.dotm,.rtf. - The document must not be open in Word already — WordMcp needs exclusive access.
- Word runs invisibly in the background and is terminated when the session closes.
The session service
Sessions normally live inside the MCP server process and disappear with it. WordMcp.Service.exe
is an optional background daemon that holds them instead, so a session survives a restarted client
and can be shared by several of them:
Starting it by hand is rarely necessary — a client configured to use it starts it on demand. The pipe it listens on embeds your SID and is ACL'd to it, so sessions are never shared between accounts. It exits on its own once no session has been open for the idle timeout.
To use it, set WORDMCP_SERVICE_MODE=daemon for the MCP server. Every tool call then travels to
the daemon instead of running in the server's own process. Without it the server keeps sessions to
itself, which is what a single client wants: no second process and no startup wait.
Tools
Seventeen tools, each with an action parameter.
file — session lifecycle
text — content
Character positions come from get and find and are Word range offsets.
paragraph — structure
Paragraph indices are 1-based, matching Word.
table — tables
document — metadata and export
image — pictures
field — fields and tables of contents
section — sections and page setup
header-footer — headers and footers
kind selects header or footer, type selects primary, first-page or even-pages.
style — styles
style_type selects paragraph, character, table or list. Pass in_use_only: false to
list for the full set, which is over 370 entries on a localized Word.
list — bullets and numbering
Omitting end_index applies the action to start_index alone.
comment — review notes
add comments the whole paragraph unless anchor_text names a phrase inside it. Indexes shift
after delete, so list again before deleting a second comment.
revision — tracked changes
Omitting index on accept/reject handles the whole document, headers and footers included.
bookmark — stable references
Names must start with a letter and may only contain letters, digits and underscores. Bookmarks survive edits elsewhere in the document, which makes them the reliable way to refer back to a passage once paragraph indexes have shifted.
footnote — footnotes and endnotes
kind selects footnote (default) or endnote; the two are separate collections in Word with
independent numbering. This is the only way to reach footnote text at all — text(get) returns the
body story and never the notes.
content-control — template fields
Content controls are the structured fields a Word template exposes. Filling them is the reliable way
to complete a template — text(replace) on the surrounding text destroys the control and its
binding. tag is not unique and updates every match, which is what a template repeating a field
expects; id addresses exactly one control.
screenshot — see the page
Layout questions — page breaks, table widths, image placement, header positions — are far easier
to answer from the rendered page than from measurements. The PNG is written to a file and the path
returned; include_image: true additionally returns it inline as base64, which is only worth the
context when the image is going to be looked at.
dpi defaults to 150. Use 96 for a quick layout check and 300 for something close to print.
Responses
Every tool returns JSON. Failures are reported as structured payloads, never as a transport error:
Known behaviour and pitfalls
document(save-as)also saves the original. Word has no format-changing "save a copy" API. For any target other than PDF the server callsSaveAs2(target)and thenSaveAs2(original), which persists pending changes to the original file as a side effect. Useexport-pdfwhen you need a side-effect-free export.- Colours are hex RGB (
#0078D4). The server converts to the BGR value Word expects. - Rights-protected documents (IRM/AIP) are rejected before Word is launched.
- A document open in Word blocks the session — close it first.
- Word dialogs stall automation. If a call times out, check for an open dialog on the desktop.
- Style names are English. Built-in styles (
Heading 1,Title,Table Grid, …) are translated to Word's language-independent style ids, so they work on localized installations. Any other name is passed to Word as-is, which is how custom and localized styles are addressed. Note that Word reports styles under their localized name (Überschrift 1on a German install), which is whystyle(list)returns bothnameandenglish_name— sendenglish_nameback when it is present. - Built-in styles cannot be deleted.
style(delete)rejects them with a clear message instead of passing Word's generic COM error through. A custom style that is still applied to a paragraph cannot be deleted either; set those paragraphs to another style first. - New documents are written directly, not via Word.
file(create)writes an empty.docx/.docmpackage itself and then opens it. Creating documents through Word instead is unreliable on machines signed in to Microsoft 365, because AutoSave claims the new document for OneDrive and silently ignores the requested local path. - Merged table cells are returned as empty strings by
table(read). - Image sizes are in points, not pixels (72 pt = 1 inch).
image(insert)andimage(resize)keep the aspect ratio unlesslock_aspect_ratiois set tofalse, so passing onlywidthscales the height along with it. imageonly covers inline pictures. Floating shapes, text boxes and charts are left untouched and do not appear inimage(list), so their presence does not shift image indexes.- A table of contents only lists heading paragraphs.
field(insert-toc)returnsentry_count: 0for a document without heading styles — applyHeading 1/Heading 2viaparagraph(add|set-style)first, then runfield(update-toc). field(update-all)also walks headers and footers. Word'sDocument.Fieldscovers the body only, which is why page numbers would otherwise never refresh.image(insert)with a caption uses Word's caption numbering, so the caption readsFigure 1 <your text>(localized on non-English installations) and participates in a table of figures.- All measurements are in points, including page margins (1 cm = 28.35 pt, 1 inch = 72 pt).
section(page-setup)appliespaper_sizebefore the margins, because changing the paper size resets them in Word. Without asection_indexthe setup is applied to every section.- Headers and footers are inherited between sections. A new section shows the previous section's header until something is written to it.
header-footer(set)with asection_indexbreaks that link automatically, so section 1 keeps its own text. first-pageandeven-pagesheaders need a section switch.header-footer(set)turns onDifferentFirstPagerespectivelyDifferentOddEvenPagesfor you — without it Word stores the text but never renders it.list(apply)starts a new list by default.continue_previous_listis off, because picking up the numbering of an unrelated earlier list is rarely what was meant. Two numbered lists separated by plain paragraphs stay independent; uselist(restart)when Word merges them anyway.- Only outline-number lists render distinct levels.
list(set-level)works on any list, but a plainbulletornumberlist shows the same marker on every level — the paragraphs are merely indented. comment(resolve)often fails on Microsoft 365. Word's modern comments treat every comment added through the API as an unposted draft, and a draft cannot be marked as done. The server reports that as a clear message; delete the comment instead.comment(list)returnsresolved: nullon installations that do not expose the state at all.- Comment and revision indexes shift. Deleting a comment or accepting a single revision renumbers everything after it, so run
listagain between two such calls instead of reusing the old indexes. revision(accept|reject)without an index also walks headers and footers. Word'sDocument.AcceptAllRevisions()covers the body only, the same gap as withfield(update-all).- Tracked changes are recorded only while tracking is on.
revision(set-tracking)does not apply retroactively — turn it on before the edits you want recorded. - Bookmark names are restricted by Word. They must start with a letter, may contain only letters, digits and underscores, and are limited to 40 characters. Spaces, hyphens, dots and non-ASCII letters are rejected before the call reaches Word, which would otherwise fail with a generic COM error.
- Bookmarks are the stable way to refer to a passage. Paragraph indexes shift with every insertion, bookmarks do not. Bookmark a passage once and use
bookmark(get-text)to re-read it later. bookmark(add)on a paragraph excludes the paragraph mark, soget-textreturns the text without a trailing newline. A bookmark over several paragraphs keeps the marks in between.text(get)never returns footnotes. Footnotes and endnotes live in their own Word story, so a document that carries its sources in notes looks complete while a part of its content is missing. Callfootnote(list)before summarizing or translating anything.- Deleting a note renumbers the rest.
footnote(delete)shifts every following index down, the same trap as with comments and revisions. When removing several notes, work from the highest index downwards. - Footnotes and endnotes are separate collections. They have independent numbering, and every
footnoteaction defaults to footnotes — passkind: "endnote"explicitly. - Filling a template means
content-control(set-text), nottext(replace). Replacing the text around a content control destroys the control and its data binding; writing through the control keeps both. - Content control tags are not unique.
content-control(set-text)bytagupdates every match and reports how many, because a template that shows the customer name in the header and again in the signature block relies on exactly that. Useidwhen precisely one control is meant. content-control(delete)keeps the text by default. Onlydelete_contents: trueremoves the content along with the control. Controls locked against deletion are reported instead of silently skipped.screenshot(page)renders through a PDF. Word has no API that returns a page as an image, so the server exports the single page withExportAsFixedFormatand rasterizes it. Unsaved changes are included, and the temporary PDF is deleted afterwards.- Page numbers come from a fresh repagination. A document that was only ever edited through automation reports a stale page count, so
screenshotrepaginates first. That also means the page count reflects the current layout, not the one at open time.
Building from source
Project layout
Generated tool layer
Fourteen of the fifteen tools are generated at build time. The command interfaces in
src/WordMcp.Core/Commands are the single source of truth for the wire contract:
[ServiceCategory("section", "Section")]names the tool class,WordSectionTool.[McpTool("section", Title = ..., Description = ...)]supplies the tool name and the prompt the model reads.[ServiceAction("page-setup")]on each method becomes a value of the generatedWordSectionActionenum.- XML documentation on the interface parameters becomes the parameter descriptions in the MCP schema.
The generator merges the parameters of all actions into one method, so a parameter used by only
some actions is emitted as optional. To change the API, edit the interface — never the generated
code. file stays hand-written because it manages sessions rather than operating on one.
Inspect the emitted code under src/WordMcp.McpServer/obj/generated. The tests in
GeneratedToolContractTests compare the generated surface against the interfaces, so a mismatch
fails the build rather than reaching a client.
Tests that need a real Word installation are marked [Trait("Category", "RequiresWord")] and are excluded in CI. Failed integration runs can leave orphaned WINWORD.EXE processes behind, which slow down or block later runs — clean them up with Get-Process WINWORD | Stop-Process -Force before re-running.
Further reading
Troubleshooting
Contributing
Bug reports and feature requests go through the issue templates. Pull requests are welcome; CONTRIBUTING.md covers how to build, how to run the two halves of the test suite, and what it takes to add a tool.
Please read the Code of Conduct first.
Do not file a public issue for a security problem — report it privately as described in the security policy.
License
MIT — see LICENSE.
来源:README.md,提交 7a59a17
工具
0版本历史
1- v0.1.0最新Sep 16, 2026
评分
已满足适用检查项的 50%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分