Skip to content

Commit 2bae83e

Browse files
authored
[Fix][DEVX-670] Fix Issues with Tools Configuration (#47)
1 parent ff09d10 commit 2bae83e

58 files changed

Lines changed: 241 additions & 279 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@commercetools/agent-essentials": patch
3+
"@commercetools/mcp-essentials": patch
4+
---
5+
6+
[Fix][DEVX-670] Fix Issues with Tools Configuration

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ To view information on how to develop the MCP server, see [this README](/typescr
4646
To view information on how to locally run the bootstrapped MCP server, see [this README](/modelcontextprotocol/README.md).
4747

4848

49+
> [!IMPORTANT]
50+
> To load all the available tools set `--tools=all` and `--isAdmin=true`, all the available tools will be loaded into the MCP server. To limit the number of loaded tools set `--tools=all.read` for read-only tools or `--tools=carts.read,quote.create,quote.read,...` To disable dynamic tools loading set the `dynamicToolLoadingThreshold` to a very high value e.g `--dynamicToolLoadingThreshold=650`.
51+
52+
To view information on how to develop the MCP server, see [this README](/typescript/README.md).<br>
53+
To view information on how to locally run the bootstrapped MCP server, see [this README](/modelcontextprotocol/README.md).
54+
4955
Refer to our [official public documentation](https://docs.commercetools.com/sdk/commerce-mcp/essentials-mcp) for a more advanced and comprehensive guide on how to get the most out of our MCP offerings.
5056

5157
<!--

modelcontextprotocol/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ export function parseArgs(args: string[]): {options: Options; env: EnvVars} {
184184
const [key, value] = arg.slice(2).split('=');
185185

186186
if (key == 'tools') {
187-
options.tools = value.split(',');
187+
options.tools = value.replace(/\s+/g, '').split(',');
188188
} else if (key == 'authType') {
189189
env.authType = value as EnvVars['authType'];
190190
} else if (key == 'accessToken') {
@@ -381,7 +381,7 @@ export async function main() {
381381
},
382382
};
383383

384-
if (selectedTools[0] === 'all') {
384+
if (options.isAdmin && selectedTools[0] === 'all') {
385385
ACCEPTED_TOOLS.forEach((tool) => {
386386
if (!configuration.actions) {
387387
configuration.actions = {};

typescript/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ import {generateText} from 'ai';
7979
import {openai} from '@ai-sdk/openai';
8080
import {CommercetoolsAgentEssentials} from '@commercetools/agent-essentials/ai-sdk';
8181

82-
const commercetoolsAgentEssentials = await CommercetoolsAgentEssentials({
82+
const commercetoolsAgentEssentials = new CommercetoolsAgentEssentials({
8383
authConfig: {
8484
type: 'client_credentials',
8585
clientId: process.env.CLIENT_ID!,,
@@ -136,7 +136,7 @@ Example:
136136
import {AgentExecutor, createStructuredChatAgent} from 'langchain/agents';
137137
import {CommercetoolsAgentEssentials} from '@commercetools/agent-essentials/langchain';
138138

139-
const commercetoolsAgentEssentials = await CommercetoolsAgentEssentials({
139+
const commercetoolsAgentEssentials = new CommercetoolsAgentEssentials({
140140
authConfig: {
141141
type: 'auth_token',
142142
accessToken: process.env.ACCESS_TOKEN!,

typescript/src/ai-sdk/__tests__/essentials.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jest.mock('../../shared/configuration', () => ({
1818
jest.mock('../../shared/tools', () => {
1919
const {z: localZ} = require('zod'); // Require z inside the factory
2020
return {
21-
contextToTools: (context: Context) => [
21+
contextToTools: (configuration: Configuration) => [
2222
{
2323
method: 'tool1',
2424
description: 'Description for tool 1',

typescript/src/ai-sdk/essentials.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class CommercetoolsAgentEssentials {
3131

3232
this.tools = {};
3333

34-
const filteredTools = contextToTools(processedConfiguration.context).filter(
34+
const filteredTools = contextToTools(processedConfiguration).filter(
3535
(tool) => isToolAllowed(tool, processedConfiguration)
3636
);
3737

typescript/src/langchain/__tests__/essentials.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import CommercetoolsTool from '../tool';
44
import {isToolAllowed} from '../../shared/configuration';
55
import {z} from 'zod';
66
import {DynamicStructuredTool} from '@langchain/core/tools';
7-
import {Context} from '../../types/configuration';
7+
import {Configuration, Context} from '../../types/configuration';
88

99
// Mock dependencies
1010
jest.mock('../../shared/api');
@@ -20,7 +20,7 @@ jest.mock('../../shared/tools', () => {
2020
// For this specific case, we can define it directly here.
2121
const {z: localZ} = require('zod'); // Require z inside the factory
2222
return {
23-
contextToTools: (context: Context) => [
23+
contextToTools: (configuration: Configuration) => [
2424
{
2525
method: 'lcTool1',
2626
name: 'lcTool1',
@@ -72,7 +72,8 @@ describe('CommercetoolsAgentEssentials (Langchain)', () => {
7272
beforeAll(() => {
7373
// Load the mocked definitions for use in tests
7474
const {contextToTools} = require('../../shared/tools');
75-
mockToolDefinitions = contextToTools({isAdmin: true});
75+
const _configuration = {context: {isAdmin: true}};
76+
mockToolDefinitions = contextToTools(_configuration);
7677
});
7778

7879
beforeEach(() => {

typescript/src/langchain/essentials.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class CommercetoolsAgentEssentials implements BaseToolkit {
3939
);
4040

4141
const filteredToolDefinitions = contextToTools(
42-
processedConfiguration.context
42+
processedConfiguration
4343
).filter((tool: ToolDefinition) =>
4444
isToolAllowed(tool, processedConfiguration)
4545
);

typescript/src/mastra/__tests__/essentials.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jest.mock('../../shared/configuration', () => ({
1919
jest.mock('../../shared/tools', () => {
2020
const {z: localZ} = require('zod');
2121
return {
22-
contextToTools: (context: Context) => [
22+
contextToTools: (configuration: Configuration) => [
2323
{
2424
method: 'tool1',
2525
description: 'Description for tool 1',

typescript/src/mastra/essentials.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class CommercetoolsAgentEssentials {
2828
processedConfiguration.context
2929
);
3030

31-
contextToTools(processedConfiguration.context)
31+
contextToTools(processedConfiguration)
3232
.filter((tool) => isToolAllowed(tool, processedConfiguration))
3333
.forEach((tool) => {
3434
this._tools[tool.method] = CommercetoolsTool(

0 commit comments

Comments
 (0)