How to persist user-defined constraints into standard protocol interactions for agents
TL;DR
- Keep the rule out of ranked retrieval. Read a known field or load a known file; Supermemory describes why a query may not surface a relevant preference.
- Have the host deliver it. Supply the constraint to each model request rather than assuming it survives from an earlier response. The Responses API documents this distinction.
- Check before the tool acts. Client permissions, hooks, and tool guardrails can refuse a call independently of the model. Their coverage depends on the client and configuration.
- Plan for a failed check. Claude Code and Cursor document both actions that proceed after hook failures and settings that block on failure.
Someone tells an agent, "never touch staging." It respects the instruction for a week. Then a new session, or a different client, makes a call that reaches staging anyway.
This article uses standard protocol to mean the Model Context Protocol (MCP). Splitting the question into store, deliver and enforce is this page's framing; every protocol and client behaviour is quoted from the spec or the vendor's docs.
Server instructions are MCP's "Optional natural-language guidance for LLMs on how to use this server effectively".
A tool guardrail is a check on a tool call: OpenAI says "Input tool guardrails run before the tool executes and can skip the call, replace the output with a message, or raise a tripwire."
Where a user-defined constraint should live
Store a required constraint where the application can find it without asking a similarity search to rank it. That can be an explicitly addressed field or a file the host loads at each turn. The constraint still needs a check at the action boundary.
Supermemory gives the example: a search about trip planning or code review "will not surface the name preference". statewave, which builds an open memory engine, shows the same with an allergy and a lunch question. The issue is the retrieval decision, not whether the memory was saved.
For a field rather than a search result, Dimitris Kyrkos puts the distinction this way: "The reason a structured field beats a retrieved passage is not that retrieval is bad, it is that a looked-up field cannot be outranked by something that merely sounds more relevant."
Memory systems hold such an entry in different places. None of the rows, by itself, makes an agent obey a constraint.
| System | Where a constraint can live | The vendor's words |
|---|---|---|
| Letta | A file at the MemFS memory root | "Files at the memory root are loaded into the agent's system prompt on every turn." |
| Zep | A typed graph entry; a property marked protected: true | "You may restrict graph queries to nodes/edges of a specific type, such as Preference." and "To keep a stored value, set protected: true on the entity type property." |
| Mem0 | A stored memory marked immutable | "Mark stored memories as immutable, excluding them from future update/consolidation." |
| Google ADK | A user: state field | "Scope: Tied to the user_id, shared across all sessions for that user (within the same app_name)." |
| Supermemory | A user profile supplied to agent context | "Think of it as a persistent "about me" document that's always up-to-date." |
| Mnemoverse (publisher) | An entry in a domain namespace, fetched by its ID | domain: "Namespace, up to 100 characters: general, user:X, project:Z (default: general)". GET /memory/atoms/{atom_id}: "Fetch a single atom by ID." |
A marker at write time helps the application identify a constraint later. In a reply to this site's author, statewave, which builds an open memory engine, writes that "something has to mark the note as a constraint when it is written." A marker does not make the read or the check happen.
The same reply describes that engine's ranking: "recency is min-max across the candidate pool". The Generative Agents paper also describes min-max scaling of recency, relevance, and importance, with recency measured from the last retrieval. This page's inference: in that calculation the minimum of the pool receives zero, and a rarely retrieved rule becomes older by that measure. These are descriptions of those implementations, not a claim about other vendors' rankings.
Do not confuse where a rule is stored with a setting that controls what gets stored: Mem0 and Zep custom instructions steer extraction when data is added. Supermemory says of its rules: "They aren't hard constraints," and puts a rule that "Every request needs it, verbatim" in the system prompt.
Saving the state itself between runs: how to store agent state across restarts.
Which MCP channel carries it, and who controls each one
The MCP specification says it "cannot enforce these security principles at the protocol level". Its current revision reads "Make MCP stateless: remove the initialize/notifications/initialized handshake". A host must therefore arrange the reads and checks its application needs; it cannot treat a previous conversation as the enforcement mechanism. See also stateless MCP agent memory.
The suitability column is this page's recommendation.
| MCP channel | Who controls it | Suitability for a user's constraint |
|---|---|---|
| Server instructions | The server supplies guidance about using itself. | Useful for server guidance, not an enforcement check. |
| Prompts | The user selects a prompt; the server defines its text; the client can supply arguments. | An argument can carry a user's value. The server still authors the template, so the host must decide when to use it. |
| Resources | The host application determines how to incorporate them. | A host can include a resource, but must arrange that inclusion for the relevant request. |
| Tools | The model can discover and invoke them; the client can provide a way to deny calls. | Put a check before the relevant call, rather than relying on the tool description. |
| Tool annotations | The server describes tool properties. | They are hints, not a substitute for a client check. |
| Roots | The client identifies relevant directories and files. | Roots "are informational guidance rather than an access-control mechanism", and "The Roots feature is deprecated as of protocol version" 2026-07-28. |
| Elicitation | The server asks the user, in this revision through Multi Round-Trip Requests. | Useful when a rule needs clarification; "Servers MUST NOT use form mode elicitation to request sensitive information". |
_meta and extensions | Requests carry client information in _meta; extensions define additional capabilities and keys. | An integration can use supported extension semantics. Both sides must implement the intended handling. |
The Skills extension, whose "SDK and host support is still being implemented", does not make a server-authored instruction a user's constraint either.
For the limits and handling of server instructions and annotations, see MCP memory server tools. For the distinction between a rule in context and an enforced check, see Claude instructions, AGENTS.md, and Cursor rules.
Delivery needs an explicit path. The Responses API: "When using along with previous_response_id, the instructions from a previous response will not be carried over to the next response." Google ADK supports substituting state values into instruction templates; the OpenAI Agents SDK supports dynamic instructions. Claude Code hooks can add a string to context through additionalContext. Each is a way to supply context, not proof that a tool call will be refused.
What enforces it on an MCP tool call, client by client
The checks below act on tool calls. A constraint such as "answer in the user's language" needs an output check: a tool-call check does not validate the answer.
| Client or framework | Where to put the check | What a refusal can do |
|---|---|---|
| Claude Code | Permission rules on mcp__*, which "matches every MCP tool across all servers" or a PreToolUse hook ("MCP tools follow the naming pattern mcp__<server>__<tool>") | "Rules are evaluated in order: deny, then ask, then allow." |
| Cursor | A beforeMCPExecution permission hook, or preToolUse. | "Exit code 2 - Block the action"; "any deny wins over ask, and ask wins over allow, regardless of source." |
| OpenAI Agents SDK | An input tool guardrail for a guarded function tool, including a local MCP tool when its server configures guardrails. | It can skip the call, replace output, or raise a tripwire. |
| Google ADK | "Callbacks and Plugins: Validate model and tool calls before or after execution, checking parameters against agent state or external policies." | Before callbacks "act as gatekeepers, allowing you to intercept execution before a major step and potentially prevent it". |
| LangChain | Middleware that can "intercept execution at strategic points", including "around model and tool calls" | "LangChain provides built-in middleware for requiring human approval before executing sensitive operations." |
| Letta | "a session-wide permission mode, and a canUseTool callback that approves, denies, or edits individual tool calls" | "A "deny" response can pass interrupt: true to also stop the turn". |
| Claude API MCP connector | Configure which connected server tools are available. | Anthropic recommends "Denylisting write or destructive tools" for read-only assistants. |
Claude Code states that "Permission rules are enforced by Claude Code, not by the model." Its hooks documentation also describes hooks that call an MCP server tool. That is distinct from a hook checking a proposed MCP tool call.
In a comment under an article by this site's author, Murali Gour, who builds DataGrout, writes: "Constraints don't need ranking or negative feedback, they need to be enforced before the action happens." In the same thread Theo Valmis, who builds Mneme HQ, calls the durable fix "separating what the agent should remember from what has to be true regardless of what it remembers". The implementation must still cover the actual path to the action: a check on one MCP tool does not itself prevent access through another path.
A small implementation pattern
Pseudocode, not any client's configuration:
on_model_request(user, request):
policy = read_policy(user) # read error: stop
return call_model(request, instructions=render(policy))
before_tool_call(user, tool, arguments):
policy = read_policy(user) # read error: deny
target = resolve_target(tool, arguments) # unknown: deny
if policy.denies(tool, target):
return DENY
return ALLOWFor the staging example, the check needs a reliable way to identify the target environment, not merely the words the user typed. Test an allowed target, a denied target, an unavailable policy store, an unidentifiable target, and a call through each tool that can reach staging. Confirm that the client's actual failure setting produces the intended result.
A hook runs at a configured event, while the model decides whether to call a tool; MCP memory servers in Claude Code and Cursor covers how each of the two fails. The next section adds what happens when a checking hook itself fails.
What happens when the check itself fails
A policy rejection and a broken policy check are different events. Decide both outcomes before enabling the hook.
Claude Code. Its hook documentation: "On most events, when a hook fails or times out, Claude Code still carries out the action. A policy hook with a wrong path or a crashing script then lets everything through." On PreToolUse, "don't count on a stalled hook to act as a gate." For a policy rejection: "If your hook is meant to enforce a policy, use exit 2."
As read on 24 November 2026: "To block the action instead, set "onFailure": "block" on a command, http, or mcp_tool hook." and "On mcp_tool hooks, onFailure requires v2.1.328 or later." For a hook that calls an MCP tool, "If the server isn't connected at that point, the hook fails." And an isError: true result is a non-blocking error.
Cursor. Its hooks documentation: "Other exit codes - Hook failed, action proceeds (fail-open by default)". For permission hooks, beforeMCPExecution among them, "invalid JSON or a response that doesn't match the hook's schema blocks the action." Of failClosed: "When true, hook failures (crash, timeout, non-zero exit code, no output) block the action instead of allowing it through." And "Dashboard hooks don't take per-hook options such as failClosed or matcher."
OpenAI Agents SDK. "Input tool guardrails run before the tool executes" (guardrails). Hosted tools, HostedMCPTool among them, "do not use this guardrail pipeline"; for hosted MCP, "Configure require_approval in the tool_config" (MCP guide). Agent-level input guardrails are a separate mechanism, not proof that each tool call was checked.
This page's recommendation: for a constraint that must prevent an action, configure a supported block-on-failure option and test the failure cases. If the check cannot obtain the information needed to decide, choose a refusal or an explicit approval path rather than silently treating the check as successful.
When a constraint should stop applying
A date and a condition answer different questions. Mem0 describes expiration as: "Hides a memory once a date you set passes". That is useful when the stopping date is known.
This page's recommendation: record the reason for a constraint and the condition under which it lifts. Check that condition when the constraint fires. For example, a staging restriction might apply while the environment is shared; if the application cannot establish whether that condition still holds, its failure policy should decide what happens next.
A condition becoming false differs from replacement by a newer instruction, a user correction, or ordinary forgetting and decay. Choose the operation that matches the reason the rule should change.
If the protocol is A2A instead of MCP
Agent2Agent is another open standard. Its specification says that when a server requires an extension declared in its Agent Card, a client that does not declare support receives an ExtensionSupportRequiredError. A2A can also use an input-required task state to request clarification. MCP likewise has an input-required result; the distinction here is A2A's required-extension mechanism, not an exclusive ability to ask for input. See A2A vs MCP.
What this page does not claim
No benchmark of any system. Splitting the question into store, deliver and enforce is this page's framing; which MCP channel suits a user's constraint, turning on the clients' block-on-failure settings for a constraint, and checking a revocation condition when the constraint fires are this page's recommendations. Practitioners quoted here build their own products and say so. Protocol and client behaviour is quoted from the documents on the date in Sources; your version may differ.
Common questions
How to persist user-defined constraints into standard protocol interactions for agents
Store the constraint outside ranked retrieval, have the host supply it on model requests, and check it before the relevant tool call. Decide what the check does when it cannot read or evaluate the rule.
My automated workflow loses crucial instructions whenever the underlying runtime restarts
Keep instructions in durable state outside the runtime and supply them again on each model request. In the Responses API, instructions from a previous response are not carried over through previous_response_id.
Can MCP server instructions enforce a rule?
No. Server instructions are optional guidance about using a server, written by the server rather than the user, and the MCP specification says MCP itself cannot enforce its security principles at the protocol level. Use a client permission, hook, or tool guardrail to enforce a constraint at the relevant tool call.
Should a user's constraint be stored in agent memory and found by similarity search?
It can be stored in memory, but a required constraint should be read directly or loaded into context rather than depending on similarity search. Delivery to the model is separate from enforcement at the tool call.
What happens if the hook that checks a constraint fails?
The result depends on the client and the failure. Claude Code and Cursor document cases where the action proceeds, and each documents a setting that blocks on failure instead: onFailure set to block in Claude Code, failClosed set to true in Cursor. In the OpenAI Agents SDK, input tool guardrails run before guarded function-tool calls; HostedMCPTool bypasses that pipeline, so configure require_approval when approval is required.
Sources
All sources below were read on 24 November 2026.
Protocols
- MCP: introduction, specification, server discovery, prompts, resources, tools, roots, elicitation, basic protocol, MRTR, changelog, schema, and Skills extension.
- A2A: llms.txt, specification and life of a task.
Clients and frameworks
- Anthropic: Claude Code permissions and hooks; Claude API MCP connector.
- Cursor: hooks.
- OpenAI: Responses API; Agents SDK guardrails, MCP, agents, and context.
- Google ADK: agent instructions, state, safety, and types of callbacks.
- LangChain: guardrails. Letta: SDK permissions.
Memory systems and research
- Letta: MemFS. Zep: graph structure and custom instructions. Mem0: adding memories, custom instructions, and expiration.
- Supermemory: user profiles and rules. Mnemoverse: API reference.
- Park and coauthors: Generative Agents.
Practitioner discussions
- statewave: article and reply.
- Murali Gour (DataGrout) and Theo Valmis (Mneme HQ): comments 3f82f and 3f7n6 under an article by this site's author.
- Dimitris Kyrkos: comment.
Related
- Why agents retrieve irrelevant past context
- Claude instructions, AGENTS.md, and Cursor rules
- MCP memory servers in Claude Code and Cursor
- How to stop an agent repeating fixed mistakes
- The agent memory write gate
- Claude Code persistent memory
Sources were read on 24 November 2026; the page describes them as of that date.
Who wrote this. Mnemoverse publishes this page and is one of the memory systems in its table of where a constraint can live, so we are an interested party. Every system is quoted from its own documentation on the date in Sources, ours included. Send corrections through contact.
Edward Izgorodin · Mnemoverse · 24 November 2026
