See Ash Code logo See Ash Code

A CLI and an MCP server can share the same application code

Ashlynn Antrobus
• • 2 min read

After separating the cPanel email operations from their transport, I could call the same operations from a terminal as well as an MCP client.

The December refactor adds a CLI beside the server. Both build a CpanelEmail object with the selected connector. That is the code I want them to share: the mapping from an email operation to a cPanel function and its parameters.

Two ways to ask the same question

Using a dummy domain, the terminal invocation looks like:

cpanel-cli api --list-accounts --domain example.com

The corresponding MCP tool is list_email_accounts, with domain set to example.com. Both reach the email method that calls make_call with Email, list_pops, and the domain parameter.

The MCP server registers the email methods as tools. The CLI uses its command selection to look up the corresponding method on the same application object.

Neither interface needs its own implementation of how cPanel names the account-listing operation. If I correct that mapping, I have one application method to correct.

Two dragons send envelopes from a terminal and a server along paths to the same post office.

The signature selects the arguments

In the follow-up CLI revision, the command dispatcher inspects the selected method:

sig = inspect.signature(tool)
kwargs = {
    name: getattr(args, name)
    for name in sig.parameters
    if hasattr(args, name)
}

print(tool(**kwargs))

For listing accounts, it picks the domain argument. A password-changing method has a different signature and therefore needs a different set of arguments.

That saves manually repeating the method’s parameter list in every dispatch branch. It doesn’t establish that each supplied value is valid.

The parser still needs to explain which arguments a command requires. It also needs to convert values to the right types. An argument existing on the parsed namespace is a weaker condition than a valid domain, a supplied password, or a suitable integer quota.

Shared results, different presentation

The shared email method returns the connector’s result. With the same fake connector result, the application boundary can give both interfaces the same dictionary.

What the user sees is different. The CLI prints the result; MCP returns a tool result through its protocol. Matching application data doesn’t mean their rendered output is byte-for-byte identical.

And, as the transport post showed, HTTP and SSH don’t yet return identical result representations in these snapshots. Sharing the application method doesn’t remove that work either.

AA

Written by Ashlynn Antrobus

Software developer, author, and builder. Sharing technical lessons learned from building tools like Ebook2Text, IndexedDict, and rag-mcp, and navigating life as a programmer with dyslexia.