@kontent-ai/mcp-server 0.18.0 → 0.20.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.
- package/README.md +6 -2
- package/build/bin.js +17 -9
- package/build/clients/kontentClients.js +12 -9
- package/build/schemas/searchOperationSchemas.js +14 -0
- package/build/server.js +30 -30
- package/build/telemetry/applicationInsights.js +161 -0
- package/build/telemetry/telemetrySanitizer.js +48 -0
- package/build/tools/add-content-item-mapi.js +2 -2
- package/build/tools/add-content-type-mapi.js +2 -2
- package/build/tools/add-content-type-snippet-mapi.js +2 -2
- package/build/tools/add-taxonomy-group-mapi.js +3 -3
- package/build/tools/change-variant-workflow-step-mapi.js +3 -3
- package/build/tools/context/initial-context.js +11 -1
- package/build/tools/create-variant-version-mapi.js +3 -3
- package/build/tools/delete-content-item-mapi.js +3 -3
- package/build/tools/delete-content-type-mapi.js +3 -3
- package/build/tools/delete-language-variant-mapi.js +3 -3
- package/build/tools/filter-variants-mapi.js +23 -45
- package/build/tools/get-asset-mapi.js +3 -3
- package/build/tools/get-item-mapi.js +3 -3
- package/build/tools/get-taxonomy-group-mapi.js +3 -3
- package/build/tools/get-type-mapi.js +3 -3
- package/build/tools/get-type-snippet-mapi.js +3 -3
- package/build/tools/get-variant-mapi.js +3 -3
- package/build/tools/list-assets-mapi.js +4 -3
- package/build/tools/list-content-type-snippets-mapi.js +4 -3
- package/build/tools/list-content-types-mapi.js +4 -3
- package/build/tools/list-languages-mapi.js +4 -3
- package/build/tools/list-taxonomy-groups-mapi.js +4 -3
- package/build/tools/list-workflows-mapi.js +3 -3
- package/build/tools/patch-content-type-mapi.js +2 -2
- package/build/tools/publish-variant-mapi.js +2 -2
- package/build/tools/search-variants-mapi.js +97 -0
- package/build/tools/unpublish-variant-mapi.js +2 -2
- package/build/tools/update-content-item-mapi.js +2 -2
- package/build/tools/upsert-language-variant-mapi.js +2 -2
- package/build/utils/errorHandler.js +15 -3
- package/package.json +2 -5
- package/build/config/appConfiguration.js +0 -51
- package/build/tools/get-item-dapi.js +0 -26
package/README.md
CHANGED
|
@@ -91,7 +91,8 @@ npx @kontent-ai/mcp-server@latest shttp
|
|
|
91
91
|
* **upsert-language-variant-mapi** – Create or update Kontent.ai language variant of a content item via Management API. This adds actual content to the content item elements. When updating an existing variant, only the provided elements will be modified
|
|
92
92
|
* **create-variant-version-mapi** – Create new version of Kontent.ai language variant via Management API. This operation creates a new version of an existing language variant, useful for content versioning and creating new drafts from published content
|
|
93
93
|
* **delete-language-variant-mapi** – Delete Kontent.ai language variant from Management API
|
|
94
|
-
* **filter-variants-mapi** –
|
|
94
|
+
* **filter-variants-mapi** – Filter Kontent.ai language variants of content items using Management API. Use for exact keyword matching and finding specific terms in content. Supports full filtering capabilities (content types, workflow steps, taxonomies, etc.)
|
|
95
|
+
* **search-variants-mapi** – AI-powered semantic search for finding content by meaning and concepts in a specific language variant. Use for: conceptual searches when you don't know exact keywords. Limited filtering options (variant ID only)
|
|
95
96
|
|
|
96
97
|
### Asset Management
|
|
97
98
|
|
|
@@ -122,6 +123,9 @@ For single-tenant mode, configure environment variables:
|
|
|
122
123
|
| KONTENT_API_KEY | Your Kontent.ai Management API key | ✅ |
|
|
123
124
|
| KONTENT_ENVIRONMENT_ID | Your environment ID | ✅ |
|
|
124
125
|
| PORT | Port for HTTP transport (defaults to 3001) | ❌ |
|
|
126
|
+
| appInsightsConnectionString | Application Insights connection string for telemetry | ❌ |
|
|
127
|
+
| projectLocation | Project location identifier for telemetry tracking | ❌ |
|
|
128
|
+
| manageApiUrl | Custom Management API base URL (for preview environments) | ❌ |
|
|
125
129
|
|
|
126
130
|
### Multi-Tenant Mode
|
|
127
131
|
|
|
@@ -345,4 +349,4 @@ MIT
|
|
|
345
349
|
[discord-shield]: https://img.shields.io/discord/821885171984891914?color=%237289DA&label=Kontent.ai%20Discord&logo=discord&style=for-the-badge
|
|
346
350
|
[discord-url]: https://discord.com/invite/SKCxwPtevJ
|
|
347
351
|
[npm-url]: https://www.npmjs.com/package/@kontent-ai/mcp-server
|
|
348
|
-
[npm-shield]: https://img.shields.io/npm/v/%40kontent-ai%2Fmcp-server?style=for-the-badge&logo=npm&color=%23CB0000
|
|
352
|
+
[npm-shield]: https://img.shields.io/npm/v/%40kontent-ai%2Fmcp-server?style=for-the-badge&logo=npm&color=%23CB0000
|
package/build/bin.js
CHANGED
|
@@ -4,17 +4,17 @@ import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/
|
|
|
4
4
|
import "dotenv/config";
|
|
5
5
|
import express from "express";
|
|
6
6
|
import packageJson from "../package.json" with { type: "json" };
|
|
7
|
-
import { loadAppConfiguration, } from "./config/appConfiguration.js";
|
|
8
7
|
import { createServer } from "./server.js";
|
|
8
|
+
import { initializeApplicationInsights, trackException, trackServerStartup, } from "./telemetry/applicationInsights.js";
|
|
9
9
|
import { extractBearerToken } from "./utils/extractBearerToken.js";
|
|
10
10
|
import { isValidGuid } from "./utils/isValidGuid.js";
|
|
11
11
|
const version = packageJson.version;
|
|
12
|
-
async function startStreamableHTTP(
|
|
12
|
+
async function startStreamableHTTP() {
|
|
13
13
|
const app = express();
|
|
14
14
|
app.use(express.json());
|
|
15
15
|
app.post("/mcp", async (req, res) => {
|
|
16
16
|
try {
|
|
17
|
-
const { server } = createServer(
|
|
17
|
+
const { server } = createServer();
|
|
18
18
|
const transport = new StreamableHTTPServerTransport({
|
|
19
19
|
sessionIdGenerator: undefined,
|
|
20
20
|
});
|
|
@@ -28,6 +28,7 @@ async function startStreamableHTTP(config) {
|
|
|
28
28
|
}
|
|
29
29
|
catch (error) {
|
|
30
30
|
console.error("Error handling MCP request:", error);
|
|
31
|
+
trackException(error, "MCP Request Handler");
|
|
31
32
|
if (!res.headersSent) {
|
|
32
33
|
res.status(500).json({
|
|
33
34
|
jsonrpc: "2.0",
|
|
@@ -69,7 +70,7 @@ async function startStreamableHTTP(config) {
|
|
|
69
70
|
});
|
|
70
71
|
return;
|
|
71
72
|
}
|
|
72
|
-
const { server } = createServer(
|
|
73
|
+
const { server } = createServer();
|
|
73
74
|
const transport = new StreamableHTTPServerTransport({
|
|
74
75
|
sessionIdGenerator: undefined,
|
|
75
76
|
});
|
|
@@ -96,6 +97,7 @@ async function startStreamableHTTP(config) {
|
|
|
96
97
|
}
|
|
97
98
|
catch (error) {
|
|
98
99
|
console.error("Error handling MCP request:", error);
|
|
100
|
+
trackException(error, "MCP Multi-tenant Request Handler");
|
|
99
101
|
if (!res.headersSent) {
|
|
100
102
|
res.status(500).json({
|
|
101
103
|
jsonrpc: "2.0",
|
|
@@ -128,6 +130,10 @@ async function startStreamableHTTP(config) {
|
|
|
128
130
|
id: null,
|
|
129
131
|
}));
|
|
130
132
|
});
|
|
133
|
+
app.use((err, _req, _res, next) => {
|
|
134
|
+
trackException(err, "Express Error Handler");
|
|
135
|
+
next(err);
|
|
136
|
+
});
|
|
131
137
|
const PORT = process.env.PORT || 3001;
|
|
132
138
|
app.listen(PORT, () => {
|
|
133
139
|
console.log(`Kontent.ai MCP Server v${version} (Streamable HTTP) running on port ${PORT}.
|
|
@@ -136,14 +142,15 @@ Available endpoints:
|
|
|
136
142
|
/{environmentId}/mcp (requires Bearer authentication)`);
|
|
137
143
|
});
|
|
138
144
|
}
|
|
139
|
-
async function startStdio(
|
|
140
|
-
const { server } = createServer(
|
|
145
|
+
async function startStdio() {
|
|
146
|
+
const { server } = createServer();
|
|
141
147
|
const transport = new StdioServerTransport();
|
|
142
148
|
console.log(`Kontent.ai MCP Server v${version} (stdio) starting`);
|
|
143
149
|
await server.connect(transport);
|
|
144
150
|
}
|
|
145
151
|
async function main() {
|
|
146
|
-
|
|
152
|
+
initializeApplicationInsights();
|
|
153
|
+
trackServerStartup(version);
|
|
147
154
|
const args = process.argv.slice(2);
|
|
148
155
|
const transportType = args[0]?.toLowerCase();
|
|
149
156
|
if (!transportType ||
|
|
@@ -152,13 +159,14 @@ async function main() {
|
|
|
152
159
|
process.exit(1);
|
|
153
160
|
}
|
|
154
161
|
if (transportType === "stdio") {
|
|
155
|
-
await startStdio(
|
|
162
|
+
await startStdio();
|
|
156
163
|
}
|
|
157
164
|
else if (transportType === "shttp") {
|
|
158
|
-
await startStreamableHTTP(
|
|
165
|
+
await startStreamableHTTP();
|
|
159
166
|
}
|
|
160
167
|
}
|
|
161
168
|
main().catch((error) => {
|
|
162
169
|
console.error("Fatal error:", error);
|
|
170
|
+
trackException(error, "Server Startup");
|
|
163
171
|
process.exit(1);
|
|
164
172
|
});
|
|
@@ -6,10 +6,18 @@ const sourceTrackingHeaderName = "X-KC-SOURCE";
|
|
|
6
6
|
* Creates a Kontent.ai Management API client
|
|
7
7
|
* @param environmentId Optional environment ID (defaults to process.env.KONTENT_ENVIRONMENT_ID)
|
|
8
8
|
* @param apiKey Optional API key (defaults to process.env.KONTENT_API_KEY)
|
|
9
|
-
* @param
|
|
9
|
+
* @param additionalHeaders Optional additional headers to include in requests
|
|
10
10
|
* @returns Management API client instance
|
|
11
11
|
*/
|
|
12
|
-
export const createMapiClient = (environmentId, apiKey,
|
|
12
|
+
export const createMapiClient = (environmentId, apiKey, additionalHeaders) => {
|
|
13
|
+
const allHeaders = [
|
|
14
|
+
{
|
|
15
|
+
header: sourceTrackingHeaderName,
|
|
16
|
+
value: `${packageJson.name};${packageJson.version}`,
|
|
17
|
+
},
|
|
18
|
+
...(additionalHeaders || []),
|
|
19
|
+
];
|
|
20
|
+
const manageApiUrl = process.env.manageApiUrl;
|
|
13
21
|
return createManagementClient({
|
|
14
22
|
apiKey: apiKey ??
|
|
15
23
|
process.env.KONTENT_API_KEY ??
|
|
@@ -17,12 +25,7 @@ export const createMapiClient = (environmentId, apiKey, config) => {
|
|
|
17
25
|
environmentId: environmentId ??
|
|
18
26
|
process.env.KONTENT_ENVIRONMENT_ID ??
|
|
19
27
|
throwError("KONTENT_ENVIRONMENT_ID is not set"),
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
header: sourceTrackingHeaderName,
|
|
23
|
-
value: `${packageJson.name};${packageJson.version}`,
|
|
24
|
-
},
|
|
25
|
-
],
|
|
26
|
-
baseUrl: config ? `${config.manageApiUrl}v2` : undefined,
|
|
28
|
+
baseUrl: manageApiUrl ? `${manageApiUrl}v2` : undefined,
|
|
29
|
+
headers: allHeaders,
|
|
27
30
|
});
|
|
28
31
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export const searchOperationSchema = z.object({
|
|
3
|
+
searchPhrase: z
|
|
4
|
+
.string()
|
|
5
|
+
.describe("Search phrase for AI-powered semantic search. Uses vector database to find content by meaning and similarity, not just exact keyword matching"),
|
|
6
|
+
filter: z
|
|
7
|
+
.object({
|
|
8
|
+
variantId: z
|
|
9
|
+
.string()
|
|
10
|
+
.uuid()
|
|
11
|
+
.describe("UUID of the language variant to filter by"),
|
|
12
|
+
})
|
|
13
|
+
.describe("Mandatory content item variant filter to restrict search scope. Must specify a valid variant UUID"),
|
|
14
|
+
});
|
package/build/server.js
CHANGED
|
@@ -12,7 +12,6 @@ import { registerTool as registerDeleteLanguageVariantMapi } from "./tools/delet
|
|
|
12
12
|
import { registerTool as registerFilterVariantsMapi } from "./tools/filter-variants-mapi.js";
|
|
13
13
|
import { registerTool as registerGetAssetMapi } from "./tools/get-asset-mapi.js";
|
|
14
14
|
import { registerTool as registerGetInitialContext } from "./tools/get-initial-context.js";
|
|
15
|
-
import { registerTool as registerGetItemDapi } from "./tools/get-item-dapi.js";
|
|
16
15
|
import { registerTool as registerGetItemMapi } from "./tools/get-item-mapi.js";
|
|
17
16
|
import { registerTool as registerGetTaxonomyGroupMapi } from "./tools/get-taxonomy-group-mapi.js";
|
|
18
17
|
import { registerTool as registerGetTypeMapi } from "./tools/get-type-mapi.js";
|
|
@@ -26,11 +25,12 @@ import { registerTool as registerListTaxonomyGroupsMapi } from "./tools/list-tax
|
|
|
26
25
|
import { registerTool as registerListWorkflowsMapi } from "./tools/list-workflows-mapi.js";
|
|
27
26
|
import { registerTool as registerPatchContentTypeMapi } from "./tools/patch-content-type-mapi.js";
|
|
28
27
|
import { registerTool as registerPublishVariantMapi } from "./tools/publish-variant-mapi.js";
|
|
28
|
+
import { registerTool as registerSearchVariantsMapi } from "./tools/search-variants-mapi.js";
|
|
29
29
|
import { registerTool as registerUnpublishVariantMapi } from "./tools/unpublish-variant-mapi.js";
|
|
30
30
|
import { registerTool as registerUpdateContentItemMapi } from "./tools/update-content-item-mapi.js";
|
|
31
31
|
import { registerTool as registerUpsertLanguageVariantMapi } from "./tools/upsert-language-variant-mapi.js";
|
|
32
32
|
// Create server instance
|
|
33
|
-
export const createServer = (
|
|
33
|
+
export const createServer = () => {
|
|
34
34
|
const server = new McpServer({
|
|
35
35
|
name: "kontent-ai",
|
|
36
36
|
version: packageJson.version,
|
|
@@ -41,33 +41,33 @@ export const createServer = (config) => {
|
|
|
41
41
|
});
|
|
42
42
|
// Register all tools
|
|
43
43
|
registerGetInitialContext(server);
|
|
44
|
-
registerGetItemMapi(server
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
registerPublishVariantMapi(server
|
|
71
|
-
registerUnpublishVariantMapi(server
|
|
44
|
+
registerGetItemMapi(server);
|
|
45
|
+
registerGetVariantMapi(server);
|
|
46
|
+
registerGetTypeMapi(server);
|
|
47
|
+
registerListContentTypesMapi(server);
|
|
48
|
+
registerDeleteContentTypeMapi(server);
|
|
49
|
+
registerListLanguagesMapi(server);
|
|
50
|
+
registerGetAssetMapi(server);
|
|
51
|
+
registerListAssetsMapi(server);
|
|
52
|
+
registerAddContentTypeMapi(server);
|
|
53
|
+
registerPatchContentTypeMapi(server);
|
|
54
|
+
registerAddContentTypeSnippetMapi(server);
|
|
55
|
+
registerGetTypeSnippetMapi(server);
|
|
56
|
+
registerListContentTypeSnippetsMapi(server);
|
|
57
|
+
registerAddTaxonomyGroupMapi(server);
|
|
58
|
+
registerListTaxonomyGroupsMapi(server);
|
|
59
|
+
registerGetTaxonomyGroupMapi(server);
|
|
60
|
+
registerAddContentItemMapi(server);
|
|
61
|
+
registerUpdateContentItemMapi(server);
|
|
62
|
+
registerDeleteContentItemMapi(server);
|
|
63
|
+
registerUpsertLanguageVariantMapi(server);
|
|
64
|
+
registerCreateVariantVersionMapi(server);
|
|
65
|
+
registerDeleteLanguageVariantMapi(server);
|
|
66
|
+
registerListWorkflowsMapi(server);
|
|
67
|
+
registerChangeVariantWorkflowStepMapi(server);
|
|
68
|
+
registerFilterVariantsMapi(server);
|
|
69
|
+
registerSearchVariantsMapi(server);
|
|
70
|
+
registerPublishVariantMapi(server);
|
|
71
|
+
registerUnpublishVariantMapi(server);
|
|
72
72
|
return { server };
|
|
73
73
|
};
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { SharedModels } from "@kontent-ai/management-sdk";
|
|
2
|
+
import appInsights from "applicationinsights";
|
|
3
|
+
import { sanitizeTelemetry, sanitizeUrl } from "./telemetrySanitizer.js";
|
|
4
|
+
let isInitialized = false;
|
|
5
|
+
function trackKontentApiError(error, context) {
|
|
6
|
+
if (error.validationErrors && error.validationErrors.length > 0) {
|
|
7
|
+
// Don't log 400 responses as exceptions
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const safeError = new Error(error.message);
|
|
11
|
+
safeError.stack = error.originalError.stack || safeError.stack;
|
|
12
|
+
appInsights.defaultClient.trackException({
|
|
13
|
+
exception: safeError,
|
|
14
|
+
properties: {
|
|
15
|
+
errorType: "KontentManagementApiError",
|
|
16
|
+
errorCode: error.errorCode,
|
|
17
|
+
requestId: error.requestId,
|
|
18
|
+
context: context,
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function trackHttpError(error, context) {
|
|
23
|
+
let errorMessage;
|
|
24
|
+
let properties = {
|
|
25
|
+
errorType: "HttpError",
|
|
26
|
+
axiosErrorCode: error.code,
|
|
27
|
+
method: error.config?.method?.toUpperCase(),
|
|
28
|
+
url: error.config?.url ? sanitizeUrl(error.config.url) : undefined,
|
|
29
|
+
context: context,
|
|
30
|
+
};
|
|
31
|
+
if (error.response) {
|
|
32
|
+
errorMessage = `HTTP ${error.response.status} ${error.response.statusText || "Error"}`;
|
|
33
|
+
properties = {
|
|
34
|
+
...properties,
|
|
35
|
+
scenario: "ServerResponseError",
|
|
36
|
+
status: error.response.status,
|
|
37
|
+
statusText: error.response.statusText,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
else if (error.request) {
|
|
41
|
+
errorMessage = "Network Error - No response received";
|
|
42
|
+
properties = {
|
|
43
|
+
...properties,
|
|
44
|
+
scenario: "NetworkError",
|
|
45
|
+
timeout: error.config?.timeout,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
errorMessage = `Request Setup Error: ${error.message}`;
|
|
50
|
+
properties = {
|
|
51
|
+
...properties,
|
|
52
|
+
scenario: "RequestSetupError",
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
const safeError = new Error(errorMessage);
|
|
56
|
+
safeError.stack = error.stack || safeError.stack;
|
|
57
|
+
appInsights.defaultClient.trackException({
|
|
58
|
+
exception: safeError,
|
|
59
|
+
properties,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
function trackGeneralError(error, context) {
|
|
63
|
+
const safeError = new Error(error.message);
|
|
64
|
+
safeError.stack = error.stack;
|
|
65
|
+
appInsights.defaultClient.trackException({
|
|
66
|
+
exception: safeError,
|
|
67
|
+
properties: {
|
|
68
|
+
errorType: "JavaScriptError",
|
|
69
|
+
name: error.name,
|
|
70
|
+
context: context,
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
function trackUnknownError(error, context) {
|
|
75
|
+
appInsights.defaultClient.trackException({
|
|
76
|
+
exception: new Error("An error occurred"),
|
|
77
|
+
properties: {
|
|
78
|
+
errorType: "UnknownError",
|
|
79
|
+
actualType: typeof error,
|
|
80
|
+
context: context,
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
export function trackException(error, context) {
|
|
85
|
+
try {
|
|
86
|
+
if (!isInitialized || !appInsights.defaultClient) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (error instanceof SharedModels.ContentManagementBaseKontentError) {
|
|
90
|
+
trackKontentApiError(error, context);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (error.isAxiosError) {
|
|
94
|
+
trackHttpError(error, context);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (error instanceof Error) {
|
|
98
|
+
trackGeneralError(error, context);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
trackUnknownError(error, context);
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
// Silently fail - tracking should never break the application
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
export function trackServerStartup(version) {
|
|
108
|
+
try {
|
|
109
|
+
if (isInitialized && appInsights.defaultClient) {
|
|
110
|
+
appInsights.defaultClient.trackEvent({
|
|
111
|
+
name: "ServerStartup",
|
|
112
|
+
properties: {
|
|
113
|
+
version: version,
|
|
114
|
+
timestamp: new Date().toISOString(),
|
|
115
|
+
nodeVersion: process.version,
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
// Silently fail - tracking should never break the application
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function createTelemetryProcessor() {
|
|
125
|
+
return (envelope) => {
|
|
126
|
+
sanitizeTelemetry(envelope);
|
|
127
|
+
if (envelope.data?.baseData) {
|
|
128
|
+
envelope.data.baseData.properties =
|
|
129
|
+
envelope.data.baseData.properties || {};
|
|
130
|
+
envelope.data.baseData.properties["component.name"] = "mcp-server";
|
|
131
|
+
envelope.data.baseData.properties["component.location"] =
|
|
132
|
+
process.env.projectLocation || "unknown";
|
|
133
|
+
}
|
|
134
|
+
return true;
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
export function initializeApplicationInsights() {
|
|
138
|
+
try {
|
|
139
|
+
const connectionString = process.env.appInsightsConnectionString;
|
|
140
|
+
if (!connectionString) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
appInsights
|
|
144
|
+
.setup(connectionString)
|
|
145
|
+
.setAutoCollectExceptions(true)
|
|
146
|
+
.setAutoCollectRequests(true)
|
|
147
|
+
.setAutoCollectConsole(false)
|
|
148
|
+
.setAutoCollectDependencies(false)
|
|
149
|
+
.setAutoDependencyCorrelation(false)
|
|
150
|
+
.setAutoCollectHeartbeat(false)
|
|
151
|
+
.setAutoCollectPerformance(false)
|
|
152
|
+
.setAutoCollectIncomingRequestAzureFunctions(false)
|
|
153
|
+
.setAutoCollectPreAggregatedMetrics(false)
|
|
154
|
+
.start();
|
|
155
|
+
isInitialized = true;
|
|
156
|
+
appInsights.defaultClient.addTelemetryProcessor(createTelemetryProcessor());
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
console.log("Failed to initialize Application Insights:", error);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const SENSITIVE_KEYWORDS = [
|
|
2
|
+
"authorization",
|
|
3
|
+
"x-authorization",
|
|
4
|
+
"x-api-key",
|
|
5
|
+
"bearer",
|
|
6
|
+
"token",
|
|
7
|
+
"password",
|
|
8
|
+
"secret",
|
|
9
|
+
"key",
|
|
10
|
+
"pwd",
|
|
11
|
+
"pass",
|
|
12
|
+
"credential",
|
|
13
|
+
"x-kc-",
|
|
14
|
+
"cookie",
|
|
15
|
+
];
|
|
16
|
+
function isSensitive(key) {
|
|
17
|
+
const lowerKey = key.toLowerCase();
|
|
18
|
+
return SENSITIVE_KEYWORDS.some((keyword) => lowerKey.includes(keyword));
|
|
19
|
+
}
|
|
20
|
+
function sanitizeObject(obj) {
|
|
21
|
+
if (!obj || typeof obj !== "object")
|
|
22
|
+
return;
|
|
23
|
+
Object.keys(obj).forEach((key) => {
|
|
24
|
+
if (isSensitive(key)) {
|
|
25
|
+
delete obj[key];
|
|
26
|
+
}
|
|
27
|
+
else if (typeof obj[key] === "object") {
|
|
28
|
+
sanitizeObject(obj[key]);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
export function sanitizeUrl(url) {
|
|
33
|
+
return url.split("?")[0];
|
|
34
|
+
}
|
|
35
|
+
export function sanitizeTelemetry(envelope) {
|
|
36
|
+
if (!envelope.data?.baseData)
|
|
37
|
+
return;
|
|
38
|
+
const data = envelope.data.baseData;
|
|
39
|
+
if (envelope.tags) {
|
|
40
|
+
sanitizeObject(envelope.tags);
|
|
41
|
+
}
|
|
42
|
+
if (data.properties) {
|
|
43
|
+
sanitizeObject(data.properties);
|
|
44
|
+
}
|
|
45
|
+
if (data.url) {
|
|
46
|
+
data.url = sanitizeUrl(data.url);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -2,7 +2,7 @@ import { z } from "zod";
|
|
|
2
2
|
import { createMapiClient } from "../clients/kontentClients.js";
|
|
3
3
|
import { handleMcpToolError } from "../utils/errorHandler.js";
|
|
4
4
|
import { createMcpToolSuccessResponse } from "../utils/responseHelper.js";
|
|
5
|
-
export const registerTool = (server
|
|
5
|
+
export const registerTool = (server) => {
|
|
6
6
|
server.tool("add-content-item-mapi", "Add new Kontent.ai content item via Management API. This creates the content item structure but does not add content to language variants. Use upsert-language-variant-mapi to add content to the item.", {
|
|
7
7
|
name: z
|
|
8
8
|
.string()
|
|
@@ -33,7 +33,7 @@ export const registerTool = (server, config) => {
|
|
|
33
33
|
.optional()
|
|
34
34
|
.describe("Reference to a collection by id, codename, or external_id (optional)"),
|
|
35
35
|
}, async ({ name, type, codename, external_id, collection }, { authInfo: { token, clientId } = {} }) => {
|
|
36
|
-
const client = createMapiClient(clientId, token
|
|
36
|
+
const client = createMapiClient(clientId, token);
|
|
37
37
|
try {
|
|
38
38
|
const response = await client
|
|
39
39
|
.addContentItem()
|
|
@@ -3,7 +3,7 @@ import { createMapiClient } from "../clients/kontentClients.js";
|
|
|
3
3
|
import { contentGroupSchema, elementSchema, } from "../schemas/contentTypeSchemas.js";
|
|
4
4
|
import { handleMcpToolError } from "../utils/errorHandler.js";
|
|
5
5
|
import { createMcpToolSuccessResponse } from "../utils/responseHelper.js";
|
|
6
|
-
export const registerTool = (server
|
|
6
|
+
export const registerTool = (server) => {
|
|
7
7
|
server.tool("add-content-type-mapi", "Add new Kontent.ai content type via Management API", {
|
|
8
8
|
name: z.string().describe("Display name of the content type"),
|
|
9
9
|
codename: z
|
|
@@ -22,7 +22,7 @@ export const registerTool = (server, config) => {
|
|
|
22
22
|
.optional()
|
|
23
23
|
.describe("Array of content groups (optional)"),
|
|
24
24
|
}, async ({ name, codename, external_id, elements, content_groups }, { authInfo: { token, clientId } = {} }) => {
|
|
25
|
-
const client = createMapiClient(clientId, token
|
|
25
|
+
const client = createMapiClient(clientId, token);
|
|
26
26
|
try {
|
|
27
27
|
const response = await client
|
|
28
28
|
.addContentType()
|
|
@@ -3,7 +3,7 @@ import { createMapiClient } from "../clients/kontentClients.js";
|
|
|
3
3
|
import { snippetElementSchema } from "../schemas/contentTypeSchemas.js";
|
|
4
4
|
import { handleMcpToolError } from "../utils/errorHandler.js";
|
|
5
5
|
import { createMcpToolSuccessResponse } from "../utils/responseHelper.js";
|
|
6
|
-
export const registerTool = (server
|
|
6
|
+
export const registerTool = (server) => {
|
|
7
7
|
server.tool("add-content-type-snippet-mapi", "Add new Kontent.ai content type snippet via Management API", {
|
|
8
8
|
name: z.string().describe("Display name of the content type snippet"),
|
|
9
9
|
codename: z
|
|
@@ -18,7 +18,7 @@ export const registerTool = (server, config) => {
|
|
|
18
18
|
.array(snippetElementSchema)
|
|
19
19
|
.describe("Array of elements that define the structure of the content type snippet"),
|
|
20
20
|
}, async ({ name, codename, external_id, elements }, { authInfo: { token, clientId } = {} }) => {
|
|
21
|
-
const client = createMapiClient(clientId, token
|
|
21
|
+
const client = createMapiClient(clientId, token);
|
|
22
22
|
try {
|
|
23
23
|
const response = await client
|
|
24
24
|
.addContentTypeSnippet()
|
|
@@ -2,15 +2,15 @@ import { createMapiClient } from "../clients/kontentClients.js";
|
|
|
2
2
|
import { taxonomyGroupSchemas } from "../schemas/taxonomySchemas.js";
|
|
3
3
|
import { handleMcpToolError } from "../utils/errorHandler.js";
|
|
4
4
|
import { createMcpToolSuccessResponse } from "../utils/responseHelper.js";
|
|
5
|
-
export const registerTool = (server
|
|
5
|
+
export const registerTool = (server) => {
|
|
6
6
|
server.tool("add-taxonomy-group-mapi", "Add new Kontent.ai taxonomy group via Management API", taxonomyGroupSchemas, async (taxonomyGroup, { authInfo: { token, clientId } = {} }) => {
|
|
7
|
-
const client = createMapiClient(clientId, token
|
|
7
|
+
const client = createMapiClient(clientId, token);
|
|
8
8
|
try {
|
|
9
9
|
const response = await client
|
|
10
10
|
.addTaxonomy()
|
|
11
11
|
.withData(taxonomyGroup)
|
|
12
12
|
.toPromise();
|
|
13
|
-
return createMcpToolSuccessResponse(response.
|
|
13
|
+
return createMcpToolSuccessResponse(response.rawData);
|
|
14
14
|
}
|
|
15
15
|
catch (error) {
|
|
16
16
|
return handleMcpToolError(error, "Taxonomy Group Creation");
|
|
@@ -2,7 +2,7 @@ import { z } from "zod";
|
|
|
2
2
|
import { createMapiClient } from "../clients/kontentClients.js";
|
|
3
3
|
import { handleMcpToolError } from "../utils/errorHandler.js";
|
|
4
4
|
import { createMcpToolSuccessResponse } from "../utils/responseHelper.js";
|
|
5
|
-
export const registerTool = (server
|
|
5
|
+
export const registerTool = (server) => {
|
|
6
6
|
server.tool("change-variant-workflow-step-mapi", "Change the workflow step of a language variant in Kontent.ai. This operation moves a language variant to a different step in the workflow, enabling content lifecycle management such as moving content from draft to review, review to published, etc.", {
|
|
7
7
|
itemId: z
|
|
8
8
|
.string()
|
|
@@ -21,7 +21,7 @@ export const registerTool = (server, config) => {
|
|
|
21
21
|
.uuid()
|
|
22
22
|
.describe("Internal ID (UUID) of the target workflow step. This must be a valid step ID from the specified workflow. Common steps include Draft, Review, Published, and Archived, but the actual IDs depend on your specific workflow configuration"),
|
|
23
23
|
}, async ({ itemId, languageId, workflowId, workflowStepId }, { authInfo: { token, clientId } = {} }) => {
|
|
24
|
-
const client = createMapiClient(clientId, token
|
|
24
|
+
const client = createMapiClient(clientId, token);
|
|
25
25
|
try {
|
|
26
26
|
const response = await client
|
|
27
27
|
.changeWorkflowOfLanguageVariant()
|
|
@@ -38,7 +38,7 @@ export const registerTool = (server, config) => {
|
|
|
38
38
|
.toPromise();
|
|
39
39
|
return createMcpToolSuccessResponse({
|
|
40
40
|
message: `Successfully changed workflow step of language variant '${languageId}' for content item '${itemId}' to workflow step '${workflowStepId}'`,
|
|
41
|
-
result: response.
|
|
41
|
+
result: response.rawData,
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
44
|
catch (error) {
|
|
@@ -123,6 +123,8 @@ When working with taxonomy elements, always retrieve and understand the taxonomy
|
|
|
123
123
|
|
|
124
124
|
## MCP Tool Usage Guidelines
|
|
125
125
|
|
|
126
|
+
### ID Reference Preferences
|
|
127
|
+
|
|
126
128
|
**CRITICAL**: When using MCP tools, always prefer internal IDs over codenames:
|
|
127
129
|
|
|
128
130
|
- **Content Items**: Use internal IDs to reference content items
|
|
@@ -143,4 +145,12 @@ When working with taxonomy elements, always retrieve and understand the taxonomy
|
|
|
143
145
|
- Debugging and logging
|
|
144
146
|
- Initial content setup when IDs are not yet known
|
|
145
147
|
|
|
146
|
-
All MCP tools have been optimized to work with internal IDs for maximum efficiency
|
|
148
|
+
All MCP tools have been optimized to work with internal IDs for maximum efficiency.
|
|
149
|
+
|
|
150
|
+
### Content Search Tools
|
|
151
|
+
|
|
152
|
+
The MCP server provides two search tools with distinct purposes:
|
|
153
|
+
- **filter-variants-mapi**: Exact keyword matching with advanced filtering capabilities
|
|
154
|
+
- **search-variants-mapi**: AI-powered semantic/conceptual search (when available)
|
|
155
|
+
|
|
156
|
+
See each tool's description for detailed usage guidelines and selection criteria.`;
|
|
@@ -2,7 +2,7 @@ import { z } from "zod";
|
|
|
2
2
|
import { createMapiClient } from "../clients/kontentClients.js";
|
|
3
3
|
import { handleMcpToolError } from "../utils/errorHandler.js";
|
|
4
4
|
import { createMcpToolSuccessResponse } from "../utils/responseHelper.js";
|
|
5
|
-
export const registerTool = (server
|
|
5
|
+
export const registerTool = (server) => {
|
|
6
6
|
server.tool("create-variant-version-mapi", "Create new version of Kontent.ai language variant via Management API. This operation creates a new version of an existing language variant, useful for content versioning and creating new drafts from published content.", {
|
|
7
7
|
itemId: z
|
|
8
8
|
.string()
|
|
@@ -13,7 +13,7 @@ export const registerTool = (server, config) => {
|
|
|
13
13
|
.uuid()
|
|
14
14
|
.describe("Internal ID (UUID) of the language variant to create a new version of. Use '00000000-0000-0000-0000-000000000000' for the default language"),
|
|
15
15
|
}, async ({ itemId, languageId }, { authInfo: { token, clientId } = {} }) => {
|
|
16
|
-
const client = createMapiClient(clientId, token
|
|
16
|
+
const client = createMapiClient(clientId, token);
|
|
17
17
|
try {
|
|
18
18
|
const response = await client
|
|
19
19
|
.createNewVersionOfLanguageVariant()
|
|
@@ -22,7 +22,7 @@ export const registerTool = (server, config) => {
|
|
|
22
22
|
.toPromise();
|
|
23
23
|
return createMcpToolSuccessResponse({
|
|
24
24
|
message: `Successfully created new version of language variant '${languageId}' for content item '${itemId}'`,
|
|
25
|
-
result: response.
|
|
25
|
+
result: response.rawData,
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
28
|
catch (error) {
|
|
@@ -2,11 +2,11 @@ import { z } from "zod";
|
|
|
2
2
|
import { createMapiClient } from "../clients/kontentClients.js";
|
|
3
3
|
import { handleMcpToolError } from "../utils/errorHandler.js";
|
|
4
4
|
import { createMcpToolSuccessResponse } from "../utils/responseHelper.js";
|
|
5
|
-
export const registerTool = (server
|
|
5
|
+
export const registerTool = (server) => {
|
|
6
6
|
server.tool("delete-content-item-mapi", "Delete Kontent.ai content item by internal ID from Management API", {
|
|
7
7
|
id: z.string().describe("Internal ID of the content item to delete"),
|
|
8
8
|
}, async ({ id }, { authInfo: { token, clientId } = {} }) => {
|
|
9
|
-
const client = createMapiClient(clientId, token
|
|
9
|
+
const client = createMapiClient(clientId, token);
|
|
10
10
|
try {
|
|
11
11
|
const response = await client
|
|
12
12
|
.deleteContentItem()
|
|
@@ -14,7 +14,7 @@ export const registerTool = (server, config) => {
|
|
|
14
14
|
.toPromise();
|
|
15
15
|
return createMcpToolSuccessResponse({
|
|
16
16
|
message: `Content item '${id}' deleted successfully`,
|
|
17
|
-
deletedItem: response.
|
|
17
|
+
deletedItem: response.rawData,
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
catch (error) {
|