@makingchatbots/genesys-cloud-mcp-server
Version:
A Model Context Protocol (MCP) server exposing Genesys Cloud tools for LLMs, including sentiment analysis, conversation search, topic detection and more.
104 lines (103 loc) • 4.27 kB
JavaScript
import { z } from "zod";
import { isUnauthorisedError } from "./utils/genesys/isUnauthorisedError.js";
import { createTool } from "./utils/createTool.js";
import { paginationSection } from "./utils/paginationSection.js";
function hasIdAndName(queue) {
return queue.id !== undefined && queue.name !== undefined;
}
function formatQueues(inputQueueName, queues, pagination) {
const queueItems = queues.flatMap((q) => [
`• Name: ${q.name}`,
` • ID: ${q.id}`,
...(q.description ? [` • Description: ${q.description}`] : []),
...(q.memberCount !== undefined
? [` • Member Count: ${String(q.memberCount)}`]
: []),
]);
const firstLine = pagination.totalHits !== undefined
? `Found ${String(pagination.totalHits)} queues matching "${inputQueueName}":`
: `Found the following queues matching "${inputQueueName}":`;
return [
firstLine,
...queueItems,
"",
...paginationSection("Total Matching Queues", pagination),
].join("\n");
}
const paramsSchema = z.object({
name: z
.string()
.min(1)
.describe("The name (or partial name) of the routing queue(s) to search for. Wildcards ('*') are supported for pattern matching (e.g., 'Support*', '*Emergency', '*Sales*'). Use '*' alone to retrieve all queues"),
pageNumber: z
.number()
.int()
.positive()
.optional()
.describe("The page number of the results to retrieve, starting from 1. Defaults to 1 if not specified. Used with 'pageSize' for navigating large result sets"),
pageSize: z
.number()
.int()
.positive()
.max(500)
.optional()
.describe("The maximum number of queues to return per page. Defaults to 100 if not specified. Used with 'pageNumber' for pagination. The maximum value is 500"),
});
export const searchQueues = ({ routingApi }) => createTool({
schema: {
name: "search_queues",
description: "Searches for routing queues based on their name, allowing for wildcard searches. Returns a paginated list of matching queues, including their Name, ID, Description (if available), and Member Count (if available). Also provides pagination details like current page, page size, total results found, and total pages available. Useful for finding specific queue IDs, checking queue configurations, or listing available queues.",
paramsSchema,
},
call: async ({ name, pageNumber = 1, pageSize = 100 }) => {
let result;
try {
result = await routingApi.getRoutingQueues({
name,
pageSize: pageSize,
pageNumber: pageNumber,
});
}
catch (error) {
const message = isUnauthorisedError(error)
? "Failed to search queues: Unauthorised access. Please check API credentials or permissions."
: `Failed to search queues: ${error instanceof Error ? error.message : JSON.stringify(error)}`;
return {
isError: true,
content: [
{
type: "text",
text: message,
},
],
};
}
const entities = result.entities ?? [];
if (entities.length === 0) {
return {
content: [
{
type: "text",
text: name === "*"
? "No routing queues found in the system."
: `No routing queues found matching the name pattern "${name}".`,
},
],
};
}
const foundQueues = entities.filter(hasIdAndName);
return {
content: [
{
type: "text",
text: formatQueues(name, foundQueues, {
pageNumber: result.pageNumber,
pageSize: result.pageSize,
pageCount: result.pageCount,
totalHits: result.total,
}),
},
],
};
},
});