Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .changeset/tricky-shrimps-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"@commercetools/commerce-agent": minor
---

Add missing tools
- approval-flow
- approval-rule
- associate-role
- order-edit
- product-selection-product
- recurrence-policy
- state
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,24 @@ Add the following to your `claude_desktop_config.json`. See [here](https://model

| Tool | Description |
| -------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| `approval-flow.read` | [Read Approval Flow](https://docs.commercetools.com/api/projects/approval-flows#query-approvalflows) |
| `approval-flow.update` | [Update Approval Flow](https://docs.commercetools.com/api/projects/approval-flows#update-approvalflow-by-id) |
| `approval-rule.read` | [Read Approval Rule](https://docs.commercetools.com/api/projects/approval-rules#query-approvalrules) |
| `approval-rule.create` | [Create Approval Rule](https://docs.commercetools.com/api/projects/approval-rules#create-approvalrule) |
| `approval-rule.update` | [Update Approval Rule](https://docs.commercetools.com/api/projects/approval-rules#update-approvalrule-by-id) |
| `associate-role.read` | [Read Associate Role](https://docs.commercetools.com/api/projects/associate-roles#query-associate-roles) |
| `associate-role.create` | [Create Associate Role](https://docs.commercetools.com/api/projects/associate-roles#create-associate-role) |
| `associate-role.update` | [Update Associate Role](https://docs.commercetools.com/api/projects/associate-roles#update-associate-role-by-id) |
| `order-edit.read` | [Read Order Edit](https://docs.commercetools.com/api/projects/order-edits#query-orderedits) |
| `order-edit.create` | [Create Order Edit](https://docs.commercetools.com/api/projects/order-edits#create-orderedit) |
| `order-edit.update` | [Update or Apply Order Edit](https://docs.commercetools.com/api/projects/order-edits#update-orderedit-by-id) |
| `product-selection-product.read` | [Read Products in Product Selection](https://docs.commercetools.com/api/projects/product-selections#query-productselection-products) |
| `recurrence-policy.read` | [Read Recurrence Policy](https://docs.commercetools.com/api/projects/recurrence-policies#query-recurrencepolicies) |
| `recurrence-policy.create` | [Create Recurrence Policy](https://docs.commercetools.com/api/projects/recurrence-policies#create-recurrencepolicy) |
| `recurrence-policy.update` | [Update Recurrence Policy](https://docs.commercetools.com/api/projects/recurrence-policies#update-recurrencepolicy-by-id) |
| `states.read` | [Read State](https://docs.commercetools.com/api/projects/states#query-states) |
| `states.create` | [Create State](https://docs.commercetools.com/api/projects/states#create-state) |
| `states.update` | [Update State](https://docs.commercetools.com/api/projects/states#update-state-by-id) |
| `products.read` | [Read product information](https://docs.commercetools.com/api/projects/products#query-products) |
| `products.create` | [Create product information](https://docs.commercetools.com/api/projects/products#create-product) |
| `products.update` | [Update product information](https://docs.commercetools.com/api/projects/products#update-product) |
Expand Down
2 changes: 1 addition & 1 deletion modelcontextprotocol/src/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@
'--apiUrl=https://api.commercetools.com',
];
expect(() => parseArgs(args)).toThrow(
'Invalid tool: invalid.tool. Accepted tools are: business-unit.read, business-unit.create, business-unit.update, products.read, products.create, products.update, project.read, product-search.read, category.read, category.create, category.update, channel.read, channel.create, channel.update, product-selection.read, product-selection.create, product-selection.update, order.read, order.create, order.update, cart.read, cart.create, cart.update, customer.create, customer.read, customer.update, customer-group.read, customer-group.create, customer-group.update, quote.read, quote.create, quote.update, quote-request.read, quote-request.create, quote-request.update, staged-quote.read, staged-quote.create, staged-quote.update, standalone-price.read, standalone-price.create, standalone-price.update, product-discount.read, product-discount.create, product-discount.update, cart-discount.read, cart-discount.create, cart-discount.update, discount-code.read, discount-code.create, discount-code.update, product-type.read, product-type.create, product-type.update, bulk.create, bulk.update, inventory.read, inventory.create, inventory.update, store.read, store.create, store.update'
`Invalid tool: invalid.tool. Accepted tools are: ${ACCEPTED_TOOLS.join(", ")}`

Check failure on line 660 in modelcontextprotocol/src/test/index.test.ts

View workflow job for this annotation

GitHub Actions / Linting

Replace `",·"` with `',·'`
);
});

Expand Down
7 changes: 7 additions & 0 deletions modelcontextprotocol/src/test/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ describe('main function', () => {
'custom-objects': {read: true, create: true, update: true},
'payment-intents': {update: true},
transactions: {read: true, create: true},
'approval-flow': {read: true, create: true, update: true},
'approval-rule': {read: true, create: true, update: true},
'associte-role': {read: true, create: true, update: true},
'order-edit': {read: true, create: true, update: true},
'product-selection-product': {read: true},
'recurrence-policy': {read: true, create: true, update: true},
states: {read: true, create: true, update: true},
},
context: {
isAdmin: true,
Expand Down
87 changes: 87 additions & 0 deletions typescript/src/shared/approval-flow/admin.functions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import {z} from 'zod';
import {ApiRoot, ApprovalFlowUpdateAction} from '@commercetools/platform-sdk';
import {SDKError} from '../errors/sdkError';
import {
readApprovalFlowById,
queryApprovalFlows,
updateApprovalFlowById,
} from './base.functions';
import {
readApprovalFlowParameters,
updateApprovalFlowParameters,
} from './parameters';

export const readApprovalFlow = async (
apiRoot: ApiRoot,
context: {projectKey: string},
params: z.infer<typeof readApprovalFlowParameters>
) => {
if (!params.customerId) {
throw new Error(
'customerId is required for admin approval flow operations'
);
}
if (!params.businessUnitKey) {
throw new Error(
'businessUnitKey is required for admin approval flow operations'
);
}

try {
if (params.id) {
return await readApprovalFlowById(
apiRoot,
context.projectKey,
params.customerId,
params.businessUnitKey,
params.id,
params.expand
);
}

return await queryApprovalFlows(
apiRoot,
context.projectKey,
params.customerId,
params.businessUnitKey,
params.where,
params.limit,
params.offset,
params.sort,
params.expand
);
} catch (error: any) {
throw new SDKError('Failed to read approval flow', error);
}
};

export const updateApprovalFlow = async (
apiRoot: ApiRoot,
context: {projectKey: string},
params: z.infer<typeof updateApprovalFlowParameters>
) => {
if (!params.customerId) {
throw new Error(
'customerId is required for admin approval flow operations'
);
}
if (!params.businessUnitKey) {
throw new Error(
'businessUnitKey is required for admin approval flow operations'
);
}

try {
return await updateApprovalFlowById(
apiRoot,
context.projectKey,
params.customerId,
params.businessUnitKey,
params.id,
params.version,
params.actions as ApprovalFlowUpdateAction[]
);
} catch (error: any) {
throw new SDKError('Failed to update approval flow', error);
}
};
84 changes: 84 additions & 0 deletions typescript/src/shared/approval-flow/associate.functions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import {z} from 'zod';
import {ApiRoot, ApprovalFlowUpdateAction} from '@commercetools/platform-sdk';
import {SDKError} from '../errors/sdkError';
import {CommercetoolsFuncContext} from '../../types/configuration';
import {
readApprovalFlowById,
queryApprovalFlows,
updateApprovalFlowById,
} from './base.functions';
import {
readApprovalFlowParameters,
updateApprovalFlowParameters,
} from './parameters';

export const readApprovalFlow = async (
apiRoot: ApiRoot,
context: CommercetoolsFuncContext,
params: z.infer<typeof readApprovalFlowParameters>
) => {
if (!context.customerId) {
throw new Error(
'Associate ID (customerId) is required for associate operations'
);
}
if (!context.businessUnitKey) {
throw new Error('Business Unit key is required for associate operations');
}

try {
if (params.id) {
return await readApprovalFlowById(
apiRoot,
context.projectKey,
context.customerId,
context.businessUnitKey,
params.id,
params.expand
);
}

return await queryApprovalFlows(
apiRoot,
context.projectKey,
context.customerId,
context.businessUnitKey,
params.where,
params.limit,
params.offset,
params.sort,
params.expand
);
} catch (error: any) {
throw new SDKError('Failed to read approval flow as associate', error);
}
};

export const updateApprovalFlow = async (
apiRoot: ApiRoot,
context: CommercetoolsFuncContext,
params: z.infer<typeof updateApprovalFlowParameters>
) => {
if (!context.customerId) {
throw new Error(
'Associate ID (customerId) is required for associate operations'
);
}
if (!context.businessUnitKey) {
throw new Error('Business Unit key is required for associate operations');
}

try {
return await updateApprovalFlowById(
apiRoot,
context.projectKey,
context.customerId,
context.businessUnitKey,
params.id,
params.version,
params.actions as ApprovalFlowUpdateAction[]
);
} catch (error: any) {
throw new SDKError('Failed to update approval flow as associate', error);
}
};
107 changes: 107 additions & 0 deletions typescript/src/shared/approval-flow/base.functions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import {ApiRoot, ApprovalFlowUpdateAction} from '@commercetools/platform-sdk';
import {SDKError} from '../errors/sdkError';

const getApprovalFlowsBuilder = (
apiRoot: ApiRoot,
projectKey: string,
customerId: string,
businessUnitKey: string
) =>
apiRoot
.withProjectKey({projectKey})
.asAssociate()
.withAssociateIdValue({associateId: customerId})
.inBusinessUnitKeyWithBusinessUnitKeyValue({businessUnitKey})
.approvalFlows();

export const readApprovalFlowById = async (
apiRoot: ApiRoot,
projectKey: string,
customerId: string,
businessUnitKey: string,
id: string,
expand?: string[]
) => {
try {
const response = await getApprovalFlowsBuilder(
apiRoot,
projectKey,
customerId,
businessUnitKey
)
.withId({ID: id})
.get({
queryArgs: {
...(expand && {expand}),
},
})
.execute();
return response.body;
} catch (error: any) {
throw new SDKError('Failed to read approval flow by ID', error);
}
};

export const queryApprovalFlows = async (
apiRoot: ApiRoot,
projectKey: string,
customerId: string,
businessUnitKey: string,
where?: string[],
limit?: number,
offset?: number,
sort?: string[],
expand?: string[]
) => {
try {
const response = await getApprovalFlowsBuilder(
apiRoot,
projectKey,
customerId,
businessUnitKey
)
.get({
queryArgs: {
...(where && {where}),
limit: limit ?? 10,
...(offset !== undefined && {offset}),
...(sort && {sort}),
...(expand && {expand}),
},
})
.execute();
return response.body;
} catch (error: any) {
throw new SDKError('Failed to query approval flows', error);
}
};

export const updateApprovalFlowById = async (
apiRoot: ApiRoot,
projectKey: string,
customerId: string,
businessUnitKey: string,
id: string,
version: number,
actions: ApprovalFlowUpdateAction[]
) => {
try {
const response = await getApprovalFlowsBuilder(
apiRoot,
projectKey,
customerId,
businessUnitKey
)
.withId({ID: id})
.post({
body: {
version,
actions,
},
})
.execute();
return response.body;
} catch (error: any) {
throw new SDKError('Failed to update approval flow by ID', error);
}
};
56 changes: 56 additions & 0 deletions typescript/src/shared/approval-flow/functions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import * as admin from './admin.functions';
import * as associate from './associate.functions';
import {CommercetoolsFuncContext, Context} from '../../types/configuration';
import {ApiRoot} from '@commercetools/platform-sdk';
import {z} from 'zod';
import {
readApprovalFlowParameters,
updateApprovalFlowParameters,
} from './parameters';

export const contextToApprovalFlowFunctionMapping = (
context?: Context
): Record<
string,
(
apiRoot: ApiRoot,
context: CommercetoolsFuncContext,
params: any
) => Promise<any>
> => {
if (context?.customerId && context?.businessUnitKey) {
return {
read_approval_flow: associate.readApprovalFlow,
update_approval_flow: associate.updateApprovalFlow,
};
}
if (context?.isAdmin) {
return {
read_approval_flow: admin.readApprovalFlow,
update_approval_flow: admin.updateApprovalFlow,
};
}
return {};
};

export const readApprovalFlow = (
apiRoot: ApiRoot,
context: any,
params: z.infer<typeof readApprovalFlowParameters>
) => {
if (context?.customerId && context?.businessUnitKey) {
return associate.readApprovalFlow(apiRoot, context, params);
}
return admin.readApprovalFlow(apiRoot, context, params);
};

export const updateApprovalFlow = (
apiRoot: ApiRoot,
context: any,
params: z.infer<typeof updateApprovalFlowParameters>
) => {
if (context?.customerId && context?.businessUnitKey) {
return associate.updateApprovalFlow(apiRoot, context, params);
}
return admin.updateApprovalFlow(apiRoot, context, params);
};
Loading
Loading