feat(registry): add official MCP server.json and mcpName configuration
This commit is contained in:
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||
import type { CourierRegistry } from "../adapters/registry.js";
|
||||
export declare function registerTools(server: McpServer, registry: CourierRegistry): void;
|
||||
Vendored
+162
@@ -0,0 +1,162 @@
|
||||
/**
|
||||
* MCP tool definitions. Each tool validates input with zod, routes through the
|
||||
* registry to a courier adapter, and returns a normalized, human-readable result.
|
||||
* Adapter errors become clean tool errors — never raw crashes.
|
||||
*/
|
||||
import { z } from "zod";
|
||||
import { CourierError } from "../adapters/base.js";
|
||||
const courierEnum = z.enum(["steadfast", "pathao", "redx", "paperfly"]);
|
||||
function ok(data) {
|
||||
return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
|
||||
}
|
||||
function fail(err) {
|
||||
const e = err instanceof CourierError
|
||||
? { error: err.code, message: err.message, details: err.details }
|
||||
: { error: "unexpected", message: String(err) };
|
||||
return { isError: true, content: [{ type: "text", text: JSON.stringify(e, null, 2) }] };
|
||||
}
|
||||
export function registerTools(server, registry) {
|
||||
server.registerTool("list_couriers", {
|
||||
title: "List supported couriers",
|
||||
annotations: {
|
||||
readOnlyHint: true,
|
||||
destructiveHint: false,
|
||||
idempotentHint: true,
|
||||
openWorldHint: false,
|
||||
},
|
||||
description: "List every courier this connector supports and whether each is configured with credentials.",
|
||||
inputSchema: {},
|
||||
}, async () => {
|
||||
try {
|
||||
return ok({ couriers: registry.list() });
|
||||
}
|
||||
catch (err) {
|
||||
return fail(err);
|
||||
}
|
||||
});
|
||||
server.registerTool("create_parcel", {
|
||||
title: "Create a courier parcel (book a delivery)",
|
||||
annotations: {
|
||||
readOnlyHint: false,
|
||||
// A real, costed booking with the courier -- not trivially reversible from here, and
|
||||
// there's no local dedup: the adapter passes `invoice` straight through, so a retried
|
||||
// call is only as safe as the courier's own server-side handling of a repeat invoice.
|
||||
destructiveHint: true,
|
||||
idempotentHint: false,
|
||||
openWorldHint: true,
|
||||
},
|
||||
description: "Book a delivery with a Bangladesh courier. Returns the consignment id and tracking code. " +
|
||||
"COD amount is in BDT (use 0 for prepaid). The invoice must be unique per order — retrying " +
|
||||
"with the same invoice is NOT guaranteed to be safe; this connector does no local dedup. " +
|
||||
"Pathao also needs meta:{ storeId, cityId, zoneId, areaId } — resolve the IDs with get_courier_locations.",
|
||||
inputSchema: {
|
||||
courier: courierEnum.default("steadfast").describe("Which courier to book with."),
|
||||
invoice: z.string().min(1).describe("Your unique order/invoice id (idempotency key)."),
|
||||
recipientName: z.string().min(1),
|
||||
recipientPhone: z
|
||||
.string()
|
||||
.regex(/^01\d{9}$/, "Must be an 11-digit BD mobile number, e.g. 01700000000."),
|
||||
recipientAddress: z.string().min(1),
|
||||
codAmount: z.number().min(0).describe("Cash-on-delivery amount in BDT (0 = prepaid)."),
|
||||
itemDescription: z.string().optional(),
|
||||
note: z.string().optional(),
|
||||
meta: z
|
||||
.record(z.any())
|
||||
.optional()
|
||||
.describe("Courier-specific extras. Pathao: { storeId, cityId, zoneId, areaId }."),
|
||||
},
|
||||
}, async (args) => {
|
||||
try {
|
||||
const parcel = await registry.get(args.courier).createParcel(args);
|
||||
return ok(parcel);
|
||||
}
|
||||
catch (err) {
|
||||
return fail(err);
|
||||
}
|
||||
});
|
||||
server.registerTool("track_parcel", {
|
||||
title: "Track a parcel's delivery status",
|
||||
annotations: {
|
||||
readOnlyHint: true,
|
||||
destructiveHint: false,
|
||||
idempotentHint: true,
|
||||
openWorldHint: true,
|
||||
},
|
||||
description: "Look up the current delivery status of a parcel. Provide any ONE of: consignmentId, " +
|
||||
"invoice, or trackingCode.",
|
||||
inputSchema: {
|
||||
courier: courierEnum.default("steadfast"),
|
||||
consignmentId: z.string().optional(),
|
||||
invoice: z.string().optional(),
|
||||
trackingCode: z.string().optional(),
|
||||
},
|
||||
}, async (args) => {
|
||||
try {
|
||||
const result = await registry.get(args.courier).track({
|
||||
consignmentId: args.consignmentId,
|
||||
invoice: args.invoice,
|
||||
trackingCode: args.trackingCode,
|
||||
});
|
||||
return ok(result);
|
||||
}
|
||||
catch (err) {
|
||||
return fail(err);
|
||||
}
|
||||
});
|
||||
server.registerTool("get_balance", {
|
||||
title: "Get courier account balance",
|
||||
annotations: {
|
||||
readOnlyHint: true,
|
||||
destructiveHint: false,
|
||||
idempotentHint: true,
|
||||
openWorldHint: true,
|
||||
},
|
||||
description: "Get the merchant's current account balance with a courier (BDT).",
|
||||
inputSchema: {
|
||||
courier: courierEnum.default("steadfast"),
|
||||
},
|
||||
}, async (args) => {
|
||||
try {
|
||||
const adapter = registry.get(args.courier);
|
||||
if (!adapter.getBalance) {
|
||||
throw new CourierError("unsupported", `${adapter.label} has no balance endpoint.`);
|
||||
}
|
||||
return ok(await adapter.getBalance());
|
||||
}
|
||||
catch (err) {
|
||||
return fail(err);
|
||||
}
|
||||
});
|
||||
server.registerTool("get_courier_locations", {
|
||||
title: "Resolve courier location IDs (city / zone / area)",
|
||||
annotations: {
|
||||
readOnlyHint: true,
|
||||
destructiveHint: false,
|
||||
idempotentHint: true,
|
||||
openWorldHint: true,
|
||||
},
|
||||
description: "For couriers that address by structured location IDs (e.g. Pathao). Get the list of " +
|
||||
"cities, or the zones of a city (parentId = city id), or the areas of a zone (parentId = " +
|
||||
"zone id). Use the returned ids in create_parcel's meta for Pathao.",
|
||||
inputSchema: {
|
||||
courier: courierEnum.default("pathao"),
|
||||
level: z.enum(["city", "zone", "area"]),
|
||||
parentId: z
|
||||
.number()
|
||||
.optional()
|
||||
.describe("Required for zone (city id) and area (zone id)."),
|
||||
},
|
||||
}, async (args) => {
|
||||
try {
|
||||
const adapter = registry.get(args.courier);
|
||||
if (!adapter.getLocations) {
|
||||
throw new CourierError("unsupported", `${adapter.label} addresses by free text — no location IDs needed.`);
|
||||
}
|
||||
return ok({ locations: await adapter.getLocations(args.level, args.parentId) });
|
||||
}
|
||||
catch (err) {
|
||||
return fail(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=index.js.map
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGnD,MAAM,WAAW,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;AAExE,SAAS,EAAE,CAAC,IAAa;IACvB,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;AACvF,CAAC;AAED,SAAS,IAAI,CAAC,GAAY;IACxB,MAAM,CAAC,GACL,GAAG,YAAY,YAAY;QACzB,CAAC,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE;QACjE,CAAC,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;IACpD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;AACnG,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,MAAiB,EAAE,QAAyB;IACxE,MAAM,CAAC,YAAY,CACjB,eAAe,EACf;QACE,KAAK,EAAE,yBAAyB;QAChC,WAAW,EAAE;YACX,YAAY,EAAE,IAAI;YAClB,eAAe,E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