Skip to content

Commit 9b5c875

Browse files
committed
feat(mcp): update change customer func
1 parent 20ea012 commit 9b5c875

File tree

3 files changed

+32
-30
lines changed

3 files changed

+32
-30
lines changed

doit-mcp-server/src/app.ts

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -128,29 +128,16 @@ app.post("/customer-context", async (c) => {
128128
);
129129
}
130130

131-
if (!payload.DoitEmployee) {
132-
// request validation for non-doit employees
133-
const validatePromise = await handleValidateUserRequest({}, apiKey);
134-
const result = validatePromise.content[0].text;
135-
136-
if (!result.toLowerCase().includes(payload.sub)) {
137-
return await renderAuthorizationRejection(
138-
c,
139-
oauthReqInfo?.redirectUri || "/"
140-
);
141-
}
142-
143-
return await handleApprove(c);
144-
}
131+
const doitEmployeeContext = payload.DoitEmployee
132+
? {
133+
customerContext: "EE8CtpzYiKp0dVAESVrB",
134+
}
135+
: {};
145136

146-
// request validation for doit employees
147137
const validatePromise = await handleValidateUserRequest(
148-
{
149-
customerContext: "EE8CtpzYiKp0dVAESVrB",
150-
},
138+
doitEmployeeContext,
151139
apiKey
152140
);
153-
154141
const result = validatePromise.content[0].text;
155142

156143
if (!result.toLowerCase().includes(payload.sub)) {
@@ -160,6 +147,11 @@ app.post("/customer-context", async (c) => {
160147
);
161148
}
162149

150+
if (!payload.DoitEmployee) {
151+
// request validation for non-doit employees
152+
return await handleApprove(c);
153+
}
154+
163155
const content = await renderCustomerContextScreen(
164156
action,
165157
oauthReqInfo,

doit-mcp-server/src/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,21 @@ export class ContextStorage extends DurableObject {
6666
}
6767

6868
async saveContext(customerContext: string): Promise<void> {
69-
console.log("Saving customer context:", customerContext, this.ctx.id);
69+
console.log(
70+
"Saving customer context:",
71+
customerContext,
72+
this.ctx.id.toString().slice(-6)
73+
);
7074
await this.ctx.storage.put("customerContext", customerContext);
7175
}
7276

7377
async loadContext(): Promise<string | null> {
7478
const context = await this.ctx.storage.get<string>("customerContext");
75-
console.log("Loaded customer context:", context, this.ctx.id);
79+
console.log(
80+
"Loaded customer context:",
81+
context,
82+
this.ctx.id.toString().slice(-6)
83+
);
7684
return context || null;
7785
}
7886
}

src/tools/changeCustomer.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ export const ChangeCustomerArgumentsSchema = z.object({
1515
// Interfaces
1616
export interface ChangeCustomerResponse {
1717
success: boolean;
18-
previousContext?: string;
19-
newContext: string;
2018
message: string;
2119
}
2220

@@ -53,24 +51,28 @@ export async function handleChangeCustomerRequest(
5351

5452
const previousContext = args.customerContext;
5553

56-
// Update the customer context if callback is provided
57-
if (updateCustomerContext) {
58-
await updateCustomerContext(newContext);
59-
}
60-
6154
// Verify that the new context is valid
6255
const newCustomerDomain = await handleValidateUserRequest(
6356
{ customerContext: newContext }, // Validate doers
6457
token
6558
);
6659

60+
if (newCustomerDomain.content[0].text.toLowerCase().includes("failed")) {
61+
return createErrorResponse(
62+
"Customer context is invalid. Please try again with a valid customer id."
63+
);
64+
}
65+
66+
// Update the customer context if callback is provided
67+
if (updateCustomerContext) {
68+
await updateCustomerContext(newContext);
69+
}
70+
6771
const domain = newCustomerDomain.content[0].text.split("Domain: ")[1];
6872

6973
// Create response
7074
const response: ChangeCustomerResponse = {
7175
success: true,
72-
previousContext,
73-
newContext,
7476
message: `Customer context successfully changed to '${domain}'`,
7577
};
7678

0 commit comments

Comments
 (0)