Skip to main content
Glama
Leopards Courier MCP Server

Leopards Courier MCP Server

Leopards Courier MCP Server

An open-source Model Context Protocol (MCP) server for the Leopards Courier eCom Merchant API (v2.0). With it, an AI assistant such as Claude, Cursor or any other MCP client can book, track and manage Leopards shipments for you, using your own merchant account.

You can ask things like:

  • "Track KI1234567890 and tell me where it is."

  • "What would a 1.5 kg parcel from Karachi to Lahore with Rs 3,000 COD cost?"

  • "Book a packet for Ali Raza, 0300-1234567, House 12, DHA Lahore, Rs 2,500 COD."

  • "Which of last week's parcels are still undelivered? Re-attempt the ones in Lahore."

  • "Has Leopards paid me for these 10 CNs yet?"

This is a community project. It is not made, endorsed or supported by Leopards Courier Services.


Contents


Related MCP server: Shiprocket MCP

Features

  • 20 tools covering the Leopards merchant API: cities, booking (single and batch), tracking, cancellation, load sheets, shipper advice, COD payments, tariffs, shipping charges, invoices, proof of delivery and sub-shippers.

  • Bring your own credentials. The server stores no API keys. Each request carries the caller's own Leopards key and password, so one deployment can serve many merchants.

  • Streamable HTTP transport, stateless, so it runs on serverless platforms. It deploys to Vercel without changes.

  • Production and staging. One environment variable switches to the Leopards staging API for testing.

  • Clear errors. Leopards' own error messages are passed back to the assistant, and bad input (empty lists, more than 50 CNs, unknown advice statuses) is rejected before anything reaches Leopards.

Built with FastMCP 3, FastAPI and httpx.


How authentication works

Leopards authenticates every API call with an API key and an API password. This server does not keep either. The MCP client sends them with each request, and the server forwards them to Leopards for that one call.

The server reads credentials from the first of these that is present:

Method

How to send it

Bearer token (recommended)

Authorization: Bearer <api_key>:<api_password>

Separate headers

x-api-key: <api_key> and x-api-password: <api_password> (or x-leopards-api-key / x-leopards-api-password)

Query string (last resort)

https://<server>/mcp?api_key=<api_key>&api_password=<api_password>

Server fallback (private deployments only)

LEOPARDS_API_KEY and LEOPARDS_API_PASSWORD environment variables

In the bearer token, everything after the first colon is treated as the password, so passwords that contain : work.

If no credentials are found, tools return a message explaining how to supply them, and nothing is sent to Leopards.


Getting your Leopards API credentials

  1. Log in to your Leopards merchant portal account (via leopardscourier.com).

  2. Open API Settings → API Management.

  3. Generate an API key and choose an API password.

For testing, ask Leopards for staging credentials and run the server with LEOPARDS_ENV=staging (see Configuration). Staging bookings are not real shipments.


Quick start (run locally)

You need Python 3.10 or later.

git clone https://github.com/Muhammadzainattiq/leopards-mcp.git
cd leopards-mcp

python3 -m venv .venv
source .venv/bin/activate          # Windows: .venv\Scripts\activate
pip install -r requirements.txt uvicorn

uvicorn app:app --port 8000

The MCP endpoint is now http://127.0.0.1:8000/mcp. Opening http://127.0.0.1:8000/ shows a JSON summary of the server and its tools.

Check that it works:

# List the tools (no credentials needed)
python smoke_test.py

# Also call get_all_cities with your own credentials (read-only)
python smoke_test.py http://127.0.0.1:8000/mcp YOUR_API_KEY YOUR_API_PASSWORD --call

Deploy your own server on Vercel

The repo is ready for Vercel's Python runtime: app.py exposes a FastAPI app, and vercel.json sets a 60-second function timeout.

From the CLI:

npm i -g vercel
vercel deploy --prod

From the dashboard: fork this repo, then import it at vercel.com/new. Vercel detects FastAPI on its own.

Your MCP endpoint is https://<your-deployment>.vercel.app/mcp.

Leave LEOPARDS_API_KEY / LEOPARDS_API_PASSWORD unset on any deployment other people can reach. See Security notes.

Any host that runs an ASGI app works too (Render, Railway, Fly.io, a VPS, and so on). Run uvicorn app:app --host 0.0.0.0 --port $PORT.


Connect an MCP client

Replace <server> with http://127.0.0.1:8000 for a local server or your deployment URL, and fill in your own key and password.

Claude Code

claude mcp add --transport http leopards <server>/mcp \
  --header "Authorization: Bearer <api_key>:<api_password>"

Claude Desktop

Claude Desktop connects to remote servers through mcp-remote. Add this to claude_desktop_config.json (Settings → Developer → Edit Config):

{
  "mcpServers": {
    "leopards": {
      "command": "npx",
      "args": [
        "-y", "mcp-remote", "<server>/mcp",
        "--header", "Authorization: Bearer ${LEOPARDS_AUTH}"
      ],
      "env": { "LEOPARDS_AUTH": "<api_key>:<api_password>" }
    }
  }
}

Claude.ai (web) custom connector

Claude.ai connectors cannot send custom headers, so use the query-string form:

<server>/mcp?api_key=<api_key>&api_password=<api_password>

Read Security notes first: the credentials then sit inside the URL.

Cursor

Add to ~/.cursor/mcp.json (or .cursor/mcp.json in a project):

{
  "mcpServers": {
    "leopards": {
      "url": "<server>/mcp",
      "headers": { "Authorization": "Bearer <api_key>:<api_password>" }
    }
  }
}

VS Code (GitHub Copilot)

Add to .vscode/mcp.json:

{
  "servers": {
    "leopards": {
      "type": "http",
      "url": "<server>/mcp",
      "headers": { "Authorization": "Bearer <api_key>:<api_password>" }
    }
  }
}

Any other client, or your own code

Use the streamable HTTP transport and send one of the auth headers above. With the FastMCP Python client:

import asyncio
from fastmcp import Client

async def main():
    # A plain string is sent as "Authorization: Bearer <string>".
    async with Client("http://127.0.0.1:8000/mcp", auth="API_KEY:API_PASSWORD") as client:
        result = await client.call_tool("track_packets", {"track_numbers": ["KI1234567890"]})
        print(result.data)

asyncio.run(main())

Tools reference

Tools marked ⚠️ change real shipments or account data. MCP clients usually ask before running a tool. Read the arguments before you approve one of these.

Reference data

Tool

What it does

Arguments

get_all_cities

Lists every city with its numeric ID, shipment types, and whether it can be an origin or destination. Other tools need these IDs.

none

get_bank_list

Lists banks and their IDs, for create_shipper.

none

Booking and cancelling

Tool

What it does

Arguments

get_tariff_details

Quotes the charges for a packet before booking.

packet_weight (grams), shipment_type (ID), origin_city, destination_city, cod_amount (default 0)

⚠️ book_packet

Books one packet. Returns its tracking (CN) number and slip link.

packet, see Packet fields

⚠️ batch_book_packets

Books several packets in one call.

packets: a list of packets

⚠️ cancel_packets

Cancels booked packets.

cn_numbers: a list

Tracking and lookups

Tool

What it does

Arguments

track_packets

Current status and full tracking history.

track_numbers: a list

get_packet_last_statuses

Every packet booked in a date range, with its latest status.

from_date, to_date (yyyy-mm-dd)

get_shipment_details_by_order_ids

Finds shipments by your own order IDs.

order_ids: a list

get_proof_of_delivery

Receiver name and relation, GPS location, signature image.

cn_numbers: up to 50

Load sheets

Tool

What it does

Arguments

generate_load_sheet

Creates a load sheet for the courier picking up your parcels. Returns a load_sheet_id.

cn_numbers, courier_name, courier_code

download_load_sheet

Gets the sheet as a base64 PDF, or its packet data as JSON.

load_sheet_id, response_type: PDF (default) or JSON

Undelivered parcels (shipper advice)

Tool

What it does

Arguments

get_shipper_advice_list

Parcels waiting for your instruction after a failed delivery. Each has the id and cn_number that add_shipper_advices needs.

all optional: from_date, to_date, origin_city, destination_city, cn_number, product, status, start, length

⚠️ add_shipper_advices

Tells Leopards to re-attempt (RA) or return (RT) each parcel.

advices: a list of {id, cn_number, shipper_advice_status, shipper_remarks}

get_activity_log

Advice you have already given, and what happened.

all optional: cn_number, product, status, start, length

Money

Tool

What it does

Arguments

get_payment_details

Whether COD has been paid out, the amount, and invoice or cheque details.

cn_numbers: up to 50

get_shipping_charges

What Leopards charged for packets already booked.

cn_numbers: up to 50

get_invoices

Invoices and cheques Leopards has issued to you.

none

Sub-shippers

Tool

What it does

Arguments

⚠️ create_shipper

Creates a shipper under your account. Returns its shipment ID, which book_packet accepts as shipment_id.

shipment_name, shipment_phone, shipment_address, city_id, bank_id; optional: email, bank account details, cnic, return_address

get_shipper_details

Looks up shippers by a field.

request_param (e.g. shipment_id), request_value

Packet fields

Field names match the Leopards API exactly.

Field

Required

Notes

booked_packet_weight

yes

Grams, e.g. 2000 for 2 kg

booked_packet_no_piece

yes

Number of pieces

booked_packet_collect_amount

yes

COD amount; 0 for prepaid

origin_city

yes

City ID from get_all_cities, or self for your account's city

destination_city

yes

City ID, or self

consignment_name_eng

yes

Customer name

consignment_phone

yes

Customer phone

consignment_address

yes

Customer address

special_instructions

yes

Note for the rider

shipment_name_eng, shipment_email, shipment_phone, shipment_address

no

Sender details. Default self uses your account's details

booked_packet_order_id

no

Your own order ID; lets you look the packet up later

booked_packet_vol_weight_w / _h / _l

no

Volumetric dimensions

shipment_id

no

Book on behalf of a sub-shipper

consignment_email, consignment_phone_two, consignment_phone_three

no

Extra customer contacts

shipment_type

no

Defaults to overnight

return_address, return_city

no

Default to the sender's

custom_data

no

Extra key/value pairs, e.g. [{"key1": "value1"}]

is_vpc

no

1 for VPC; booked_packet_order_id must then be a CN number

Every tool returns Leopards' response as-is: a status / error envelope plus the data. A Leopards error comes back as a tool error that contains Leopards' own message.


Configuration

All settings are environment variables, and all are optional. See .env.example.

Variable

Default

Purpose

LEOPARDS_ENV

production

staging uses https://merchantapistaging.leopardscourier.com/api

LEOPARDS_BASE_URL

per LEOPARDS_ENV

Overrides the API base URL completely

LEOPARDS_TIMEOUT

30

Seconds to wait for Leopards on each call

LEOPARDS_API_KEY

unset

Fallback key for requests that bring none. Private deployments only

LEOPARDS_API_PASSWORD

unset

Fallback password. Private deployments only


Security notes

  • Never set the fallback credentials on a shared or public deployment. Anyone who finds the URL could then book and cancel shipments on that account. The landing page (GET /) reports shared_fallback_credentials_configured, so you can check.

  • Prefer headers to the query string. URLs are written to server, proxy and browser logs. Use the query-string form only for clients that cannot send headers, and only on a server you run yourself.

  • The server keeps nothing. Credentials are read from each request, forwarded to Leopards over HTTPS and discarded. They are never stored, cached or logged by this code. Your hosting platform's request logs are a separate matter.

  • If you use someone else's deployment, you are trusting its operator with your credentials. Running your own copy takes a few minutes.

  • Staging first. Try booking and cancelling on staging credentials before you point an assistant at your live account.

Found a security problem? Please open a GitHub issue without exploit details, or contact the maintainer privately.


Troubleshooting

Symptom

Likely cause

No Leopards API credentials were supplied

Your client isn't sending the header. Check the config, and that the bearer value is key:password with a colon.

Invalid API Key

Wrong key or password, or staging credentials on production (or the reverse). Check LEOPARDS_ENV.

Leopards returned a non-JSON response ... HTTP 404/405

Leopards changed or removed that endpoint. Please open an issue with the tool name.

Timeouts

Leopards is slow or down. Raise LEOPARDS_TIMEOUT, and on Vercel maxDuration in vercel.json.

A city name is rejected

Booking needs numeric city IDs. Ask the assistant to call get_all_cities first.

Differences from the official guide

The live API doesn't always match the Leopards v2 PDF guide. This server follows the live API:

  • Batch booking uses batchBookPackets. The guide's batchBookPacketv2 / batchBookPacketsv2 URLs return 404 on both production and staging.

  • getBankList only accepts GET. The guide's sample uses POST, which returns 405.

  • shipperAdviceList is documented with two different request shapes. The server sends both sets of fields so either backend version reads the filters.


Project structure

.
├── app.py               # ASGI entry point: FastAPI app, mounts MCP at /mcp
├── leopards/
│   ├── server.py        # MCP tools, one per Leopards endpoint
│   ├── client.py        # async HTTP client and response normalisation
│   └── config.py        # environment configuration
├── smoke_test.py        # connect, list tools, optionally call get_all_cities
├── requirements.txt
├── vercel.json
└── .env.example

Contributing

Issues and pull requests are welcome, especially reports of Leopards API behaviour that differs from what this server expects.

  1. Fork the repo and create a branch.

  2. Make the change. Keep one tool per Leopards endpoint, and use Leopards' field names.

  3. Run the server locally and check your change with smoke_test.py, using staging credentials for anything that books, cancels or changes data.

  4. Open a pull request describing what you changed and how you tested it.


License

MIT. Leopards Courier and its API belong to Leopards Courier Services (Pvt) Ltd; this project only calls their public merchant API.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Community MCP wrapper for TCS Courier public APIs, enabling courier service interactions through natural language.
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI agents to track packages, rate and create shipments, manage pickups and customs documentation, and perform international shipping logistics checks through natural language.
      MIT
    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables merchants to connect their PostEx account to MCP clients, exposing tools to book and cancel COD orders, track parcels, generate load sheets and airway bills, and check settlement status using their own PostEx token.
      2
      -