Suman Basnet
Suman Basnet
AI & PROTOCOLS/2026-01/8 min read (810 words)

Building with MCP: Bridging AI Agents and Real-World Business Context

SB
Suman Basnet
Founder & Product Engineer · Osaka, Japan
Why standard LLM wrappers fail in commercial environments, and how Anthropic's Model Context Protocol (MCP) provides the deterministic contracts needed for real business operations.

The Hallucination Penalty in Production

When you experiment with AI prototypes in development, conversational flexibility feels remarkable. You ask an open-ended question, and the model constructs an articulate, persuasive answer. But in commercial software, a plausible answer that is factually wrong is far worse than an explicit system error.

While building HamroLink, this limitation became obvious almost immediately. If an AI agent helping a store merchant tells a buyer that a specific jacket is in stock when the inventory row has been empty for two days, or generates an unauthorized price cut because the prompt wording was slightly loose, the merchant loses money and the customer loses trust. In business systems, you cannot negotiate with state.

The root cause of this breakdown is treating a large language model as both the reasoning engine and the database of record. Language models are probabilistic pattern matchers. Business records—stock quantities, payment verifications, customer identities, courier dispatches—are strictly deterministic. When you blur the line between reasoning and state, production reliability collapses.

What Changed My Approach

Early on, my natural reaction was to add more instructions to the system prompt. I wrote detailed constraints explaining what the model should and should not say, along with fallback rules for when data was missing. This approach created brittle prompts that grew longer with every edge case, increased token costs, and still occasionally failed whenever the user phrased an order unpredictably.

I realized that prompt engineering was the wrong layer to solve an architectural problem. An AI agent should never have freeform direct access to internal database tables, nor should it guess operational facts. Instead, the model should only interact with explicitly declared, typed capabilities that mirror real-world business actions.

This realization led me to adopt Anthropic's Model Context Protocol (MCP). MCP formalizes how an autonomous model discovers available capabilities, requests fresh business context, and executes mutations through validated JSON-RPC contracts. The protocol separates the model's linguistic reasoning from the application's actual data persistence.

An AI agent without formal tool contracts is an unbounded liability. MCP transforms probabilistic model reasoning into verifiable, auditable software transactions.

How It Works: MCP as an Architectural Contract

In the HamroLink architecture, MCP functions as the constitutional gateway between the reasoning agent and our PostgreSQL multi-tenant database. The model never runs raw queries or manipulates application memory directly. When the agent receives a request—such as a customer asking whether a product can be delivered to their district—it executes a structured three-step cycle:

First, the agent inspects its tool registry to find tools matching the operational need. Second, it calls the MCP server using a strictly defined JSON Schema payload. Third, our server validates the payload against tenant permissions, queries the live database row, and returns a structured response envelope.

Sample MCP Tool Definition for Inventory Verificationjson
{
  "name": "verify_inventory_and_delivery",
  "description": "Checks real-time inventory count and courier coverage for a specific postal location.",
  "inputSchema": {
    "type": "object",
    "properties": {
      "productId": { "type": "string" },
      "variantSku": { "type": "string" },
      "postalDistrict": { "type": "string" }
    },
    "required": ["productId", "variantSku", "postalDistrict"]
  }
}

Tiered Context Assembly for Inference

To keep inference fast and economical, we assemble context in three distinct tiers. Static merchant profile information (business name, currency, return window) is stored in the initial session frame. Temporal operational rules (active store promotions, seasonal holiday courier delays) are injected dynamically when an interaction starts. Volatile business state (inventory ledgers, payment statuses) is never preloaded; it is queried on-demand through MCP tool invocations only when necessary.

This division keeps the prompt clean, avoids overwhelming the model with irrelevant records, and ensures every mutation is validated before touching the database.

What I Learned: The Hard Tradeoffs

Adopting MCP taught me that strict boundaries introduce real architectural tradeoffs. First, tool roundtrips take time. When an agent must parse intent, request a tool call, wait for the backend to validate and respond, and then compose its final answer, latency increases compared to a single naive prompt completion. You have to optimize database queries aggressively and avoid unnecessary tool roundtrips.

Second, schema design requires continuous discipline. If a tool parameter is poorly typed or its description is ambiguous, the agent will pass invalid inputs. We had to write robust error handlers that return clear validation errors back to the model, allowing it to correct its parameters rather than failing silently.

Finally, an immutable audit trail is essential. We log every agent inference, every tool parameter submitted, and the resulting database state change. When an unexpected state transition occurs, having a full record makes debugging straightforward.

What This Means in Practice

If you are designing agentic software for business operations, treat your AI model as an operator rather than a database. The model's job is to interpret human intent, pick the appropriate tool, and report the outcome clearly. The application backend remains responsible for data integrity, authentication, and state verification.

Start by cataloging the five or six fundamental actions a business user actually performs every day—checking stock, updating order status, issuing a receipt, searching customer history. Expose those as explicit, typed tools with strict validation. Do not give the model tools that can perform arbitrary database writes.

まとめと実践の要点

  • Never let an AI model act as the system of record; models handle reasoning, databases handle state.
  • Model Context Protocol (MCP) establishes deterministic, typed JSON-RPC boundaries that prevent unverified actions.
  • Tier context assembly into static merchant rules, temporal session state, and on-demand tool calls to maintain low token overhead.
  • Maintain an append-only audit log of every agent tool invocation for commercial accountability.

よくある疑問と解説

Why use MCP instead of traditional custom REST endpoints for AI tools?

Traditional REST endpoints often require writing bespoke glue code, manual serialization, and ad-hoc error parsing for every tool. MCP provides a standardized protocol with built-in capability discovery, schema validation, and structured error propagation that works consistently across different model providers and client runtimes.

Does using MCP completely prevent AI hallucinations?

MCP does not change the probabilistic nature of the language model itself, but it ensures that the model cannot alter business state without passing through strict schema validation and backend permissions. The agent can only mutate data through vetted, auditable tool contracts.

TAGS:MCPModel Context ProtocolAI AgentsTool CallingHamroLinkSystem Architecture