Skip to content

Commit a359ea8

Browse files
authored
Refactor tests and improve tool schemas (#15)
* Refactored high level tests to lower level so I can mock dependencies * Improved tool schemas
1 parent dc8331e commit a359ea8

22 files changed

+1485
-606
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@makingchatbots/genesys-cloud-mcp-server",
3-
"version": "0.0.4",
3+
"version": "0.0.5",
44
"description": "A MCP server for connecting LLMs to Genesys Cloud's Platform API",
55
"exports": "./dist/index.js",
66
"type": "module",
@@ -19,8 +19,9 @@
1919
"scripts": {
2020
"dev": "tsx watch src/index.ts",
2121
"start": "tsx src/index.ts",
22+
"start:inspector": "npm run build && npx @modelcontextprotocol/inspector node dist/index.js",
2223
"clean": "rm -rf dist/*",
23-
"build:esm": "tsc",
24+
"build:esm": "tsc -p tsconfig.build.json",
2425
"build": "npm run clean && npm run build:esm",
2526
"lint": "eslint . --ext .ts",
2627
"format": "prettier --write .",

src/index.ts

Lines changed: 38 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -22,84 +22,72 @@ const server: McpServer = new McpServer({
2222
version: "0.0.1",
2323
});
2424

25-
const searchQueuesTool = searchQueues({
26-
routingApi: new platformClient.RoutingApi(),
27-
});
25+
const routingApi = new platformClient.RoutingApi();
26+
const analyticsApi = new platformClient.AnalyticsApi();
27+
const speechTextAnalyticsApi = new platformClient.SpeechTextAnalyticsApi();
28+
29+
const searchQueuesTool = searchQueues({ routingApi });
2830
server.tool(
2931
searchQueuesTool.schema.name,
3032
searchQueuesTool.schema.description,
3133
searchQueuesTool.schema.paramsSchema.shape,
32-
config.mockingEnabled
33-
? searchQueuesTool.mockCall
34-
: withAuth(
35-
searchQueuesTool.call,
36-
config.genesysCloud,
37-
platformClient.ApiClient.instance,
38-
),
34+
withAuth(
35+
searchQueuesTool.call,
36+
config.genesysCloud,
37+
platformClient.ApiClient.instance,
38+
),
3939
);
4040

41-
const queryConversationsByQueueTool = sampleConversationsByQueue({
42-
analyticsApi: new platformClient.AnalyticsApi(),
41+
const sampleConversationsByQueueTool = sampleConversationsByQueue({
42+
analyticsApi,
4343
});
4444
server.tool(
45-
queryConversationsByQueueTool.schema.name,
46-
queryConversationsByQueueTool.schema.description,
47-
queryConversationsByQueueTool.schema.paramsSchema.shape,
48-
config.mockingEnabled
49-
? queryConversationsByQueueTool.mockCall
50-
: withAuth(
51-
queryConversationsByQueueTool.call,
52-
config.genesysCloud,
53-
platformClient.ApiClient.instance,
54-
),
45+
sampleConversationsByQueueTool.schema.name,
46+
sampleConversationsByQueueTool.schema.description,
47+
sampleConversationsByQueueTool.schema.paramsSchema.shape,
48+
withAuth(
49+
sampleConversationsByQueueTool.call,
50+
config.genesysCloud,
51+
platformClient.ApiClient.instance,
52+
),
5553
);
5654

57-
const queryQueueVolumesTool = queryQueueVolumes({
58-
analyticsApi: new platformClient.AnalyticsApi(),
59-
});
55+
const queryQueueVolumesTool = queryQueueVolumes({ analyticsApi });
6056
server.tool(
6157
queryQueueVolumesTool.schema.name,
6258
queryQueueVolumesTool.schema.description,
6359
queryQueueVolumesTool.schema.paramsSchema.shape,
64-
config.mockingEnabled
65-
? queryQueueVolumesTool.mockCall
66-
: withAuth(
67-
queryQueueVolumesTool.call,
68-
config.genesysCloud,
69-
platformClient.ApiClient.instance,
70-
),
60+
withAuth(
61+
queryQueueVolumesTool.call,
62+
config.genesysCloud,
63+
platformClient.ApiClient.instance,
64+
),
7165
);
7266

73-
const voiceCallQualityTool = voiceCallQuality({
74-
analyticsApi: new platformClient.AnalyticsApi(),
75-
});
67+
const voiceCallQualityTool = voiceCallQuality({ analyticsApi });
7668
server.tool(
7769
voiceCallQualityTool.schema.name,
7870
voiceCallQualityTool.schema.description,
7971
voiceCallQualityTool.schema.paramsSchema.shape,
80-
config.mockingEnabled
81-
? voiceCallQualityTool.mockCall
82-
: withAuth(
83-
voiceCallQualityTool.call,
84-
config.genesysCloud,
85-
platformClient.ApiClient.instance,
86-
),
72+
withAuth(
73+
voiceCallQualityTool.call,
74+
config.genesysCloud,
75+
platformClient.ApiClient.instance,
76+
),
8777
);
8878

8979
const conversationSentimentTool = conversationSentiment({
90-
speechTextAnalyticsApi: new platformClient.SpeechTextAnalyticsApi(),
80+
speechTextAnalyticsApi,
9181
});
9282
server.tool(
9383
conversationSentimentTool.schema.name,
9484
conversationSentimentTool.schema.description,
9585
conversationSentimentTool.schema.paramsSchema.shape,
96-
config.mockingEnabled
97-
? conversationSentimentTool.mockCall
98-
: withAuth(
99-
conversationSentimentTool.call,
100-
config.genesysCloud,
101-
platformClient.ApiClient.instance,
102-
),
86+
withAuth(
87+
conversationSentimentTool.call,
88+
config.genesysCloud,
89+
platformClient.ApiClient.instance,
90+
),
10391
);
10492

10593
const transport = new StdioServerTransport();

src/loadConfig.ts

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import { z } from "zod";
22

3-
export interface MockingConfig {
4-
readonly mockingEnabled: true;
5-
}
6-
7-
export interface RealConfig {
8-
readonly mockingEnabled: false;
3+
export interface Config {
94
readonly genesysCloud: {
105
readonly region: string;
116
readonly oAuthClientId: string;
@@ -15,7 +10,7 @@ export interface RealConfig {
1510

1611
export interface SuccessResult {
1712
success: true;
18-
config: MockingConfig | RealConfig;
13+
config: Config;
1914
}
2015

2116
export interface ErrorResult {
@@ -25,13 +20,6 @@ export interface ErrorResult {
2520

2621
export type Result = SuccessResult | ErrorResult;
2722

28-
const mockingConfigSchema = z.object({
29-
MOCKING_ENABLED: z
30-
.string()
31-
.transform((val) => val.toLowerCase() === "true")
32-
.default("false"),
33-
});
34-
3523
const genesysAuthConfigSchema = z.object({
3624
GENESYSCLOUD_REGION: z.string({
3725
required_error: "Missing environment variable: GENESYSCLOUD_REGION",
@@ -46,18 +34,6 @@ const genesysAuthConfigSchema = z.object({
4634
});
4735

4836
export function loadConfig(env: NodeJS.ProcessEnv): Result {
49-
const mockingConfig = mockingConfigSchema.safeParse(env);
50-
const mockingEnabled = Boolean(mockingConfig.data?.MOCKING_ENABLED);
51-
52-
if (mockingEnabled) {
53-
return {
54-
success: true,
55-
config: {
56-
mockingEnabled,
57-
},
58-
};
59-
}
60-
6137
const genesysAuthConfig = genesysAuthConfigSchema.safeParse(env);
6238
if (!genesysAuthConfig.success) {
6339
const failureReason = [
@@ -74,7 +50,6 @@ export function loadConfig(env: NodeJS.ProcessEnv): Result {
7450
return {
7551
success: true,
7652
config: {
77-
mockingEnabled,
7853
genesysCloud: {
7954
region: genesysAuthConfig.data.GENESYSCLOUD_REGION,
8055
oAuthClientId: genesysAuthConfig.data.GENESYSCLOUD_OAUTHCLIENT_ID,

0 commit comments

Comments
 (0)