@kontent-ai/mcp-server 0.4.2 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/README.md +127 -32
  2. package/build/bin.js +11 -7
  3. package/build/clients/kontentClients.js +12 -8
  4. package/build/schemas/contentItemSchemas.js +205 -0
  5. package/build/schemas/contentTypeSchemas.js +250 -127
  6. package/build/schemas/taxonomySchemas.js +11 -3
  7. package/build/server.js +22 -11
  8. package/build/tools/add-content-item-mapi.js +54 -0
  9. package/build/tools/add-content-type-mapi.js +35 -28
  10. package/build/tools/add-content-type-snippet-mapi.js +31 -29
  11. package/build/tools/add-taxonomy-group-mapi.js +14 -14
  12. package/build/tools/delete-content-item-mapi.js +24 -0
  13. package/build/tools/delete-language-variant-mapi.js +28 -0
  14. package/build/tools/get-asset-mapi.js +14 -14
  15. package/build/tools/get-item-dapi.js +13 -13
  16. package/build/tools/get-item-mapi.js +14 -14
  17. package/build/tools/get-taxonomy-group-mapi.js +14 -14
  18. package/build/tools/get-type-mapi.js +14 -14
  19. package/build/tools/get-type-snippet-mapi.js +16 -14
  20. package/build/tools/get-variant-mapi.js +17 -15
  21. package/build/tools/list-assets-mapi.js +10 -12
  22. package/build/tools/list-content-type-snippets-mapi.js +10 -12
  23. package/build/tools/list-content-types-mapi.js +10 -12
  24. package/build/tools/list-languages-mapi.js +10 -12
  25. package/build/tools/list-taxonomy-groups-mapi.js +11 -13
  26. package/build/tools/update-content-item-mapi.js +74 -0
  27. package/build/tools/upsert-language-variant-mapi.js +46 -0
  28. package/build/utils/errorHandler.js +87 -0
  29. package/build/utils/responseHelper.js +18 -0
  30. package/build/utils/throwError.js +3 -0
  31. package/package.json +13 -5
@@ -1,36 +1,38 @@
1
1
  import { z } from "zod";
2
- import { createMapiClient } from '../clients/kontentClients.js';
3
- import { snippetElementSchema, contentGroupSchema } from '../schemas/contentTypeSchemas.js';
2
+ import { createMapiClient } from "../clients/kontentClients.js";
3
+ import { snippetElementSchema } from "../schemas/contentTypeSchemas.js";
4
+ import { handleMcpToolError } from "../utils/errorHandler.js";
5
+ import { createMcpToolSuccessResponse } from "../utils/responseHelper.js";
4
6
  export const registerTool = (server) => {
5
7
  server.tool("add-content-type-snippet-mapi", "Add a new content type snippet via Management API", {
6
8
  name: z.string().describe("Display name of the content type snippet"),
7
- codename: z.string().optional().describe("Codename of the content type snippet (optional, will be generated if not provided)"),
8
- external_id: z.string().optional().describe("External ID of the content type snippet (optional)"),
9
- elements: z.array(snippetElementSchema).describe("Array of elements that define the structure of the content type snippet"),
10
- content_groups: z.array(contentGroupSchema).optional().describe("Array of content groups (optional)"),
11
- }, async ({ name, codename, external_id, elements, content_groups }) => {
9
+ codename: z
10
+ .string()
11
+ .optional()
12
+ .describe("Codename of the content type snippet (optional, will be generated if not provided)"),
13
+ external_id: z
14
+ .string()
15
+ .optional()
16
+ .describe("External ID of the content type snippet (optional)"),
17
+ elements: z
18
+ .array(snippetElementSchema)
19
+ .describe("Array of elements that define the structure of the content type snippet"),
20
+ }, async ({ name, codename, external_id, elements }) => {
12
21
  const client = createMapiClient();
13
- const response = await client
14
- .addContentTypeSnippet()
15
- .withData(() => ({
16
- name,
17
- codename,
18
- external_id,
19
- elements,
20
- content_groups: content_groups?.map(group => ({
21
- name: group.name,
22
- external_id: group.external_id,
23
- codename: group.codename
24
- })),
25
- }))
26
- .toPromise();
27
- return {
28
- content: [
29
- {
30
- type: "text",
31
- text: JSON.stringify(response.rawData),
32
- },
33
- ],
34
- };
22
+ try {
23
+ const response = await client
24
+ .addContentTypeSnippet()
25
+ .withData(() => ({
26
+ name,
27
+ codename,
28
+ external_id,
29
+ elements,
30
+ }))
31
+ .toPromise();
32
+ return createMcpToolSuccessResponse(response.rawData);
33
+ }
34
+ catch (error) {
35
+ return handleMcpToolError(error, "Content Type Snippet Creation");
36
+ }
35
37
  });
36
38
  };
@@ -1,19 +1,19 @@
1
- import { createMapiClient } from '../clients/kontentClients.js';
2
- import { taxonomyGroupSchemas } from '../schemas/taxonomySchemas.js';
1
+ import { createMapiClient } from "../clients/kontentClients.js";
2
+ import { taxonomyGroupSchemas } from "../schemas/taxonomySchemas.js";
3
+ import { handleMcpToolError } from "../utils/errorHandler.js";
4
+ import { createMcpToolSuccessResponse } from "../utils/responseHelper.js";
3
5
  export const registerTool = (server) => {
4
6
  server.tool("add-taxonomy-group-mapi", "Add a new taxonomy group via Management API", taxonomyGroupSchemas, async (taxonomyGroup) => {
5
7
  const client = createMapiClient();
6
- const response = await client
7
- .addTaxonomy()
8
- .withData(taxonomyGroup)
9
- .toPromise();
10
- return {
11
- content: [
12
- {
13
- type: "text",
14
- text: JSON.stringify(response.data),
15
- },
16
- ],
17
- };
8
+ try {
9
+ const response = await client
10
+ .addTaxonomy()
11
+ .withData(taxonomyGroup)
12
+ .toPromise();
13
+ return createMcpToolSuccessResponse(response.data);
14
+ }
15
+ catch (error) {
16
+ return handleMcpToolError(error, "Taxonomy Group Creation");
17
+ }
18
18
  });
19
19
  };
@@ -0,0 +1,24 @@
1
+ import { z } from "zod";
2
+ import { createMapiClient } from "../clients/kontentClients.js";
3
+ import { handleMcpToolError } from "../utils/errorHandler.js";
4
+ import { createMcpToolSuccessResponse } from "../utils/responseHelper.js";
5
+ export const registerTool = (server) => {
6
+ server.tool("delete-content-item-mapi", "Delete a content item by codename from Management API", {
7
+ codename: z.string().describe("Codename of the content item to delete"),
8
+ }, async ({ codename }) => {
9
+ const client = createMapiClient();
10
+ try {
11
+ const response = await client
12
+ .deleteContentItem()
13
+ .byItemCodename(codename)
14
+ .toPromise();
15
+ return createMcpToolSuccessResponse({
16
+ message: `Content item '${codename}' deleted successfully`,
17
+ deletedItem: response.data,
18
+ });
19
+ }
20
+ catch (error) {
21
+ return handleMcpToolError(error, "Content Item Deletion");
22
+ }
23
+ });
24
+ };
@@ -0,0 +1,28 @@
1
+ import { z } from "zod";
2
+ import { createMapiClient } from "../clients/kontentClients.js";
3
+ import { handleMcpToolError } from "../utils/errorHandler.js";
4
+ import { createMcpToolSuccessResponse } from "../utils/responseHelper.js";
5
+ export const registerTool = (server) => {
6
+ server.tool("delete-language-variant-mapi", "Delete a language variant of a content item from Management API", {
7
+ itemCodename: z.string().describe("Codename of the content item"),
8
+ languageCodename: z
9
+ .string()
10
+ .describe("Codename of the language variant to delete"),
11
+ }, async ({ itemCodename, languageCodename }) => {
12
+ const client = createMapiClient();
13
+ try {
14
+ const response = await client
15
+ .deleteLanguageVariant()
16
+ .byItemCodename(itemCodename)
17
+ .byLanguageCodename(languageCodename)
18
+ .toPromise();
19
+ return createMcpToolSuccessResponse({
20
+ message: `Language variant '${languageCodename}' of content item '${itemCodename}' deleted successfully`,
21
+ deletedVariant: response.data,
22
+ });
23
+ }
24
+ catch (error) {
25
+ return handleMcpToolError(error, "Language Variant Deletion");
26
+ }
27
+ });
28
+ };
@@ -1,21 +1,21 @@
1
1
  import { z } from "zod";
2
- import { createMapiClient } from '../clients/kontentClients.js';
2
+ import { createMapiClient } from "../clients/kontentClients.js";
3
+ import { handleMcpToolError } from "../utils/errorHandler.js";
4
+ import { createMcpToolSuccessResponse } from "../utils/responseHelper.js";
3
5
  export const registerTool = (server) => {
4
6
  server.tool("get-asset-mapi", "Get a specific asset by codename from Management API", {
5
- assetCodename: z.string().describe("Codename of the asset to retrieve")
7
+ assetCodename: z.string().describe("Codename of the asset to retrieve"),
6
8
  }, async ({ assetCodename }) => {
7
9
  const client = createMapiClient();
8
- const response = await client
9
- .viewAsset()
10
- .byAssetCodename(assetCodename)
11
- .toPromise();
12
- return {
13
- content: [
14
- {
15
- type: "text",
16
- text: JSON.stringify(response.data),
17
- },
18
- ],
19
- };
10
+ try {
11
+ const response = await client
12
+ .viewAsset()
13
+ .byAssetCodename(assetCodename)
14
+ .toPromise();
15
+ return createMcpToolSuccessResponse(response.data);
16
+ }
17
+ catch (error) {
18
+ return handleMcpToolError(error, "Asset Retrieval");
19
+ }
20
20
  });
21
21
  };
@@ -1,23 +1,23 @@
1
+ import { createDeliveryClient } from "@kontent-ai/delivery-sdk";
1
2
  import { z } from "zod";
2
- import { createDeliveryClient } from '@kontent-ai/delivery-sdk';
3
+ import { handleMcpToolError } from "../utils/errorHandler.js";
4
+ import { createMcpToolSuccessResponse } from "../utils/responseHelper.js";
3
5
  export const registerTool = (server) => {
4
6
  server.tool("get-item-dapi", "Get Kontent.ai item by codename from Delivery API", {
5
7
  codename: z.string().describe("Codename of the item to get"),
6
- environmentId: z.string().describe("Environment ID of the item's environment"),
8
+ environmentId: z
9
+ .string()
10
+ .describe("Environment ID of the item's environment"),
7
11
  }, async ({ codename, environmentId }) => {
8
12
  const client = createDeliveryClient({
9
13
  environmentId,
10
14
  });
11
- const response = await client
12
- .item(codename)
13
- .toPromise();
14
- return {
15
- content: [
16
- {
17
- type: "text",
18
- text: JSON.stringify(response.data.item),
19
- },
20
- ],
21
- };
15
+ try {
16
+ const response = await client.item(codename).toPromise();
17
+ return createMcpToolSuccessResponse(response.data.item);
18
+ }
19
+ catch (error) {
20
+ return handleMcpToolError(error, "Item Retrieval (Delivery API)");
21
+ }
22
22
  });
23
23
  };
@@ -1,21 +1,21 @@
1
1
  import { z } from "zod";
2
- import { createMapiClient } from '../clients/kontentClients.js';
2
+ import { createMapiClient } from "../clients/kontentClients.js";
3
+ import { handleMcpToolError } from "../utils/errorHandler.js";
4
+ import { createMcpToolSuccessResponse } from "../utils/responseHelper.js";
3
5
  export const registerTool = (server) => {
4
6
  server.tool("get-item-mapi", "Get Kontent.ai item by codename from Management API", {
5
- codename: z.string().describe("Codename of the item to get")
7
+ codename: z.string().describe("Codename of the item to get"),
6
8
  }, async ({ codename }) => {
7
9
  const client = createMapiClient();
8
- const response = await client
9
- .viewContentItem()
10
- .byItemCodename(codename)
11
- .toPromise();
12
- return {
13
- content: [
14
- {
15
- type: "text",
16
- text: JSON.stringify(response.data),
17
- },
18
- ],
19
- };
10
+ try {
11
+ const response = await client
12
+ .viewContentItem()
13
+ .byItemCodename(codename)
14
+ .toPromise();
15
+ return createMcpToolSuccessResponse(response.data);
16
+ }
17
+ catch (error) {
18
+ return handleMcpToolError(error, "Item Retrieval");
19
+ }
20
20
  });
21
21
  };
@@ -1,21 +1,21 @@
1
1
  import { z } from "zod";
2
- import { createMapiClient } from '../clients/kontentClients.js';
2
+ import { createMapiClient } from "../clients/kontentClients.js";
3
+ import { handleMcpToolError } from "../utils/errorHandler.js";
4
+ import { createMcpToolSuccessResponse } from "../utils/responseHelper.js";
3
5
  export const registerTool = (server) => {
4
6
  server.tool("get-taxonomy-group-mapi", "Get taxonomy group by codename from Management API", {
5
- codename: z.string().describe("Codename of the taxonomy group to get")
7
+ codename: z.string().describe("Codename of the taxonomy group to get"),
6
8
  }, async ({ codename }) => {
7
9
  const client = createMapiClient();
8
- const response = await client
9
- .getTaxonomy()
10
- .byTaxonomyCodename(codename)
11
- .toPromise();
12
- return {
13
- content: [
14
- {
15
- type: "text",
16
- text: JSON.stringify(response.data),
17
- },
18
- ],
19
- };
10
+ try {
11
+ const response = await client
12
+ .getTaxonomy()
13
+ .byTaxonomyCodename(codename)
14
+ .toPromise();
15
+ return createMcpToolSuccessResponse(response.data);
16
+ }
17
+ catch (error) {
18
+ return handleMcpToolError(error, "Taxonomy Group Retrieval");
19
+ }
20
20
  });
21
21
  };
@@ -1,21 +1,21 @@
1
1
  import { z } from "zod";
2
- import { createMapiClient } from '../clients/kontentClients.js';
2
+ import { createMapiClient } from "../clients/kontentClients.js";
3
+ import { handleMcpToolError } from "../utils/errorHandler.js";
4
+ import { createMcpToolSuccessResponse } from "../utils/responseHelper.js";
3
5
  export const registerTool = (server) => {
4
6
  server.tool("get-type-mapi", "Get content type by codename from Management API", {
5
- codename: z.string().describe("Codename of the content type to get")
7
+ codename: z.string().describe("Codename of the content type to get"),
6
8
  }, async ({ codename }) => {
7
9
  const client = createMapiClient();
8
- const response = await client
9
- .viewContentType()
10
- .byTypeCodename(codename)
11
- .toPromise();
12
- return {
13
- content: [
14
- {
15
- type: "text",
16
- text: JSON.stringify(response.data),
17
- },
18
- ],
19
- };
10
+ try {
11
+ const response = await client
12
+ .viewContentType()
13
+ .byTypeCodename(codename)
14
+ .toPromise();
15
+ return createMcpToolSuccessResponse(response.data);
16
+ }
17
+ catch (error) {
18
+ return handleMcpToolError(error, "Content Type Retrieval");
19
+ }
20
20
  });
21
21
  };
@@ -1,21 +1,23 @@
1
1
  import { z } from "zod";
2
- import { createMapiClient } from '../clients/kontentClients.js';
2
+ import { createMapiClient } from "../clients/kontentClients.js";
3
+ import { handleMcpToolError } from "../utils/errorHandler.js";
4
+ import { createMcpToolSuccessResponse } from "../utils/responseHelper.js";
3
5
  export const registerTool = (server) => {
4
6
  server.tool("get-type-snippet-mapi", "Get content type snippet by codename from Management API", {
5
- codename: z.string().describe("Codename of the content type snippet to get")
7
+ codename: z
8
+ .string()
9
+ .describe("Codename of the content type snippet to get"),
6
10
  }, async ({ codename }) => {
7
11
  const client = createMapiClient();
8
- const response = await client
9
- .viewContentTypeSnippet()
10
- .byTypeCodename(codename)
11
- .toPromise();
12
- return {
13
- content: [
14
- {
15
- type: "text",
16
- text: JSON.stringify(response.data),
17
- },
18
- ],
19
- };
12
+ try {
13
+ const response = await client
14
+ .viewContentTypeSnippet()
15
+ .byTypeCodename(codename)
16
+ .toPromise();
17
+ return createMcpToolSuccessResponse(response.data);
18
+ }
19
+ catch (error) {
20
+ return handleMcpToolError(error, "Content Type Snippet Retrieval");
21
+ }
20
22
  });
21
23
  };
@@ -1,23 +1,25 @@
1
1
  import { z } from "zod";
2
- import { createMapiClient } from '../clients/kontentClients.js';
2
+ import { createMapiClient } from "../clients/kontentClients.js";
3
+ import { handleMcpToolError } from "../utils/errorHandler.js";
4
+ import { createMcpToolSuccessResponse } from "../utils/responseHelper.js";
3
5
  export const registerTool = (server) => {
4
6
  server.tool("get-variant-mapi", "Get language variant of a content item from Management API", {
5
7
  itemCodename: z.string().describe("Codename of the content item"),
6
- languageCodename: z.string().describe("Codename of the language variant to get")
8
+ languageCodename: z
9
+ .string()
10
+ .describe("Codename of the language variant to get"),
7
11
  }, async ({ itemCodename, languageCodename }) => {
8
12
  const client = createMapiClient();
9
- const response = await client
10
- .viewLanguageVariant()
11
- .byItemCodename(itemCodename)
12
- .byLanguageCodename(languageCodename)
13
- .toPromise();
14
- return {
15
- content: [
16
- {
17
- type: "text",
18
- text: JSON.stringify(response.data),
19
- },
20
- ],
21
- };
13
+ try {
14
+ const response = await client
15
+ .viewLanguageVariant()
16
+ .byItemCodename(itemCodename)
17
+ .byLanguageCodename(languageCodename)
18
+ .toPromise();
19
+ return createMcpToolSuccessResponse(response.data);
20
+ }
21
+ catch (error) {
22
+ return handleMcpToolError(error, "Language Variant Retrieval");
23
+ }
22
24
  });
23
25
  };
@@ -1,17 +1,15 @@
1
- import { createMapiClient } from '../clients/kontentClients.js';
1
+ import { createMapiClient } from "../clients/kontentClients.js";
2
+ import { handleMcpToolError } from "../utils/errorHandler.js";
3
+ import { createMcpToolSuccessResponse } from "../utils/responseHelper.js";
2
4
  export const registerTool = (server) => {
3
5
  server.tool("list-assets-mapi", "Get all assets from Management API", {}, async () => {
4
6
  const client = createMapiClient();
5
- const response = await client
6
- .listAssets()
7
- .toAllPromise();
8
- return {
9
- content: [
10
- {
11
- type: "text",
12
- text: JSON.stringify(response.data),
13
- },
14
- ],
15
- };
7
+ try {
8
+ const response = await client.listAssets().toAllPromise();
9
+ return createMcpToolSuccessResponse(response.data);
10
+ }
11
+ catch (error) {
12
+ return handleMcpToolError(error, "Assets Listing");
13
+ }
16
14
  });
17
15
  };
@@ -1,17 +1,15 @@
1
- import { createMapiClient } from '../clients/kontentClients.js';
1
+ import { createMapiClient } from "../clients/kontentClients.js";
2
+ import { handleMcpToolError } from "../utils/errorHandler.js";
3
+ import { createMcpToolSuccessResponse } from "../utils/responseHelper.js";
2
4
  export const registerTool = (server) => {
3
5
  server.tool("list-content-type-snippets-mapi", "Get all content type snippets from Management API", {}, async () => {
4
6
  const client = createMapiClient();
5
- const response = await client
6
- .listContentTypeSnippets()
7
- .toAllPromise();
8
- return {
9
- content: [
10
- {
11
- type: "text",
12
- text: JSON.stringify(response.data),
13
- },
14
- ],
15
- };
7
+ try {
8
+ const response = await client.listContentTypeSnippets().toAllPromise();
9
+ return createMcpToolSuccessResponse(response.data);
10
+ }
11
+ catch (error) {
12
+ return handleMcpToolError(error, "Content Type Snippets Listing");
13
+ }
16
14
  });
17
15
  };
@@ -1,17 +1,15 @@
1
- import { createMapiClient } from '../clients/kontentClients.js';
1
+ import { createMapiClient } from "../clients/kontentClients.js";
2
+ import { handleMcpToolError } from "../utils/errorHandler.js";
3
+ import { createMcpToolSuccessResponse } from "../utils/responseHelper.js";
2
4
  export const registerTool = (server) => {
3
5
  server.tool("list-content-types-mapi", "Get all content types from Management API", {}, async () => {
4
6
  const client = createMapiClient();
5
- const response = await client
6
- .listContentTypes()
7
- .toAllPromise();
8
- return {
9
- content: [
10
- {
11
- type: "text",
12
- text: JSON.stringify(response.data),
13
- },
14
- ],
15
- };
7
+ try {
8
+ const response = await client.listContentTypes().toAllPromise();
9
+ return createMcpToolSuccessResponse(response.data);
10
+ }
11
+ catch (error) {
12
+ return handleMcpToolError(error, "Content Types Listing");
13
+ }
16
14
  });
17
15
  };
@@ -1,17 +1,15 @@
1
- import { createMapiClient } from '../clients/kontentClients.js';
1
+ import { createMapiClient } from "../clients/kontentClients.js";
2
+ import { handleMcpToolError } from "../utils/errorHandler.js";
3
+ import { createMcpToolSuccessResponse } from "../utils/responseHelper.js";
2
4
  export const registerTool = (server) => {
3
5
  server.tool("list-languages-mapi", "Get all languages from Management API", {}, async () => {
4
6
  const client = createMapiClient();
5
- const response = await client
6
- .listLanguages()
7
- .toAllPromise();
8
- return {
9
- content: [
10
- {
11
- type: "text",
12
- text: JSON.stringify(response.data),
13
- },
14
- ],
15
- };
7
+ try {
8
+ const response = await client.listLanguages().toAllPromise();
9
+ return createMcpToolSuccessResponse(response.data);
10
+ }
11
+ catch (error) {
12
+ return handleMcpToolError(error, "Languages Listing");
13
+ }
16
14
  });
17
15
  };
@@ -1,17 +1,15 @@
1
- import { createMapiClient } from '../clients/kontentClients.js';
1
+ import { createMapiClient } from "../clients/kontentClients.js";
2
+ import { handleMcpToolError } from "../utils/errorHandler.js";
3
+ import { createMcpToolSuccessResponse } from "../utils/responseHelper.js";
2
4
  export const registerTool = (server) => {
3
- server.tool("list-taxonomy-groups-mapi", "Get all taxonomy groups from Management API", {}, async () => {
5
+ server.tool("list-taxonomy-groups-mapi", "Get all taxonomy groups from Management API", {}, {}, async () => {
4
6
  const client = createMapiClient();
5
- const response = await client
6
- .listTaxonomies()
7
- .toPromise();
8
- return {
9
- content: [
10
- {
11
- type: "text",
12
- text: JSON.stringify(response.data),
13
- },
14
- ],
15
- };
7
+ try {
8
+ const response = await client.listTaxonomies().toPromise();
9
+ return createMcpToolSuccessResponse(response.data);
10
+ }
11
+ catch (error) {
12
+ return handleMcpToolError(error, "Taxonomy Groups Listing");
13
+ }
16
14
  });
17
15
  };
@@ -0,0 +1,74 @@
1
+ import { z } from "zod";
2
+ import { createMapiClient } from "../clients/kontentClients.js";
3
+ import { handleMcpToolError } from "../utils/errorHandler.js";
4
+ import { createMcpToolSuccessResponse } from "../utils/responseHelper.js";
5
+ export const registerTool = (server) => {
6
+ server.tool("update-content-item-mapi", "Update an existing content item by codename via Management API. The content item must already exist - this tool will not create new items.", {
7
+ codename: z.string().describe("Codename of the content item to update"),
8
+ name: z
9
+ .string()
10
+ .min(1)
11
+ .max(200)
12
+ .optional()
13
+ .describe("New display name of the content item (1-200 characters, optional)"),
14
+ collection: z
15
+ .object({
16
+ id: z.string().optional(),
17
+ codename: z.string().optional(),
18
+ external_id: z.string().optional(),
19
+ })
20
+ .optional()
21
+ .describe("Reference to a collection by id, codename, or external_id (optional)"),
22
+ }, async ({ codename, name, collection }) => {
23
+ const client = createMapiClient();
24
+ try {
25
+ // First, verify the item exists by trying to get it
26
+ await client.viewContentItem().byItemCodename(codename).toPromise();
27
+ // If we get here, the item exists, so we can update it
28
+ const updateData = {};
29
+ if (name !== undefined) {
30
+ updateData.name = name;
31
+ }
32
+ if (collection !== undefined) {
33
+ updateData.collection = collection;
34
+ }
35
+ // If no update data is provided, return an error
36
+ if (Object.keys(updateData).length === 0) {
37
+ return {
38
+ content: [
39
+ {
40
+ type: "text",
41
+ text: "Update Content Item: No update data provided. At least one field (name or collection) must be specified.",
42
+ },
43
+ ],
44
+ isError: true,
45
+ };
46
+ }
47
+ const response = await client
48
+ .upsertContentItem()
49
+ .byItemCodename(codename)
50
+ .withData(updateData)
51
+ .toPromise();
52
+ return createMcpToolSuccessResponse({
53
+ message: `Content item '${codename}' updated successfully`,
54
+ updatedItem: response.rawData,
55
+ });
56
+ }
57
+ catch (error) {
58
+ // Check if the error is because the item doesn't exist
59
+ if (error?.response?.status === 404 ||
60
+ error?.message?.includes("not found")) {
61
+ return {
62
+ content: [
63
+ {
64
+ type: "text",
65
+ text: `Update Content Item: Content item with codename '${codename}' does not exist. Use add-content-item-mapi to create new items.`,
66
+ },
67
+ ],
68
+ isError: true,
69
+ };
70
+ }
71
+ return handleMcpToolError(error, "Content Item Update");
72
+ }
73
+ });
74
+ };