Skip to content
James Ross
articlePublished Updated 8 min read

Small internal MCP servers that pay for themselves

By James Ross

An internal MCP server pays for itself when it wraps a multi-step task an agent already does by hand: find the receipts, parse them, render the PDFs, write the filenames back into the spreadsheet. Two examples: a four-tool image generation server and a six-tool receipts reconciliation server that reads a mailbox over IMAP.

A compact server module chaining receipts, a parser and a PDF printer into one workflow, showing an internal MCP server.

Both are small. Neither has users outside the business, a billing system or an OAuth server. They are the smallest useful shape of an MCP server: one job, a handful of tools, and no reason to be a platform. The hosting and auth decisions are covered in building a remote MCP server with OAuth 2.1; internal tools usually skip most of that.

When an internal tool deserves MCP

Most internal scripts do not need MCP. A cron job that exports a CSV should stay a cron job. The protocol earns its overhead when four conditions hold at once.

  • The task is multi-step and varies. Fetch, parse, render, match, write back. A fixed pipeline is a script; a task where the next step depends on what was found is a tool.
  • The caller is an agent. If a person runs it, a CLI with good flags is cheaper. If an assistant has to decide which receipt to fetch or which images to regenerate, a typed tool is the interface it can use.
  • The credentials already exist. The server wraps access the business already has, rather than creating a new integration.
  • The output is a file or a record. An image on disk, a PDF next to a spreadsheet row. Something the caller can point at afterwards.
Shape Best for Cost to maintain
Shell script One fixed pipeline, one operator Low
CLI with flags A person choosing options Low
Internal MCP server An agent choosing steps, repeatedly Medium
Hosted MCP server Multiple users or clients High

Which should you choose? Start with a CLI. If the same CLI keeps being driven by an assistant through shell commands and the argument quoting becomes the hard part, wrap it as a stdio MCP server. Move to a hosted server only when someone other than the builder needs to reach it.

Image generation: four tools and a free diagnostic

The image server wraps a compatible image API. It has no browser, no queue and no database. The whole surface is four tools, and the most important one spends nothing.

check_image_api reports the resolved endpoint, model, output directory and credential source. It does not print the key and it does not make a billed request. That single tool prevents the most common failure in this class: a generation call that fails after spending money because an environment variable was missing or pointed at the wrong host.

generate_image takes a prompt, a size and a prefix, generates one to four images, returns them to the client and saves local copies. The saved copies are what makes the output usable in a real workflow; an inline image in a chat transcript is not a file a site build can reference.

edit_image edits one or more local files, optionally with a mask. It accepts PNG, JPEG and WebP, and it can read the paths it is given.

show_image redisplays a saved output without another API request. That sounds trivial and is not. Regenerating an image to look at it again is the most expensive way to check your work.

Three design choices make the server portable across clients:

  • Credential names in priority order. The server accepts a neutral name first, then two vendor-specific names. The neutral name is recommended because it makes the server’s purpose explicit and does not change the environment of unrelated tools that read the same variable.
  • A tokenized loopback preview. Some MCP clients do not render image blocks. For those, the server starts a loopback preview on 127.0.0.1, restricted to files in the output directory, and returns copy-ready Markdown. The preview lives only while the server process runs.
  • Output paths that cannot escape. The filename prefix is sanitised and cannot select an arbitrary directory. edit_image can read a path it is given, which is the point of an edit tool, but the write side is pinned to one directory.

The configuration is six environment variables, one of which is the timeout. That is the right size for an internal tool: small enough to read in one sitting, explicit enough that a wrong setting fails at the diagnostic rather than mid-batch.

Receipts: IMAP to PDF to spreadsheet

The receipts server turns a mailbox and an expense spreadsheet into a folder of PDFs with matching filenames. It is the kind of task that looks like a 20-line script until the first email that does not match the template.

The pipeline has five steps, and each one is a tool boundary:

  1. Search. Query the mailbox by sender and date range. The search returns message metadata, not bodies, so a wide date range is cheap.
  2. Parse. Fetch one message by IMAP UID and extract merchant, amount, currency, transaction ID and date. The parser handles both person-to-person and merchant receipt formats, because the same provider sends both.
  3. Render. Convert the original HTML body into a PDF. Rendering the email rather than rebuilding a receipt from parsed fields keeps the document faithful to what was sent.
  4. Reconcile. Read the expense spreadsheet, match rows to receipts by date plus amount, render the PDFs and write the receipt filenames back into the sheet.
  5. Review. List the rows and receipts that did not match, so a person can see what the matcher could not resolve.

Two smaller tools make the server operable: list_unmatched returns the leftovers from the last match run, and reset_state clears the local SQLite database that tracks what has been processed. State on disk is what lets the server run repeatedly without re-rendering every receipt, and a reset is what lets a bad run be undone without deleting files by hand.

The matching rule is date plus amount, not a transaction ID. That is deliberate. The spreadsheet is maintained by a person, and the date and amount are the fields a person actually enters; a transaction ID is in the email but rarely in the sheet. The cost is that two receipts on the same day for the same amount are ambiguous, which is exactly what list_unmatched is for.

IMAP is an old protocol with a well-defined search grammar (RFC 3501). The server uses the search command rather than downloading a mailbox and filtering locally, so the cost scales with matches rather than with mailbox size.

The rules that made both usable

The two servers use different languages and live in different domains, but five rules shaped both, even where only one needed the implementation.

  • A cheap check first. check_image_api spends nothing, and the receipts server’s search returns metadata before any body is fetched. A tool that can cost money or time should have a cheaper way to confirm the configuration.
  • Explicit identifiers. IMAP UIDs, file paths, lookup IDs. Nothing depends on “the last one” or on the server remembering the previous call.
  • Paid calls are never the default. In the image server, generation and editing are billed while the diagnostic and the redisplay are not, and the descriptions say which is which.
  • Bounded output. generate_image returns at most four images. The receipt parser returns one transaction per message. A tool that can return an unbounded list will eventually return one.
  • State the caller can reset. The receipts server keeps processing state in SQLite; the image server writes files to one directory. Both survive a restart and can be cleared deliberately.

stdio or hosted HTTP for internal tools

Internal tools usually start as stdio because there is no deployment and no auth server. That is also the right default: the client launches the process, the credentials come from the environment, and the tool disappears when the client exits.

stdio Hosted Streamable HTTP
Setup Add a command and env vars to the client Deploy, DNS, auth
Credentials Environment variables OAuth or API key per caller
Reachable by The machine running the client Any client that can reach the URL
Lifecycle Starts and stops with the client Always running
Best for One operator, local files A team, shared state, web clients

Which should you choose? Use stdio for anything that reads local files or runs on one machine. Use a hosted server when the tool needs to be reachable from a web client, when several people need it, or when the work must continue after the caller disconnects. Moving from one to the other is mostly a transport change if the tool handlers were written without assumptions about the process.

Failure modes these servers are built around

Both servers are shaped by failure modes that are easy to predict in this class of tool. Naming them is more useful than pretending they were discovered the hard way.

  • The key leaks into output. A diagnostic that prints the resolved configuration must redact the credential. The image server keeps the key out of tool output and logs and reports only the credential source.
  • A prefix becomes a path. Any argument that becomes part of a filename is a path traversal candidate. The image server sanitises the prefix and pins writes to the output directory.
  • A read tool becomes a file reader. edit_image can read any path it is given. That is inherent to the operation, so the mitigation is client approval and filesystem permissions, not a regex.
  • The transcript becomes the delivery mechanism. Large images returned inline consume message bandwidth. The fix is to save local copies and offer show_image, so the file survives the conversation.
  • The client cannot render the result. A tool that returns an image block to a client that ignores image blocks looks broken. The loopback preview and Markdown fallback make the output usable anyway.
  • Email HTML is not a schema. Receipt templates change. The parser is regex heuristics over HTML, which is brittle by nature; the unmatched list is what keeps a template change visible instead of silently dropping rows.

The last one is the honest limit of the receipts server. It works because the set of senders is small and the formats are stable, not because the parser is general. A second provider with a different template would need its own parser, and the tool description should say so.

Frequently asked questions

What is an internal MCP server?

It is an MCP server built for one organisation's own tools and data, rather than published for customers. It usually runs over stdio on one machine, uses credentials from the environment, and wraps a task the team already does by hand.

When is MCP overkill for an internal tool?

When the task is a fixed pipeline with no decisions. A cron job or a CLI with flags is cheaper to build and easier to debug. MCP earns its place when an agent has to choose the next step, or when several tools share one interface.

Why does an image tool need a diagnostic that makes no request?

Because generation is billed and configuration errors are common. A free tool that reports the resolved endpoint, model and credential source turns a failed paid call into a one-second check. It also gives a new user a safe first command.

How do you stop an MCP tool reading arbitrary files?

You cannot, if the tool's job is to edit a file the caller names. The controls are the client's approval prompt and the operating system's permissions. The server's job is to constrain what it writes and to avoid turning a read argument into a directory scan.

Why use IMAP instead of a provider API?

The receipts arrive by email, and the mailbox is the source of truth. IMAP search is available on any mailbox and does not need a separate API integration. The trade-off is HTML parsing, which is why the unmatched list matters.

Can these servers run on a laptop and a server?

Yes, if the handlers do not assume a process lifetime. State lives in SQLite or on disk, identifiers are passed explicitly, and the transport is a thin adapter. That is also what makes a later move to hosted HTTP mostly a deployment change.

How many tools should an internal server expose?

Enough to cover the task and no more. Four tools for image generation and six for receipts is a surface a person can hold in their head, which matters when the same person has to debug it at the end of the month.