GenMCP.Suite.SessionController.DevSessionStore (gen_mcp v0.9.1)

Copy Markdown View Source

An implementation of GenMCP.Suite.SessionController that persists the session to disk.

This is useful during development to be able to stop and restart the Elixir runtime without losing the session. Many MCP clients do not support 404 Not Found error for sessions and will need manual assistance to create a new session. This controller solves that.

Development Only

Sessions are stored on the hard drive. There is no support for data corruption prevention, distribution on multiple nodes, etc.

It is not suited for production environments.

To use this controller, provide it as the :session_controller option to the transport plug. Optionally with a custom directory:

forward "/real", McpReal,
  server_name: "Real Server",
  server_version: "0.0.1",
  server_title: "GenMCP own development server",
  tools: [GenMCP.Test.Tools.ErlangHasher, GenMCP.Test.Tools.Addition],
  extensions: [],
  session_controller:
    {GenMCP.Suite.SessionController.DevSessionStore, cache_dir: "tmp/sessions"}

Options

  • :cache_dir - a directory path to store sessions as files. The directory will be created if it does not exist. The default value uses System.tmp_dir!() which will lead to sessions being lost after a while on most platforms.