← Blog

Date:Thu, 19 Nov 2026 From:Thomas Gumz <thomas@lograker.app> To:You Subject:

A memory cap for the MCP Swift SDK

LogRaker has had an MCP Server since this summer, so AI agents can read your Streams, search them and wait for a line to show up. It’s built on the official MCP Swift SDK, which does all the protocol work, so LogRaker only has to answer the questions.

Today I went through all of LogRaker looking for anything that wastes CPU or memory, and one thing I didn’t expect turned up in the SDK itself: every MCP session kept a copy of every answer it ever sent, for as long as the session lived.

Where it comes from

MCP over HTTP sends its answers as a stream of server-sent events, and the spec lets a client that lost its connection reconnect and say “I last saw event 42, send me what came after”. To make that work, the SDK’s StatefulHTTPServerTransport stores every message it sends, together with its event ID.

That’s the right idea, but the store has no limit. It’s only emptied when the session closes, and in LogRaker a session can live for a very long time.

You see, LogRaker isn’t an app you open, use for five minutes and quit (although you can, of course). It’s meant to keep running for days, almost like a little server itself: it can start when you log in without even showing a window, closing the window doesn’t quit it, your Streams keep tailing in the background, and your Monitors keep watching them around the clock and let you know when something shows up. The MCP Server runs right along with all of that, so an agent that connects to it can stay connected just as long.

An agent that keeps LogRaker open all day and asks for 2,000 lines of a Stream every now and then gets a fresh copy of those 2,000 lines kept in memory each time, and none of them ever go away. In LogRaker a session ends when the agent disconnects or after 24 hours of not being used, and up to 32 of them can be open at once, so in the worst case that adds up to a lot of memory nobody will ever ask for again (in practice, a client that reconnects only ever wants the last few events).

I checked the newest release (0.12.1) and the main branch: both still keep everything.

Why I couldn’t fix it from the outside

The store is private to the transport, and there’s no setting for it. The only thing LogRaker could do from the outside was close busy sessions early, and that would break the agents using them, which is worse than the problem.

So, just like with swift-nio-ssh, LogRaker now carries its own copy of the SDK with one small change, marked with a LOGRAKER FORK: comment and explained in a FORK.md.

The change

The transport now keeps at most 8 MB of messages per session (maxStoredEventBytes, a new init parameter with that as its default). Once a session goes past it, the oldest events are dropped, except the one just stored, so the stream that’s still running can always be resumed.

If a client asks to resume after an event that has already been dropped, it gets the same 400 Invalid Last-Event-ID answer the SDK already gives for an ID it doesn’t know, and starts over, which the spec allows for.

One new test covers it: under the normal cap a stream can be resumed, and under a 1-byte cap its events are gone. All 552 tests of the SDK pass.

The fork is published as 0.12.1-cap.1, under the same license as upstream, so anyone who runs into the same thing can use it (or just copy the few lines).

So…

It’s a small change, but it means an agent can now stay connected to LogRaker for days without LogRaker slowly eating more and more memory. If you build an MCP server in Swift yourself, keep an eye on this one too, especially if your answers are big.

Thanks for reading!