mcp_authorization v0.7.1

Talking to the outside world

Every recipe so far returned a canned hash. Real handlers do I/O โ€” they query databases and open sockets. The gem doesn't get in the way: a handler is a plai...

Every recipe so far returned a canned hash. Real handlers do I/O โ€” they query databases and open sockets. The gem doesn't get in the way: a handler is a plain Ruby object running inside your Rails process, so you have ActiveRecord, connection pools, and the standard library. Two things stay your job, and the next two recipes are mostly about them:

The input is hostile. Every param value originates from an LLM, which is steered by whoever is talking to it. Treat query:, host:, and friends exactly as you'd treat a raw HTTP param: never interpolate them into SQL, never open a connection to an attacker-chosen address without an allowlist. Schema constraints (@pattern, @format, @min) narrow the shape but do not make a value trusted.

Connections don't survive the request. The transport is stateless โ€” each MCP request builds a fresh server (see README: Stateless transport). Open what you need inside call, use it, close it. Don't stash a socket in an instance variable hoping to reuse it next call; there is no next call on this object.

Collected from COOKBOOK.md in the repository. Edit it there, not here.