An agent conversation is temporary. A Microfn function can keep small pieces of structured state between calls with @microfn/kv, then expose that function as a reusable MCP tool.
Create the memory function
import kv from "@microfn/kv";
type Input =
| { action: "remember"; key: string; value: string }
| { action: "recall"; key: string };
export async function main(input: Input) {
const key = `agent-memory:${input.key}`;
if (input.action === "remember") {
await kv.set(key, input.value);
return { saved: true, key: input.key };
}
const value = await kv.get<string>(key);
return { key: input.key, value: value ?? null };
}
Deploy the function, run a remember call, then run recall with the same key. Enable Direct MCP Tool under Triggers if you want the connected agent to call it by name.
Keep the scope narrow
Use explicit keys and store only data the function needs. This example has no delete or list operation, so it is a small preference store rather than a general database. Do not store API keys, access tokens, or sensitive personal data in KV; use function secrets for credentials.