@contentful/mcp-server 1.0.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/LICENSE +21 -0
- package/README.md +165 -0
- package/build/config/contentful.js +19 -0
- package/build/config/env.js +25 -0
- package/build/config/version.js +2 -0
- package/build/index.js +33 -0
- package/build/prompts/register.js +1 -0
- package/build/resources/register.js +1 -0
- package/build/tools/ai-actions/createAiAction.js +55 -0
- package/build/tools/ai-actions/deleteAiAction.js +20 -0
- package/build/tools/ai-actions/getAiAction.js +20 -0
- package/build/tools/ai-actions/getAiActionInvocation.js +21 -0
- package/build/tools/ai-actions/invokeAiAction.js +74 -0
- package/build/tools/ai-actions/listAiActions.js +65 -0
- package/build/tools/ai-actions/publishAiAction.js +34 -0
- package/build/tools/ai-actions/register.js +20 -0
- package/build/tools/ai-actions/unpublishAiAction.js +28 -0
- package/build/tools/ai-actions/updateAiAction.js +64 -0
- package/build/tools/assets/deleteAsset.js +20 -0
- package/build/tools/assets/getAsset.js +18 -0
- package/build/tools/assets/listAssets.js +68 -0
- package/build/tools/assets/publishAsset.js +58 -0
- package/build/tools/assets/register.js +16 -0
- package/build/tools/assets/unpublishAsset.js +58 -0
- package/build/tools/assets/updateAsset.js +42 -0
- package/build/tools/assets/uploadAsset.js +51 -0
- package/build/tools/context/getInitialContextTool.js +41 -0
- package/build/tools/context/instructions.js +111 -0
- package/build/tools/context/middleware.js +8 -0
- package/build/tools/context/register.js +4 -0
- package/build/tools/context/store.js +15 -0
- package/build/tools/entries/createEntry.js +39 -0
- package/build/tools/entries/deleteEntry.js +21 -0
- package/build/tools/entries/getEntry.js +18 -0
- package/build/tools/entries/publishEntry.js +58 -0
- package/build/tools/entries/register.js +16 -0
- package/build/tools/entries/searchEntries.js +50 -0
- package/build/tools/entries/unpublishEntry.js +58 -0
- package/build/tools/entries/updateEntry.js +50 -0
- package/build/tools/environments/createEnvironment.js +21 -0
- package/build/tools/environments/deleteEnvironment.js +19 -0
- package/build/tools/environments/listEnvironments.js +62 -0
- package/build/tools/environments/register.js +8 -0
- package/build/tools/locales/createLocale.js +49 -0
- package/build/tools/locales/deleteLocale.js +21 -0
- package/build/tools/locales/getLocale.js +18 -0
- package/build/tools/locales/listLocales.js +61 -0
- package/build/tools/locales/register.js +12 -0
- package/build/tools/locales/updateLocale.js +47 -0
- package/build/tools/register.js +20 -0
- package/build/tools/spaces/getSpace.js +20 -0
- package/build/tools/spaces/listSpaces.js +53 -0
- package/build/tools/spaces/register.js +6 -0
- package/build/tools/tags/createTag.js +24 -0
- package/build/tools/tags/listTags.js +50 -0
- package/build/tools/tags/register.js +6 -0
- package/build/tools/types/createContentType.js +33 -0
- package/build/tools/types/deleteContentType.js +20 -0
- package/build/tools/types/getContentType.js +24 -0
- package/build/tools/types/listContentTypes.js +59 -0
- package/build/tools/types/publishContentType.js +22 -0
- package/build/tools/types/register.js +16 -0
- package/build/tools/types/unpublishContentType.js +20 -0
- package/build/tools/types/updateContentType.js +78 -0
- package/build/types/fieldSchema.js +29 -0
- package/build/utils/ai-actions.js +46 -0
- package/build/utils/bulkOperations.js +94 -0
- package/build/utils/formatters.js +39 -0
- package/build/utils/getVersion.js +11 -0
- package/build/utils/response.js +37 -0
- package/build/utils/summarizer.js +39 -0
- package/build/utils/tools.js +20 -0
- package/package.json +64 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { formatResponse } from './formatters.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a standardized success response
|
|
4
|
+
*/
|
|
5
|
+
export function createSuccessResponse(message, data) {
|
|
6
|
+
const text = data ? formatResponse(message, data) : message;
|
|
7
|
+
return {
|
|
8
|
+
content: [
|
|
9
|
+
{
|
|
10
|
+
type: 'text',
|
|
11
|
+
text,
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Higher-order function that wraps tool handlers with standardized error handling
|
|
18
|
+
*/
|
|
19
|
+
export function withErrorHandling(handler, errorPrefix = 'Error') {
|
|
20
|
+
return async (params, extra) => {
|
|
21
|
+
try {
|
|
22
|
+
return await handler(params, extra);
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
26
|
+
return {
|
|
27
|
+
isError: true,
|
|
28
|
+
content: [
|
|
29
|
+
{
|
|
30
|
+
type: 'text',
|
|
31
|
+
text: `${errorPrefix}: ${errorMessage}`,
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export const summarizeData = (data, options = {}) => {
|
|
2
|
+
const { maxItems = 3, remainingMessage = 'To see more items, please ask me to retrieve the next page.', } = options;
|
|
3
|
+
// Handle Contentful-style responses with items and total
|
|
4
|
+
if (data && typeof data === 'object' && 'items' in data && 'total' in data) {
|
|
5
|
+
const items = data.items;
|
|
6
|
+
const total = data.total;
|
|
7
|
+
// Type guard to ensure items is an array and total is a number
|
|
8
|
+
if (!Array.isArray(items) || typeof total !== 'number') {
|
|
9
|
+
return data;
|
|
10
|
+
}
|
|
11
|
+
if (items.length <= maxItems) {
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
items: items.slice(0, maxItems),
|
|
16
|
+
total: total,
|
|
17
|
+
showing: maxItems,
|
|
18
|
+
remaining: total - maxItems,
|
|
19
|
+
message: remainingMessage,
|
|
20
|
+
skip: maxItems, // Add skip value for next page
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
// Handle plain arrays
|
|
24
|
+
if (Array.isArray(data)) {
|
|
25
|
+
if (data.length <= maxItems) {
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
items: data.slice(0, maxItems),
|
|
30
|
+
total: data.length,
|
|
31
|
+
showing: maxItems,
|
|
32
|
+
remaining: data.length - maxItems,
|
|
33
|
+
message: remainingMessage,
|
|
34
|
+
skip: maxItems, // Add skip value for next page
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
// Return non-array data as-is (cast to expected return type)
|
|
38
|
+
return data;
|
|
39
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import ctfl from 'contentful-management';
|
|
2
|
+
import { getDefaultClientConfig } from '../config/contentful.js';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
export const BaseToolSchema = z.object({
|
|
5
|
+
spaceId: z.string().describe('The ID of the Contentful space'),
|
|
6
|
+
environmentId: z.string().describe('The ID of the Contentful environment'),
|
|
7
|
+
});
|
|
8
|
+
/**
|
|
9
|
+
* Creates a Contentful client with the correct configuration based on resource parameters
|
|
10
|
+
*
|
|
11
|
+
* @param params - Tool parameters that may include a resource
|
|
12
|
+
* @returns Configured Contentful client
|
|
13
|
+
*/
|
|
14
|
+
export function createToolClient(params) {
|
|
15
|
+
const clientConfig = getDefaultClientConfig();
|
|
16
|
+
if (params.spaceId) {
|
|
17
|
+
clientConfig.space = params.spaceId;
|
|
18
|
+
}
|
|
19
|
+
return ctfl.createClient(clientConfig, { type: 'plain' });
|
|
20
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@contentful/mcp-server",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "https://github.com/contentful/contentful-mcp-server"
|
|
7
|
+
},
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"type": "module",
|
|
10
|
+
"bin": {
|
|
11
|
+
"contentful-mcp-server": "./build/index.js"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"build"
|
|
15
|
+
],
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=22.0.0",
|
|
18
|
+
"npm": ">=10.0.0"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc",
|
|
22
|
+
"dev": "nodemon --ext ts --ignore build/ --watch src/ --exec 'npm run build && npm start'",
|
|
23
|
+
"format": "prettier --write .",
|
|
24
|
+
"lint": "eslint .",
|
|
25
|
+
"lint:fix": "eslint . --fix",
|
|
26
|
+
"start": "node build/index.js",
|
|
27
|
+
"test": "vitest",
|
|
28
|
+
"test:run": "vitest run",
|
|
29
|
+
"inspect": "node -r dotenv/config ./scripts/inspect.js",
|
|
30
|
+
"inspect:watch": "node ./scripts/inspect-watch.js",
|
|
31
|
+
"logs:watch": "npx mcps-logger",
|
|
32
|
+
"update-licenses": "node scripts/update-licenses.js",
|
|
33
|
+
"prepare": "husky"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@modelcontextprotocol/sdk": "^1.16.0",
|
|
37
|
+
"contentful-management": "^11.52.2",
|
|
38
|
+
"dotenv": "^16.4.7",
|
|
39
|
+
"fast-xml-parser": "^5.2.0",
|
|
40
|
+
"get-it": "^8.6.10",
|
|
41
|
+
"gpt-tokenizer": "^2.9.0",
|
|
42
|
+
"outdent": "^0.8.0",
|
|
43
|
+
"zod": "^3.24.2"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@commitlint/cli": "^19.8.1",
|
|
47
|
+
"@commitlint/config-conventional": "^19.8.1",
|
|
48
|
+
"@modelcontextprotocol/inspector": "0.15.0",
|
|
49
|
+
"@nx/js": "^21.3.2",
|
|
50
|
+
"@types/node": "^22.13.11",
|
|
51
|
+
"@typescript-eslint/eslint-plugin": "^8.29.1",
|
|
52
|
+
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
53
|
+
"eslint-plugin-unused-imports": "^4.1.4",
|
|
54
|
+
"husky": "^9.1.7",
|
|
55
|
+
"mcps-logger": "^1.0.0",
|
|
56
|
+
"nodemon": "^3.1.0",
|
|
57
|
+
"nx": "^21.2.3",
|
|
58
|
+
"prettier": "^3.6.2",
|
|
59
|
+
"pretty-quick": "^4.2.2",
|
|
60
|
+
"ts-node": "^10.9.2",
|
|
61
|
+
"typescript": "^5.8.2",
|
|
62
|
+
"vitest": "^3.2.1"
|
|
63
|
+
}
|
|
64
|
+
}
|