@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
@@ -0,0 +1,46 @@
1
+ import { z } from "zod";
2
+ import { createMapiClient } from "../clients/kontentClients.js";
3
+ import { createValidationErrorResponse, handleMcpToolError, } from "../utils/errorHandler.js";
4
+ import { createMcpToolSuccessResponse } from "../utils/responseHelper.js";
5
+ export const registerTool = (server) => {
6
+ server.tool("upsert-language-variant-mapi", "Create or update a language variant of a content item via Management API. This adds actual content to the content item elements. Elements should be provided as JSON string in the format expected by the SDK.", {
7
+ itemCodename: z.string().describe("Codename of the content item"),
8
+ languageCodename: z
9
+ .string()
10
+ .describe("Codename of the language variant (e.g., 'default', 'en-US', 'es-ES')"),
11
+ elements: z
12
+ .string()
13
+ .describe('JSON string representing an array of element objects. Each element should have an "element" object with "codename" property and a "value" property. Example: \'[{"element": {"codename": "title"}, "value": "My Title"}, {"element": {"codename": "content"}, "value": "<p>My content</p>"}]\''),
14
+ workflow_step_codename: z
15
+ .string()
16
+ .optional()
17
+ .describe("Codename of the workflow step (optional)"),
18
+ }, async ({ itemCodename, languageCodename, elements, workflow_step_codename, }) => {
19
+ const client = createMapiClient();
20
+ let parsedElements;
21
+ try {
22
+ parsedElements = JSON.parse(elements);
23
+ }
24
+ catch (error) {
25
+ return createValidationErrorResponse(`Invalid JSON format in elements parameter. ${error instanceof Error ? error.message : "Unknown JSON parsing error"}`, "JSON Parsing Error");
26
+ }
27
+ const data = {
28
+ elements: parsedElements,
29
+ };
30
+ if (workflow_step_codename) {
31
+ data.workflow_step = { codename: workflow_step_codename };
32
+ }
33
+ try {
34
+ const response = await client
35
+ .upsertLanguageVariant()
36
+ .byItemCodename(itemCodename)
37
+ .byLanguageCodename(languageCodename)
38
+ .withData(() => data)
39
+ .toPromise();
40
+ return createMcpToolSuccessResponse(response.rawData);
41
+ }
42
+ catch (error) {
43
+ return handleMcpToolError(error, "Language Variant Upsert");
44
+ }
45
+ });
46
+ };
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Utility for handling errors in MCP tools and returning standardized error responses
3
+ */
4
+ /**
5
+ * Handles various types of errors and returns a standardized MCP tool error response
6
+ * @param error The error to handle
7
+ * @param context Optional context string to include in error message
8
+ * @returns Standardized MCP tool error response
9
+ */
10
+ export const handleMcpToolError = (error, context) => {
11
+ const contextPrefix = context ? `${context}: ` : "";
12
+ // Handle Kontent.ai Management API specific errors
13
+ if (error?.name === "ContentManagementBaseKontentError" || error?.requestId) {
14
+ const errorMessage = [
15
+ `${contextPrefix}Kontent.ai Management API Error:`,
16
+ `Message: ${error.message || "Unknown API error"}`,
17
+ error.errorCode ? `Error Code: ${error.errorCode}` : null,
18
+ error.requestId ? `Request ID: ${error.requestId}` : null,
19
+ ]
20
+ .filter(Boolean)
21
+ .join("\n");
22
+ // Include validation errors if available
23
+ if (error.validationErrors && Array.isArray(error.validationErrors)) {
24
+ const validationDetails = error.validationErrors
25
+ .map((ve) => `- ${ve.message || JSON.stringify(ve)}`)
26
+ .join("\n");
27
+ return {
28
+ content: [
29
+ {
30
+ type: "text",
31
+ text: `${errorMessage}\n\nValidation Errors:\n${validationDetails}`,
32
+ },
33
+ ],
34
+ isError: true,
35
+ };
36
+ }
37
+ return {
38
+ content: [
39
+ {
40
+ type: "text",
41
+ text: errorMessage,
42
+ },
43
+ ],
44
+ isError: true,
45
+ };
46
+ }
47
+ // Handle network or other HTTP errors
48
+ if (error?.response) {
49
+ return {
50
+ content: [
51
+ {
52
+ type: "text",
53
+ text: `${contextPrefix}HTTP Error ${error.response.status}: ${error.response.statusText || "Unknown HTTP error"}\n\nResponse: ${JSON.stringify(error.response.data, null, 2)}`,
54
+ },
55
+ ],
56
+ isError: true,
57
+ };
58
+ }
59
+ // Handle generic errors
60
+ return {
61
+ content: [
62
+ {
63
+ type: "text",
64
+ text: `${contextPrefix}Unexpected error: ${error instanceof Error ? error.message : "Unknown error occurred"}\n\nFull error: ${JSON.stringify(error, null, 2)}`,
65
+ },
66
+ ],
67
+ isError: true,
68
+ };
69
+ };
70
+ /**
71
+ * Creates a standardized MCP tool error response for validation errors
72
+ * @param message The validation error message
73
+ * @param context Optional context string
74
+ * @returns Standardized MCP tool error response
75
+ */
76
+ export const createValidationErrorResponse = (message, context) => {
77
+ const contextPrefix = context ? `${context}: ` : "";
78
+ return {
79
+ content: [
80
+ {
81
+ type: "text",
82
+ text: `${contextPrefix}${message}`,
83
+ },
84
+ ],
85
+ isError: true,
86
+ };
87
+ };
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Utility for creating standardized MCP tool success responses
3
+ */
4
+ /**
5
+ * Creates a standardized MCP tool success response
6
+ * @param data The data to include in the response
7
+ * @returns Standardized MCP tool success response
8
+ */
9
+ export const createMcpToolSuccessResponse = (data) => {
10
+ return {
11
+ content: [
12
+ {
13
+ type: "text",
14
+ text: JSON.stringify(data, null, 2),
15
+ },
16
+ ],
17
+ };
18
+ };
@@ -0,0 +1,3 @@
1
+ export const throwError = (message) => {
2
+ throw new Error(message);
3
+ };
package/package.json CHANGED
@@ -1,11 +1,15 @@
1
1
  {
2
2
  "name": "@kontent-ai/mcp-server",
3
- "version": "0.4.2",
3
+ "version": "0.6.0",
4
4
  "type": "module",
5
5
  "scripts": {
6
- "build": "tsc",
6
+ "build": "rimraf build && tsc",
7
7
  "start:stdio": "node build/bin.js stdio",
8
- "start:sse": "node build/bin.js sse"
8
+ "start:sse": "node build/bin.js sse",
9
+ "dev:stdio": "tsx watch src/bin.ts stdio",
10
+ "dev:sse": "tsx watch src/bin.ts sse",
11
+ "format": "cross-env node node_modules/@biomejs/biome/bin/biome ci ./ --config-path=./biome.json",
12
+ "format:fix": "cross-env node node_modules/@biomejs/biome/bin/biome check ./ --fix --unsafe --config-path=./biome.json"
9
13
  },
10
14
  "bin": {
11
15
  "@kontent-ai/mcp-server": "./build/bin.js"
@@ -19,14 +23,18 @@
19
23
  "dependencies": {
20
24
  "@kontent-ai/delivery-sdk": "^16.2.0",
21
25
  "@kontent-ai/management-sdk": "^7.9.0",
22
- "@modelcontextprotocol/sdk": "^1.11.4",
26
+ "@modelcontextprotocol/sdk": "^1.12.0",
23
27
  "dotenv": "^16.5.0",
24
28
  "express": "^5.1.0",
25
- "zod": "^3.25.7"
29
+ "zod": "^3.25.30"
26
30
  },
27
31
  "devDependencies": {
32
+ "@biomejs/biome": "^2.0.5",
28
33
  "@types/express": "^5.0.2",
29
34
  "@types/node": "^22.15.19",
35
+ "cross-env": "^7.0.3",
36
+ "rimraf": "^6.0.1",
37
+ "tsx": "^4.20.3",
30
38
  "typescript": "^5.8.3"
31
39
  }
32
40
  }