Skip to content

Commit b0ca3a0

Browse files
authored
Return endpoint usage for OAuth Client (#45)
1 parent ead1a9d commit b0ca3a0

File tree

9 files changed

+29
-27
lines changed

9 files changed

+29
-27
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ A Model Context Protocol (MCP) server for Genesys Cloud's Platform API.
1818
| [Search Voice Conversation](/docs/tools.md#search-voice-conversations) | Searches voice conversations by optional criteria |
1919
| [Conversation Transcript](/docs/tools.md#conversation-transcript) | Retrieves conversation transcript |
2020
| [OAuth Clients](/docs/tools.md#oauth-clients) | Retrieves a list of all the OAuth clients |
21-
| [OAuth Client Usage](/docs/tools.md#oauth-client-usage) | Retrieves usage of an OAuth client |
21+
| [OAuth Client Usage](/docs/tools.md#oauth-client-usage) | Retrieves OAuth client usage for given period |
2222

2323
## Usage with Claude Desktop
2424

docs/tools.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ Platform API endpoints used:
242242

243243
**Tool name:** `oauth_client_usage`
244244

245-
Retrieves the usage of an OAuth Client for a given period. It returns the total number of requests and a breakdown of requests per organization.
245+
Retrieves the usage of an OAuth Client for a given period. It returns the total number of requests and a breakdown of Platform API endpoints used by the client.
246246

247247
[Source file](/src/tools/oauthClientUsage/oauthClientUsage.ts).
248248

manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifest_version": "0.2",
33
"name": "Genesys Cloud MCP Server",
4-
"version": "1.0.2",
4+
"version": "1.0.3",
55
"description": "Interact with Genesys Cloud's Platform API",
66
"long_description": "This extension allows Claude to connect to Genesys Cloud's Platform API via a local MCP server. It provides tools for querying queue volumes, retrieving conversation samples, analyzing sentiment and voice quality, accessing transcripts, and more.\n\nThis project is not affiliated with Genesys.",
77
"author": {
@@ -62,7 +62,7 @@
6262
},
6363
{
6464
"name": "oauth_client_usage",
65-
"description": "Retrieves the usage of an OAuth Client for a given period. It returns the total number of requests and a breakdown of requests per organization."
65+
"description": "Retrieves the usage of an OAuth Client for a given period. It returns the total number of requests and a breakdown of Platform API endpoints used by the client."
6666
}
6767
],
6868
"user_config": {

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@makingchatbots/genesys-cloud-mcp-server",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "A Model Context Protocol (MCP) server exposing Genesys Cloud tools for LLMs, including sentiment analysis, conversation search, topic detection and more.",
55
"bin": "./dist/cli.js",
66
"type": "module",

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const withAuth = OAuthClientCredentialsWrapper(
2525

2626
const server: McpServer = new McpServer({
2727
name: "Genesys Cloud",
28-
version: "1.0.2", // Same version as version in package.json
28+
version: "1.0.3", // Same version as version in package.json
2929
});
3030

3131
const cache = new LRUCache<string, OAuthClientUsageResponse>({

src/tools/oauthClientUsage/oauthClientUsage.test.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ describe("OAuth Client Usage", () => {
1818
postOauthClientUsageQuery: vi.fn(),
1919
getOauthClientUsageQueryResult: vi.fn(),
2020
},
21+
cache: undefined,
2122
};
2223
const toolDefinition = oauthClientUsage(toolDeps);
2324
toolName = toolDefinition.schema.name;
@@ -48,7 +49,7 @@ describe("OAuth Client Usage", () => {
4849
_meta: undefined,
4950
annotations: { title: "OAuth Client Usage" },
5051
description:
51-
"Retrieves the usage of an OAuth Client for a given period. It returns the total number of requests and a breakdown of requests per organization.",
52+
"Retrieves the usage of an OAuth Client for a given period. It returns the total number of requests and a breakdown of Platform API endpoints used by the client.",
5253
inputSchema: {
5354
properties: {
5455
oauthClientId: {
@@ -141,8 +142,6 @@ describe("OAuth Client Usage", () => {
141142
test("OAuth Client usage returned for date range", async () => {
142143
const oauthClientId = randomUUID();
143144
const executionId = randomUUID();
144-
const organisationOneId = randomUUID();
145-
const organisationTwoId = randomUUID();
146145

147146
toolDeps.oauthApi.postOauthClientUsageQuery.mockResolvedValue({
148147
executionId,
@@ -152,11 +151,13 @@ describe("OAuth Client Usage", () => {
152151
toolDeps.oauthApi.getOauthClientUsageQueryResult.mockResolvedValue({
153152
results: [
154153
{
155-
organizationId: organisationOneId,
154+
templateUri: "api/v2/authorization/divisions",
155+
httpMethod: "GET",
156156
requests: 5,
157157
},
158158
{
159-
organizationId: organisationTwoId,
159+
templateUri: "api/v2/authorization/roles",
160+
httpMethod: "GET",
160161
requests: 10,
161162
},
162163
],
@@ -181,14 +182,14 @@ describe("OAuth Client Usage", () => {
181182
text: JSON.stringify({
182183
startDate,
183184
endDate,
184-
totalRequest: 15,
185-
requestsPerOrganisation: [
185+
totalRequests: 15,
186+
requestsPerEndpoint: [
186187
{
187-
organisationId: organisationOneId,
188+
endpoint: "GET api/v2/authorization/divisions",
188189
requests: 5,
189190
},
190191
{
191-
organisationId: organisationTwoId,
192+
endpoint: "GET api/v2/authorization/roles",
192193
requests: 10,
193194
},
194195
],

src/tools/oauthClientUsage/oauthClientUsage.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import { isUnauthorisedError } from "../utils/genesys/isUnauthorisedError.js";
77
import { waitFor } from "../utils/waitFor.js";
88

99
const MAX_ATTEMPTS = 10;
10-
const TOOL_CACHE_KEY = "oauthClientUsage";
10+
const TOOL_CACHE_KEY = "oauth-client-usage";
1111

1212
export interface OAuthClientUsageResponse {
1313
startDate: string;
1414
endDate: string;
15-
totalRequest: number;
16-
requestsPerOrganisation: {
17-
organisationId?: string;
15+
totalRequests: number;
16+
requestsPerEndpoint: {
17+
endpoint?: string;
1818
requests?: number;
1919
}[];
2020
}
@@ -55,7 +55,7 @@ export const oauthClientUsage: ToolFactory<
5555
name: "oauth_client_usage",
5656
annotations: { title: "OAuth Client Usage" },
5757
description:
58-
"Retrieves the usage of an OAuth Client for a given period. It returns the total number of requests and a breakdown of requests per organization.",
58+
"Retrieves the usage of an OAuth Client for a given period. It returns the total number of requests and a breakdown of Platform API endpoints used by the client.",
5959
paramsSchema,
6060
},
6161
call: async ({ oauthClientId, startDate, endDate }) => {
@@ -91,7 +91,7 @@ export const oauthClientUsage: ToolFactory<
9191
result = await oauthApi.postOauthClientUsageQuery(oauthClientId, {
9292
interval: `${from.toISOString()}/${to.toISOString()}`,
9393
metrics: ["Requests"],
94-
groupBy: ["OrganizationId"],
94+
groupBy: ["TemplateUri", "HttpMethod"],
9595
});
9696
} catch (error: unknown) {
9797
const errorMessage = isUnauthorisedError(error)
@@ -147,13 +147,14 @@ export const oauthClientUsage: ToolFactory<
147147
const toolResult: OAuthClientUsageResponse = {
148148
startDate,
149149
endDate,
150-
totalRequest: (apiUsageQueryResult?.results ?? []).reduce(
150+
totalRequests: (apiUsageQueryResult?.results ?? []).reduce(
151151
(acc, curr) => acc + (curr.requests ?? 0),
152152
0,
153153
),
154-
requestsPerOrganisation: (apiUsageQueryResult?.results ?? []).map(
154+
requestsPerEndpoint: (apiUsageQueryResult?.results ?? []).map(
155155
(result) => ({
156-
organisationId: result.organizationId,
156+
endpoint:
157+
[result.httpMethod, result.templateUri].join(" ") || undefined,
157158
requests: result.requests,
158159
}),
159160
),

tests/integration/serverRuns.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ describe("Server Runs", () => {
8181

8282
client = new Client({
8383
name: "test-client",
84-
version: "1.0.2",
84+
version: "1.0.3",
8585
});
8686

8787
await client.connect(transport);

0 commit comments

Comments
 (0)