@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.
65 lines (64 loc) • 3.01 kB
JavaScript
import { z } from "zod";
import { createTool } from "../utils/createTool.js";
import { errorResult } from "../utils/errorResult.js";
import { isMissingPermissionsError } from "../utils/genesys/isMissingPermissionsError.js";
import { isUnauthorisedError } from "../utils/genesys/isUnauthorisedError.js";
import { formatOAuthClientJson } from "./formatOAuthClientJson.js";
const paramsSchema = z.object({});
export const oauthClients = ({ oauthApi, authorizationApi }) => createTool({
schema: {
name: "oauth_clients",
annotations: { title: "List OAuth Clients" },
description: "Retrieves a list of all OAuth clients, including their associated roles and divisions. This tool is useful for auditing and managing OAuth clients in the Genesys Cloud organization.",
paramsSchema,
},
call: async () => {
let result;
try {
result = await oauthApi.getOauthClients();
}
catch (error) {
const errorMessage = isUnauthorisedError(error)
? "Failed to retrieve list of all OAuth clients: Unauthorised access. Please check API credentials or permissions"
: `Failed to retrieve list of all OAuth clients: ${error instanceof Error ? error.message : JSON.stringify(error)}`;
return errorResult(errorMessage);
}
const entities = result.entities ?? [];
let divisions;
try {
// No logic to limit request size as divisions unlikely to be large
divisions = await authorizationApi.getAuthorizationDivisions({
pageSize: 99999,
});
}
catch (error) {
console.warn(isMissingPermissionsError(error)
? "Division names will not be populated.\nReason: Missing necessary permission."
: `Division names will not be populated.\nReason: Failed to retrieve list of divisions: ${error instanceof Error ? error.message : JSON.stringify(error)}`);
}
const roleIds = entities
.flatMap((e) => e.roleIds)
.filter((id) => id !== undefined);
let roles;
try {
roles = await authorizationApi.getAuthorizationRoles({
id: roleIds,
pageSize: roleIds.length,
});
}
catch (error) {
console.warn(isMissingPermissionsError(error)
? "Role names will not be populated.\nReason: Missing necessary permission."
: `Role names will not be populated.\nReason: Failed to retrieve list of roles: ${error instanceof Error ? error.message : JSON.stringify(error)}`);
}
const response = (result?.entities ?? []).map((e) => formatOAuthClientJson(e, divisions?.entities ?? [], roles?.entities ?? []));
return {
content: [
{
type: "text",
text: JSON.stringify(response),
},
],
};
},
});