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

✳ ENGINEERING GUIDE / MCP

Building an MCP server for business software.

Model Context Protocol describes capabilities available to compatible AI clients. The difficult part is not merely the protocol: tools must be useful, authorized and auditable.

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

1. Start with business capabilities, not endpoints

An MCP server should not expose every internal method. Start with a deliberate capability such as checking an order, looking up a customer or preparing a draft. Define tool intent, parameters and expected outcomes.

  • Limit exposure to useful and verifiable actions.
  • Document input and output schemas and possible errors.
  • Distinguish read-only, prepare and commit operations.
02

2. Reuse existing services and business rules

MCP adapters should ideally call reliable existing APIs. Cart, payment and stock validations still belong in the source system. A tool invocation never authorizes bypassing established checks.

  • Keep validations and authorization on the server.
  • Bind each operation to a verified user or customer identity.
  • Return only data the agent genuinely needs.
03

3. Choose transport and authentication deliberately

Hosting and connectivity differ between local, remote and private MCP deployments. In business environments, identity lifecycle, secret storage and revocation matter more than demo convenience.

  • Separate infrastructure credentials from user data.
  • Manage tokens and revocation properly.
  • Check the MCP features actually supported by each client.
04

4. Protect sensitive mutations

Reading an order and refunding an order are not equally risky. Sensitive operations may require explicit human approval. Add idempotency keys where a mutation might be retried after a timeout or uncertain response.

  • Do not blindly replay an uncertain write.
  • Log identity, tool, authorization decision and result.
  • Test denial and error paths as thoroughly as success.
05

5. Test and observe production behavior

A tool is not complete simply because it works in a local assistant. Implement contract tests, quotas, alerts and latency monitoring. Logs should explain what was attempted, authorized, executed and returned.

  • Functional tests and adversarial scenarios.
  • Cost, error and repeated-call monitoring.
  • Operations documentation and recovery procedures.
06

6. Worked example: wrapping an existing order API

Consider a Laravel application with an established GET /orders/{id} endpoint and working authentication. A generic tool that can call arbitrary URLs would be an unsafe shortcut: it could target unintended paths or retrieve resources owned by other users. Instead, create a dedicated orders_get_status capability. The MCP tool validates its input, resolves the authenticated user, enforces resource-level authorization and calls the existing business API. The model only receives the fields required to answer the question: order identifier, status and last update. It does not receive the internal API surface, customer records or service credentials. The protocol becomes an adapter around established domain rules rather than a substitute for them.

  • Describe a concrete business capability, not a generic request runner.
  • Resource identifiers never imply permission.
  • Return a narrow, structured result.
PSEUDOCODE / ARCHITECTURE EXAMPLE
// Illustrative pseudocode, not a complete MCP SDK example
async function orders_get_status(ctx, { orderId }) {
  const actor = await authenticate(ctx);
  await authorize(actor, 'orders:read', orderId);
  const order = await commerceApi.getOrder(orderId, actor);
  return { id: order.id, status: order.status, updatedAt: order.updatedAt };
}
07

7. Use errors the assistant cannot misinterpret

Real integrations must distinguish invalid input, missing data, denied permissions, upstream outages and uncertain mutations. If a tool returns a vague sentence, the assistant may incorrectly tell the customer that an operation succeeded. Define stable machine-readable errors such as NOT_FOUND, FORBIDDEN and UPSTREAM_UNAVAILABLE. For writes, an unanswered timeout should lead to UNKNOWN or PENDING_RECONCILIATION rather than SUCCESS. Investigate the source system before deciding whether to retry. This is critical for refunds, purchases, wallet transfers and booking changes. A model is not the source of truth for external side effects; the backend receipt is.

  • Never expose infrastructure traces or secrets in error messages.
  • Use explicit verified statuses rather than conversational assumptions.
  • Keep uncertain writes pending until they are reconciled.
08

8. Split read, prepare, confirm and commit

Permission boundaries should reflect what the tool can actually do. An authenticated user may read a scoped record. Creating a draft is different from submitting a payment or deleting data. For sensitive mutations, a safer workflow is READ → PREPARE → CONFIRM → COMMIT, with an exact summary of the target and consequence presented to an authorized human. Approval must be bound to the concrete operation and expire if its context changes. A casual statement in chat must never provide blanket permission for arbitrary future tool calls. Protect every transition server-side, including actions discovered through external documents or untrusted messages.

  • Re-evaluate authorization for every sensitive tool call.
  • Bind approvals to an exact action and identity.
  • Treat retrieved content as data, not authority.
09

9. Lessons from building JAWCHA

JAWCHA demonstrates why a usable agent console alone is not sufficient. The platform connects agents, models, channels and MCP tools; its engineering challenge is controlling which capabilities each audience can reach. Server policies, internal-versus-customer audiences and human reviews constrain actions. Mutations need idempotency identifiers and operation tracking to avoid repeating a write after an ambiguous timeout. The portfolio case study contains actual product screenshots plus an explicitly disconnected simulation of this lifecycle. It is evidence of the architecture and design work, not a guarantee that every MCP provider or transport is supported.

  • See the JAWCHA case study at /en/work/jawcha/.
  • Start with a read-only tool and verify denial cases.
  • Design a recovery path before enabling mutations.
10

10. Production delivery checklist

Before shipping an MCP adapter, establish who can invoke it, which backend API each tool calls, how identities propagate, where authorization decisions are recorded and who can revoke access. Credentials stay outside model context. Logs use correlation IDs without leaking private records. Tests include adversarial inputs, repeated requests and mid-operation network failures. Monitor latency, tool errors, rejected calls and human approval rates, not only token costs. Finally, provide runbooks covering key rotation, rollback, timeouts and reconciliation of uncertain operations. These are the engineering practices that separate a credible integration from a convincing demo.

  • Document tool contracts, tests and access policies.
  • Instrument errors, quotas and recovery operations.
  • Demonstrate both permitted and refused flows to the client team.
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

Model Context Protocol✳MCP SDK✳REST APIs✳OAuth✳Tool Calling✳JSON Schema✳Idempotency✳
06 / FAQ

FREQUENT QUESTIONS

01Can an MCP server provide access to a database?

Yes, but direct database access is not always appropriate. Narrow business tools built around existing backend services are often easier to secure and audit.

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.

↗