ENGINEERING / AGENTIC AI / MCP Morocco · Working with teams worldwide

✳ ENGINEERING GUIDE / AGENT SECURITY

Securing AI agents that can take action.

Tool-using AI agents need the same safety discipline as business software. Model instructions never replace backend authorization.

✳
AI · MCP · SYSTEMSDESIGN. CONNECT. SHIP.
01

1. Enforce permissions in the backend

Every tool must verify effective user or agent authorization. A tool being available in a conversation does not grant the right to run it. Enforce policies in APIs, MCP servers or systems of record.

  • Least-privilege access
  • Resource- and operation-level checks
02

2. Use human approval for sensitive actions

A reversible update and a financial transaction carry different risks. Create explicit approval policies for operations requiring a verified human decision.

  • Read, write and sensitive-operation separation
  • Approval flows tied to an identifiable session
03

3. Handle uncertain outcomes safely

After a network timeout, it may be unclear whether a write succeeded. Blind retries can produce duplicate payments or orders. Idempotency keys and reconciliation reduce that risk.

  • Stable operation identifiers
  • State verification before retries
04

4. Protect credentials and private data

API tokens and customer information should not leak into prompts or application logs. Give agents only the context needed for a particular action.

  • Secure credential storage and rotation
  • Sensitive-data redaction in traces
05

5. Design for operations

Tests should cover malicious inputs, unavailable tools, denied permissions and partial outages. Monitoring must distinguish a model statement from a confirmed execution.

  • Denied-access and adversarial tests
  • Useful logs and alerts
06

6. Threat modeling for prompt injection

Agents read documents, websites and incoming messages that may be controlled by third parties. Such material can contain malicious instructions asking the model to ignore rules, call privileged tools or send data elsewhere. A stronger system prompt alone cannot guarantee safety. Treat retrieved text as lower-trust data. The backend must independently validate the user, requested operation and resource scope. External documents may be summarized or cited, but never become authorization. This boundary reduces the impact of prompt injection when an assistant has connected tools.

  • Separate trusted system rules from untrusted tool and document content.
  • Reject requests outside the authorized scope regardless of persuasive wording.
  • Test adversarial input on all integration paths.
07

7. Identity, authorization and customer scope

An infrastructure API key may authenticate the application, but does not prove that the person chatting is entitled to view a particular order. Each operation must bind a verified identity, an exact resource and a capability. Policies such as PUBLIC, VERIFIED_CUSTOMER or OWN_RESOURCE should enforce access rather than serve as labels. Authentication must happen through a trusted flow; sharing someone else's phone number must not grant their access. Credentials belong on the server and should not appear in model context, public logs or client-side JavaScript. Audit policy decisions without leaking private account information.

  • Authorize per resource, not just per tool name.
  • Verify the customer before exposing sensitive records.
  • Keep tokens outside prompts and public traces.
08

8. Uncertain writes, idempotency and reconciliation

Consider an agent sending a telecom top-up request when the connection times out. The operation may have failed, succeeded or executed without an acknowledgment. Blindly trying again could duplicate a charge. Bind an idempotency key to the original business intent and inspect the source-of-truth backend before retrying. Human approvals must apply to the exact operation rather than any later mutation. Uncertain outcomes should remain pending reconciliation until verified or reviewed by a human. During JAWCHA security tests, quarantining ambiguous writes was an important mechanism for preventing this failure mode.

  • Keep the same idempotency key for the same intended write.
  • Do not repeat an uncertain mutation by default.
  • Document investigation, recovery and cancellation paths.
09

9. Observability without oversharing

Incident investigation needs a chain from the initial request through identity, selected tool, authorization decision and backend result. That does not justify collecting raw conversations indefinitely. Minimize personal data, redact secrets and define appropriate retention. Useful alerts include unexpected denials, unusual costs, repeated mutations and long pending approvals. A platform should allow investigation without exposing customer details to everyone on the team. Decide who may inspect traces, how records are deleted and what happens when a chat is flagged as sensitive.

  • Use correlation identifiers and structured result states.
  • Redact personal data and restrict access to logs.
  • Define alerts and operational playbooks.
10

10. A production security acceptance checklist

Happy-path tests are insufficient. Verify that customer A cannot see customer B's records, public agents cannot call internal tools, malicious document content cannot change privileges, expired approvals cannot execute and timeouts do not duplicate writes. Confirm that revoking credentials or disconnecting a tool takes effect promptly. Audit changes to sensitive configuration. Provide an emergency disable mechanism for risky capabilities. A demonstration may stop after one successful action; a production launch requires evidence that rejected and ambiguous cases behave safely too.

  • Test cross-tenant denial and audience separation.
  • Verify approval expiry and access revocation.
  • Test retries, timeouts and prompt-injection attempts.
ENGINEERING IN PRACTICE

See the implementation.

These concepts become more useful when tied to actual business systems.

CASE STUDY / JAWCHA MCP integration and permissions ↗
04 / THE TOOLKIT

Technologies I work with

Tool Policies✳MCP✳Human-in-the-Loop✳Idempotency✳AuthZ✳Audit Logs✳API Security✳
07 / Work with me

Your next product deserves serious engineering.

AI agents, MCP, APIs and business software: let’s define what is realistic for your team.

↗