DEV Community

JustRouting
JustRouting

Posted on

Build a Delivery AI Agent with MCP and Routing APIs

AI agents are getting better at understanding requests, reasoning about problems, and completing complex tasks.

But real-world operations need more than language.

A delivery assistant needs to answer questions like:

  • Which driver should handle this order?
  • How long will delivery take?
  • What is the most efficient route?
  • How should multiple vehicles be assigned?

These are not text problems.

They are routing problems.

In this tutorial, we will build a delivery AI agent that uses the Model Context Protocol (MCP) to access routing capabilities.

The agent will be able to:

  • convert addresses into coordinates
  • compare drivers by travel time
  • calculate routes
  • optimize multiple deliveries

The final architecture:

flowchart TD
    U[User Request]
        --> A[AI Agent]

    A --> M[MCP Server]

    M --> G[Geocoding]
    M --> R[Routing]
    M --> O[Optimization]

    G --> J[JustRouting API]
    R --> J
    O --> J

The stack:

  • MCP for connecting AI agents with tools
  • JustRouting MCP server for routing capabilities
  • Southeast Asia routing data

Why delivery agents need routing tools

A language model can understand:

"Which driver should deliver this order?"

But it does not know:

  • road distances
  • travel times
  • geographic relationships
  • delivery optimization

The AI agent decides what to do.

The routing system calculates what is physically possible.

LLM = reasoning

Routing engine = transportation intelligence
Enter fullscreen mode Exit fullscreen mode

This separation is important.

The AI agent handles:

  • user intent
  • business rules
  • decision making

The routing layer handles:

  • maps
  • distances
  • travel time
  • optimization

Install the MCP routing server

JustRouting provides an MCP server that exposes Southeast Asia routing capabilities to AI clients.

Install:

curl -fsSL https://raw.githubusercontent.com/justrouting/mcp/main/install.sh | sh
Enter fullscreen mode Exit fullscreen mode

Configure your MCP client:

{
  "mcpServers": {
    "justrouting": {
      "command": "justrouting-mcp",
      "env": {
        "JUSTROUTING_API_KEY": "YOUR_API_KEY"
      }
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

The MCP server provides four tools:

Tool Purpose
geocode Convert addresses into coordinates
route Calculate routes
table Compare travel times
optimize Plan vehicle routes

Example 1: Assign the closest driver

A dispatcher asks:

Assign the closest driver to Mondrian Singapore Duxton.

Available drivers:

D1: Marina Bay Sands
D2: Waterford Residence
D3: IKEA Alexandra
D4: VivoCity
Enter fullscreen mode Exit fullscreen mode

The AI agent creates a workflow:

flowchart LR
    A[Customer Address]
        --> B[Geocode]

    B --> C[Calculate Travel Times]

    C --> D[Compare Drivers]

    D --> E[Recommend Driver]

The routing result:

Driver   Location              Distance    Drive time

D1       Marina Bay Sands      3.60 km     ~8 min
D2       Waterford Residence   2.78 km     ~6 min
D3       IKEA Alexandra        5.33 km     ~13 min
D4       VivoCity              3.30 km     ~7 min
Enter fullscreen mode Exit fullscreen mode

The agent responds:

Assign D2.

Reason:
- Shortest driving distance: 2.78 km
- Estimated arrival: ~6 minutes
Enter fullscreen mode Exit fullscreen mode

The AI agent handles the business question:

"Who should deliver this order?"

The routing layer provides the transportation intelligence:

"These are the actual driving costs."


Example 2: Route planning

A user asks:

How long does it take to drive from Marina Bay Sands Singapore to Changi Airport?

The AI agent calls the route tool.

Result:

Distance:
~19.1 km

Duration:
~23 minutes

Main roads:
East Coast Parkway
Airport Boulevard
Enter fullscreen mode Exit fullscreen mode

The agent can explain:

The fastest driving route takes about 23 minutes.

The route uses ECP and Airport Boulevard.
ERP charges may apply.
Enter fullscreen mode Exit fullscreen mode

The user asks:

What if I'm riding a motorcycle?

The agent changes routing profiles:

Car:

Distance: ~19.1 km
Time: ~23.6 min


Motorcycle:

Distance: ~19.1 km
Time: ~26.5 min
Enter fullscreen mode Exit fullscreen mode

The user adds:

What if I want to avoid tolls?

The agent applies a routing constraint:

Motorcycle with tolls:

Distance: ~19.1 km
Time: ~26.5 min


Motorcycle without tolls:

Distance: ~21.6 km
Time: ~35 min
Enter fullscreen mode Exit fullscreen mode

The AI agent understands:

  • "drive" → driving profile
  • "motorcycle" → motorcycle profile
  • "avoid tolls" → routing constraint

The routing layer handles the geography.


Example 3: Fleet optimization

Single-driver dispatch is useful.

But real logistics problems are more complex.

A dispatcher asks:

I have two vans and six pickup locations. Create today's routes.

Vehicles:

V1: 249 Sixth Ave, Singapore

V2: 8 Harlyn Rd, Singapore
Enter fullscreen mode Exit fullscreen mode

Customers:

C1: 75 Jln Kelabu Asap

C2: 20 Mount Sinai Rd

C3: 10 Bin Tong Park

C4: 9 Cluny Park

C5: 28 Nassim Rd

C6: 30 Chancery Ln
Enter fullscreen mode Exit fullscreen mode

The AI agent calls:

optimize
Enter fullscreen mode Exit fullscreen mode

The optimization engine returns:

Van V1

Start: 249 Sixth Ave

Route: C2 → C1 → C3

Total: ~19.4 minutes
Enter fullscreen mode Exit fullscreen mode

and:

Van V2

Start: 8 Harlyn Rd

Route: C6 → C5 → C4

Total: ~29.0 minutes
Enter fullscreen mode Exit fullscreen mode

Final answer:

All six deliveries assigned.

No customer left unserved.

Combined fleet driving time:

~48.5 minutes.
Enter fullscreen mode Exit fullscreen mode

The AI agent does not manually solve the vehicle routing problem.

It delegates mathematical optimization to a specialized routing engine.


The complete delivery AI architecture

flowchart TD
    U[User]
        --> A[AI Agent]

    A --> M[MCP Server]

    M --> G[Geocode]
    M --> R[Route]
    M --> T[Travel Time Matrix]
    M --> O[Optimize]

    G --> J[JustRouting]
    R --> J
    T --> J
    O --> J

Each component has a clear responsibility.

AI Agent

Understands:

  • user requests
  • business rules
  • priorities

MCP

Provides:

  • standardized tool access
  • discoverable capabilities

Routing API

Handles:

  • maps
  • distances
  • travel times
  • optimization

Why MCP changes application architecture

Before MCP:

AI application

      |

Custom integration

      |

External services
Enter fullscreen mode Exit fullscreen mode

Every AI application needs to build its own connectors.

With MCP:

flowchart TD
    A[AI Application]
        --> M[MCP Tools]

    M --> C[Reusable Capabilities]

    C --> R[Routing]
    C --> S[Search]
    C --> P[Payments]

A routing server becomes a reusable capability that can be used by:

  • delivery agents
  • fleet assistants
  • travel planners
  • field service systems
  • logistics copilots

Beyond delivery

The same pattern applies to many physical-world applications.

Ride-hailing

Question:

Which driver should accept this passenger?

Needs:

  • geocoding
  • ETA calculation
  • distance comparison

Field service

Question:

Which technician should visit this customer?

Needs:

  • location matching
  • scheduling
  • routing

Emergency response

Question:

Which vehicle can arrive fastest?

Needs:

  • route calculation
  • travel-time estimation

Build AI applications that understand the physical world

Large language models provide reasoning.

MCP provides tool access.

Routing provides location intelligence.

Together they enable AI systems that can make decisions in the real world.

A delivery AI agent is not just a chatbot.

It is a system that can:

  • understand a request
  • call specialized tools
  • evaluate options
  • take action

The next generation of logistics software will not only show routes.

It will reason about movement.


Learn more:

Top comments (0)