letterwriter-mcp

letterwriter-mcp

Generates DOCX letters on your organization's letterhead via MCP, returning the document as an attachment. Supports custom letterhead templates and an office registry for multi-office organizations.

Category
访问服务器

README

letterwriter-mcp

An MCP server that generates DOCX letters on your organization's own letterhead and returns the document as an attachment.

Point an AI assistant at it and "write Ms. Okonkwo a closing letter for her Riverside case" produces a correctly branded Word document, signed by the right office, that someone can review and send.

It speaks MCP over streamable HTTP, so it works with LibreChat, Claude Desktop, or anything else that speaks the protocol. It is useful to any organization that sends letters on headed paper — legal aid, clinics, nonprofits — and knows nothing about the deployment it came from.

Tools

Tool Does
create_letter Renders a letter and returns the .docx itself
list_letterheads Lists the letterhead IDs and labels available

create_letter returns the document as MCP binary content — an embedded resource carrying the bytes — rather than a download link. There is no object storage here, no credentials to leak, and no URL that expires and turns a letter from last month into a dead link.

Your letterheads never live in this repository

This repository ships one template: a 1.3 KB placeholder that says [ YOUR LETTERHEAD ARTWORK GOES HERE ]. Your own letterheads stay outside it.

At runtime the server reads a registry — a letterheads.json describing your offices — and the .docx files it names:

${LETTERHEAD_DIR}/            # default /data/letterheads
├── letterheads.json
├── baltimore-city.docx
├── montgomery-county.docx
└── ...

If ${LETTERHEAD_DIR}/letterheads.json exists, that registry and those templates are used. If it does not, the server falls back to the copy committed here, so a fresh install starts and can produce a letter before anyone has uploaded anything.

/healthz reports which one is in force:

{"ok":true,"service":"letterwriter-mcp","version":"1.0.0",
 "letterheads":{"count":13,"default":"generic",
                "registry":"/data/letterheads/letterheads.json",
                "using_bundled_registry":false}}

Check using_bundled_registry first when every letter comes out on the wrong letterhead. A LETTERHEAD_DIR that is empty or never mounted leaves the placeholder in charge, and everything else looks perfectly healthy.

The registry

{
  "defaultId": "generic",
  "stopWords": ["office", "example legal aid"],
  "letterheads": [
    {
      "id": "riverside",
      "label": "Riverside",
      "file": "riverside.docx",
      "aliases": ["riverside", "riverside branch", "north county"],
      "legalserver_offices": ["Riverside Branch"],
      "include_unit_name": true
    }
  ]
}
Field Means
id Stable machine name; what letterhead_id accepts
label Human name, shown by list_letterheads
file A bare filename in the same directory as the registry
aliases Free-text spellings an assistant might be handed for this office
legalserver_offices Exact office names as LegalServer spells them, if you use it
include_unit_name When true, a unit_name argument is added to this office's signature block
defaultId Which letterhead to use when nothing matches
stopWords Words ignored when matching. Add your organization's own name, so "Example Legal Aid — Riverside Office" matches riverside.

The whole registry is validated at startup and every problem is reported at once — a missing .docx, a duplicate id, a defaultId matching nothing. Finding those one letter at a time, in production, while someone waits to send mail to a client, is the experience this avoids.

Matching prefers the longest alias, so riverside suite 300 beats riverside rather than depending on the order of the file.

Making a template

Copy templates/letterheads/generic.docx, put your artwork in it, and keep the placeholders. They are docxtemplater tags:

{today} {client_name} {address1} {address2} {honorific} {client_last_name} {message_body} {attorney} {signature_lines}

{signature_lines} is filled with your organization name, the office name, and — for offices setting include_unit_name — the unit.

Running it

docker run -d --name letterwriter-mcp \
  -e ORGANIZATION_NAME="Example Legal Aid" \
  -e MCP_ALLOWED_HOSTS=letterwriter-mcp,localhost,127.0.0.1 \
  -v /srv/letterheads:/data/letterheads:ro \
  -p 127.0.0.1:3002:3002 \
  ghcr.io/marylandlegalaid/letterwriter-mcp:v1.1.0
Variable Default Means
ORGANIZATION_NAME Your Organization First line of every signature block. Set this.
LETTERHEAD_DIR /data/letterheads Your registry and templates
MCP_HTTP_HOST 127.0.0.1 0.0.0.0 in a container
MCP_HTTP_PORT 3002
MCP_ALLOWED_HOSTS unset See below
MCP_SHARED_SECRET unset Optional shared-secret header; no-ops when unset
LETTER_OUTPUT_DIR unset Where finished letters are written. Set with the next one or neither
LETTER_PUBLIC_BASE_URL unset Absolute URL prefix serving that directory
LETTERHEAD_REGISTRY_PATH — Override just the registry path
LETTERHEAD_TEMPLATES_DIR — Override just the template directory

How the document comes back

Two modes, chosen by whether LETTER_OUTPUT_DIR and LETTER_PUBLIC_BASE_URL are set.

Unset (default) — embedded bytes. create_letter returns the .docx as an MCP embedded resource with a base64 blob. This is what the MCP specification provides for and needs no storage.

Both set — a download URL. The letter is written to ${LETTER_OUTPUT_DIR}/<random-token>/<filename>.docx and the tool returns an absolute URL. Setting only one is a startup error: an output directory with no URL writes files nobody can reach, and a URL with no directory advertises files that were never written. Both are invisible until someone clicks a link, so they are refused up front.

!!! warning "LibreChat users: you need URL mode" LibreChat v0.8.7 does not read blob. Its MCP tool-result handler has cases for text, image and resource, and the resource case reads only ui:// URIs, text, uri and mimeType. The bytes are dropped, and the model is handed a description of a file it cannot give anyone — typically producing a plausible-looking link to file:///…, which a browser resolves against the current page. Configure URL mode.

The URL is a capability: whoever has it can fetch the document, with no further authentication. The token is 24 CSPRNG bytes, base64url-encoded, so it is not guessable. Note that in the LibreChat case the letter's text is already in the conversation that produced it, so the file exposes nothing that conversation does not.

Links do not expire, deliberately — an expiring link makes a letter written three weeks ago look like data loss. Retention is the deployment's business; the directory is ordinary files on disk and can be pruned by age if it ever needs to be.

MCP_ALLOWED_HOSTS will bite you. The MCP SDK rejects requests whose Host header it does not recognize. Behind Docker Compose the caller sends the service name, so that name has to be in this list or every request is refused. Symptom: the server is healthy, the client reports a connection error, and nothing obviously connects the two.

With LibreChat

mcpSettings:
  allowedAddresses:
    - "letterwriter-mcp:3002"      # LibreChat blocks internal hostnames without this

mcpServers:
  LetterWriter:
    type: streamable-http
    url: http://letterwriter-mcp:3002/letter-writer/mcp
    description: "Create DOCX letters on organization letterhead"
    chatMenu: true

allowedAddresses is not optional. LibreChat treats a Docker service name as an SSRF target and refuses every connection without it, reporting Domain ... is not allowed.

A worked deployment — Compose service, storage, backups — is in MarylandLegalAid/librechat-azure.

Trust boundary

This server has no authentication by default, on purpose. It is built to run on a private container network reachable only by the application that calls it, and that network is the boundary.

Set MCP_SHARED_SECRET if you ever put it anywhere else. Note also that it renders whatever text it is given onto your letterhead: whoever can reach it can produce a document that looks official.

Development

npm install
npm test            # 29 tests, no network, no fixtures on disk
npm start

License

MIT — see LICENSE. No warranty; see the license text.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选