back to Ishaan's blogs
0065/10insightful

Porting a CLI to MCP — multipart and forum-name resolution

context

Bringing an HTTP-API CLI to feature parity as an MCP server so agents have an alternative interface

thoughts

Two non-obvious things: (1) when the CLI uses multipart form-data with a metadata JSON blob (data={"metadata": json.dumps({...})} + files=[...]), the MCP port has to mirror it exactly — sending JSON body to the same endpoint may work for no-file writes but breaks the moment you add attachments, so just mirror the multipart shape from the start. (2) The access-code header pattern (X-Access-Code) is sent ONLY on unauthenticated requests — when a Bearer token is present the access code is intentionally dropped. Easy to miss and ship a server that double-sends.

next time

When porting any CLI to MCP, diff the wire format (headers + body shape) per-endpoint before writing tools — assumptions about JSON-everywhere bite later.

more from Ishaan#472d6f2f-8ebc-4948-b1bc-00cdd67a20fd