microcms-mcp-server 0.6.0 → 0.9.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 +142 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +112 -25
- package/dist/cli.js.map +1 -1
- package/dist/client.d.ts +117 -28
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +293 -48
- package/dist/client.js.map +1 -1
- package/dist/config.d.ts +24 -5
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +146 -2
- package/dist/config.js.map +1 -1
- package/dist/constants.d.ts +1 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +17 -1
- package/dist/constants.js.map +1 -1
- package/dist/index.js +31 -2
- package/dist/index.js.map +1 -1
- package/dist/server.d.ts +8 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +183 -144
- package/dist/server.js.map +1 -1
- package/dist/tools/create-content-draft.d.ts +2 -2
- package/dist/tools/create-content-draft.d.ts.map +1 -1
- package/dist/tools/create-content-draft.js +7 -3
- package/dist/tools/create-content-draft.js.map +1 -1
- package/dist/tools/create-content-published.d.ts +2 -2
- package/dist/tools/create-content-published.d.ts.map +1 -1
- package/dist/tools/create-content-published.js +7 -3
- package/dist/tools/create-content-published.js.map +1 -1
- package/dist/tools/create-contents-bulk.d.ts +7 -0
- package/dist/tools/create-contents-bulk.d.ts.map +1 -0
- package/dist/tools/create-contents-bulk.js +130 -0
- package/dist/tools/create-contents-bulk.js.map +1 -0
- package/dist/tools/delete-content.d.ts +2 -2
- package/dist/tools/delete-content.d.ts.map +1 -1
- package/dist/tools/delete-content.js +6 -2
- package/dist/tools/delete-content.js.map +1 -1
- package/dist/tools/delete-media.d.ts +2 -2
- package/dist/tools/delete-media.d.ts.map +1 -1
- package/dist/tools/delete-media.js +6 -2
- package/dist/tools/delete-media.js.map +1 -1
- package/dist/tools/get-api-info.d.ts +2 -2
- package/dist/tools/get-api-info.d.ts.map +1 -1
- package/dist/tools/get-api-info.js +6 -2
- package/dist/tools/get-api-info.js.map +1 -1
- package/dist/tools/get-apis-list.d.ts +2 -2
- package/dist/tools/get-apis-list.d.ts.map +1 -1
- package/dist/tools/get-apis-list.js +9 -4
- package/dist/tools/get-apis-list.js.map +1 -1
- package/dist/tools/get-content-meta.d.ts +2 -2
- package/dist/tools/get-content-meta.d.ts.map +1 -1
- package/dist/tools/get-content-meta.js +6 -2
- package/dist/tools/get-content-meta.js.map +1 -1
- package/dist/tools/get-content.d.ts +2 -2
- package/dist/tools/get-content.d.ts.map +1 -1
- package/dist/tools/get-content.js +6 -2
- package/dist/tools/get-content.js.map +1 -1
- package/dist/tools/get-list-meta.d.ts +2 -2
- package/dist/tools/get-list-meta.d.ts.map +1 -1
- package/dist/tools/get-list-meta.js +6 -2
- package/dist/tools/get-list-meta.js.map +1 -1
- package/dist/tools/get-list.d.ts +2 -2
- package/dist/tools/get-list.d.ts.map +1 -1
- package/dist/tools/get-list.js +6 -2
- package/dist/tools/get-list.js.map +1 -1
- package/dist/tools/get-media.d.ts +2 -2
- package/dist/tools/get-media.d.ts.map +1 -1
- package/dist/tools/get-media.js +9 -4
- package/dist/tools/get-media.js.map +1 -1
- package/dist/tools/get-member.d.ts +2 -2
- package/dist/tools/get-member.d.ts.map +1 -1
- package/dist/tools/get-member.js +6 -2
- package/dist/tools/get-member.js.map +1 -1
- package/dist/tools/get-services.d.ts +19 -0
- package/dist/tools/get-services.d.ts.map +1 -0
- package/dist/tools/get-services.js +48 -0
- package/dist/tools/get-services.js.map +1 -0
- package/dist/tools/patch-content-created-by.d.ts +2 -2
- package/dist/tools/patch-content-created-by.d.ts.map +1 -1
- package/dist/tools/patch-content-created-by.js +10 -3
- package/dist/tools/patch-content-created-by.js.map +1 -1
- package/dist/tools/patch-content-status.d.ts +2 -2
- package/dist/tools/patch-content-status.d.ts.map +1 -1
- package/dist/tools/patch-content-status.js +6 -2
- package/dist/tools/patch-content-status.js.map +1 -1
- package/dist/tools/patch-content.d.ts +2 -2
- package/dist/tools/patch-content.d.ts.map +1 -1
- package/dist/tools/patch-content.js +8 -3
- package/dist/tools/patch-content.js.map +1 -1
- package/dist/tools/update-content-draft.d.ts +2 -2
- package/dist/tools/update-content-draft.d.ts.map +1 -1
- package/dist/tools/update-content-draft.js +7 -3
- package/dist/tools/update-content-draft.js.map +1 -1
- package/dist/tools/update-content-published.d.ts +2 -2
- package/dist/tools/update-content-published.d.ts.map +1 -1
- package/dist/tools/update-content-published.js +7 -3
- package/dist/tools/update-content-published.js.map +1 -1
- package/dist/tools/upload-media.d.ts +2 -2
- package/dist/tools/upload-media.d.ts.map +1 -1
- package/dist/tools/upload-media.js +12 -6
- package/dist/tools/upload-media.js.map +1 -1
- package/dist/transport/http.d.ts +4 -0
- package/dist/transport/http.d.ts.map +1 -0
- package/dist/transport/http.js +63 -0
- package/dist/transport/http.js.map +1 -0
- package/dist/transport/index.d.ts +4 -0
- package/dist/transport/index.d.ts.map +1 -0
- package/dist/transport/index.js +12 -0
- package/dist/transport/index.js.map +1 -0
- package/dist/transport/stdio.d.ts +3 -0
- package/dist/transport/stdio.d.ts.map +1 -0
- package/dist/transport/stdio.js +6 -0
- package/dist/transport/stdio.js.map +1 -0
- package/dist/types.d.ts +98 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +11 -8
- package/dist/tools/get-contents-list-management.d.ts +0 -5
- package/dist/tools/get-contents-list-management.d.ts.map +0 -1
- package/dist/tools/get-contents-list-management.js +0 -39
- package/dist/tools/get-contents-list-management.js.map +0 -1
package/dist/config.js
CHANGED
|
@@ -1,4 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse and validate service configuration from environment variables or command line arguments.
|
|
3
|
+
*
|
|
4
|
+
* Supports two modes:
|
|
5
|
+
* 1. Single service mode (legacy): MICROCMS_SERVICE_ID + MICROCMS_API_KEY
|
|
6
|
+
* 2. Multi service mode: MICROCMS_SERVICES (JSON array)
|
|
7
|
+
*
|
|
8
|
+
* If MICROCMS_SERVICES is set, it takes priority over the legacy single service config.
|
|
9
|
+
*/
|
|
1
10
|
export function parseConfig() {
|
|
11
|
+
// Check for multi-service configuration first (takes priority)
|
|
12
|
+
const servicesJson = process.env.MICROCMS_SERVICES;
|
|
13
|
+
if (servicesJson) {
|
|
14
|
+
return parseMultiServiceConfig(servicesJson);
|
|
15
|
+
}
|
|
16
|
+
// Fall back to single service configuration (legacy)
|
|
17
|
+
return parseSingleServiceConfig();
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Parse multi-service configuration from JSON string
|
|
21
|
+
*/
|
|
22
|
+
function parseMultiServiceConfig(jsonString) {
|
|
23
|
+
let services;
|
|
24
|
+
try {
|
|
25
|
+
services = JSON.parse(jsonString);
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
throw new Error('Invalid MICROCMS_SERVICES JSON format.\n' +
|
|
29
|
+
'Expected format: [{"id": "service-id", "apiKey": "api-key"}, ...]\n' +
|
|
30
|
+
`Parse error: ${error instanceof Error ? error.message : String(error)}`);
|
|
31
|
+
}
|
|
32
|
+
if (!Array.isArray(services)) {
|
|
33
|
+
throw new Error('MICROCMS_SERVICES must be a JSON array.\n' +
|
|
34
|
+
'Expected format: [{"id": "service-id", "apiKey": "api-key"}, ...]');
|
|
35
|
+
}
|
|
36
|
+
if (services.length === 0) {
|
|
37
|
+
throw new Error('MICROCMS_SERVICES array cannot be empty.');
|
|
38
|
+
}
|
|
39
|
+
// Validate each service configuration
|
|
40
|
+
const seenIds = new Set();
|
|
41
|
+
for (let i = 0; i < services.length; i++) {
|
|
42
|
+
const service = services[i];
|
|
43
|
+
if (!service || typeof service !== 'object') {
|
|
44
|
+
throw new Error(`MICROCMS_SERVICES[${i}]: Invalid service configuration.`);
|
|
45
|
+
}
|
|
46
|
+
if (!service.id || typeof service.id !== 'string') {
|
|
47
|
+
throw new Error(`MICROCMS_SERVICES[${i}]: Missing or invalid "id" field.`);
|
|
48
|
+
}
|
|
49
|
+
if (!service.apiKey || typeof service.apiKey !== 'string') {
|
|
50
|
+
throw new Error(`MICROCMS_SERVICES[${i}]: Missing or invalid "apiKey" field.`);
|
|
51
|
+
}
|
|
52
|
+
if (seenIds.has(service.id)) {
|
|
53
|
+
throw new Error(`MICROCMS_SERVICES: Duplicate service id "${service.id}".`);
|
|
54
|
+
}
|
|
55
|
+
seenIds.add(service.id);
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
mode: 'multi',
|
|
59
|
+
services,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Parse single service configuration from environment variables or command line arguments (legacy mode)
|
|
64
|
+
*/
|
|
65
|
+
function parseSingleServiceConfig() {
|
|
2
66
|
const args = process.argv.slice(2);
|
|
3
67
|
// Parse command line arguments
|
|
4
68
|
let serviceDomain;
|
|
@@ -16,12 +80,92 @@ export function parseConfig() {
|
|
|
16
80
|
apiKey = apiKey || process.env.MICROCMS_API_KEY;
|
|
17
81
|
if (!serviceDomain || !apiKey) {
|
|
18
82
|
throw new Error('microCMS credentials are required. Provide them via:\n' +
|
|
19
|
-
'
|
|
20
|
-
'
|
|
83
|
+
' Single service mode:\n' +
|
|
84
|
+
' Command line: --service-id <service-id> --api-key <key>\n' +
|
|
85
|
+
' Environment variables: MICROCMS_SERVICE_ID and MICROCMS_API_KEY\n' +
|
|
86
|
+
' Multi service mode:\n' +
|
|
87
|
+
' Environment variable: MICROCMS_SERVICES (JSON array)\n' +
|
|
88
|
+
' Example: MICROCMS_SERVICES=\'[{"id":"blog","apiKey":"xxx"}]\'');
|
|
21
89
|
}
|
|
22
90
|
return {
|
|
91
|
+
mode: 'single',
|
|
23
92
|
serviceDomain,
|
|
24
93
|
apiKey,
|
|
25
94
|
};
|
|
26
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Parse transport configuration from environment variables and CLI arguments.
|
|
98
|
+
*/
|
|
99
|
+
export function parseTransportConfig() {
|
|
100
|
+
const args = process.argv.slice(2);
|
|
101
|
+
let mode = 'stdio';
|
|
102
|
+
let host = '0.0.0.0';
|
|
103
|
+
let port = 3000;
|
|
104
|
+
// CLI arguments take priority
|
|
105
|
+
const transportIndex = args.indexOf('--transport');
|
|
106
|
+
if (transportIndex !== -1 && transportIndex + 1 < args.length) {
|
|
107
|
+
const value = args[transportIndex + 1];
|
|
108
|
+
if (value === 'stdio' || value === 'http') {
|
|
109
|
+
mode = value;
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
// biome-ignore lint/suspicious/noConsole: intentional warning to stderr
|
|
113
|
+
console.error(`Warning: Invalid transport mode "${value}". Expected "stdio" or "http". Falling back to "stdio".`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const portIndex = args.indexOf('--port');
|
|
117
|
+
if (portIndex !== -1 && portIndex + 1 < args.length) {
|
|
118
|
+
const parsed = parseInt(args[portIndex + 1], 10);
|
|
119
|
+
if (!Number.isNaN(parsed)) {
|
|
120
|
+
port = parsed;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const hostIndex = args.indexOf('--host');
|
|
124
|
+
if (hostIndex !== -1 && hostIndex + 1 < args.length) {
|
|
125
|
+
host = args[hostIndex + 1];
|
|
126
|
+
}
|
|
127
|
+
// Environment variables as fallback
|
|
128
|
+
const envTransport = process.env.MCP_TRANSPORT;
|
|
129
|
+
if (!args.includes('--transport') && envTransport) {
|
|
130
|
+
if (envTransport === 'stdio' || envTransport === 'http') {
|
|
131
|
+
mode = envTransport;
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
// biome-ignore lint/suspicious/noConsole: intentional warning to stderr
|
|
135
|
+
console.error(`Warning: Invalid MCP_TRANSPORT value "${envTransport}". Expected "stdio" or "http". Falling back to "stdio".`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const envPort = process.env.MCP_HTTP_PORT;
|
|
139
|
+
if (!args.includes('--port') && envPort) {
|
|
140
|
+
const parsed = parseInt(envPort, 10);
|
|
141
|
+
if (!Number.isNaN(parsed)) {
|
|
142
|
+
port = parsed;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const envHost = process.env.MCP_HTTP_HOST;
|
|
146
|
+
if (!args.includes('--host') && envHost) {
|
|
147
|
+
host = envHost;
|
|
148
|
+
}
|
|
149
|
+
return { mode, host, port };
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Parse authentication configuration from environment variables.
|
|
153
|
+
*/
|
|
154
|
+
export function parseAuthConfig() {
|
|
155
|
+
const bearerToken = process.env.MCP_AUTH_TOKEN;
|
|
156
|
+
return {
|
|
157
|
+
enabled: !!bearerToken,
|
|
158
|
+
bearerToken,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Parse the full application configuration including services, transport, and auth.
|
|
163
|
+
*/
|
|
164
|
+
export function parseFullConfig() {
|
|
165
|
+
return {
|
|
166
|
+
services: parseConfig(),
|
|
167
|
+
transport: parseTransportConfig(),
|
|
168
|
+
auth: parseAuthConfig(),
|
|
169
|
+
};
|
|
170
|
+
}
|
|
27
171
|
//# sourceMappingURL=config.js.map
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAqBA;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW;IACzB,+DAA+D;IAC/D,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;IACnD,IAAI,YAAY,EAAE,CAAC;QACjB,OAAO,uBAAuB,CAAC,YAAY,CAAC,CAAC;IAC/C,CAAC;IAED,qDAAqD;IACrD,OAAO,wBAAwB,EAAE,CAAC;AACpC,CAAC;AAED;;GAEG;AACH,SAAS,uBAAuB,CAAC,UAAkB;IACjD,IAAI,QAAyB,CAAC;IAE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AC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe;IAC7B,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;IAE/C,OAAO;QACL,OAAO,EAAE,CAAC,CAAC,WAAW;QACtB,WAAW;KACZ,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe;IAC7B,OAAO;QACL,QAAQ,EAAE,WAAW,EAAE;QACvB,SAAS,EAAE,oBAAoB,EAAE;QACjC,IAAI,EAAE,eAAe,EAAE;KACxB,CAAC;AACJ,CAAC"}
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const FIELD_FORMATS_DESCRIPTION = "\n Create new content in microCMS and publish it immediately. \n\n ## Important\n Ensure that the \"content\" you submit strictly adheres to the following specifications.\n In particular, take extra care when handling custom fields, as mistakes are common in their structure. \n Read the instructions thoroughly and construct the data precisely as described.\n \n ## Field type specifications\n \n * Image fields require URL string uploaded to microCMS media library (e.g., \"https://images.microcms-assets.io/assets/xxx/yyy/sample.png\"). \n * Multiple image fields use array format. \n * Rich editor fields expect HTML strings. \n * Date fields use ISO 8601 format. \n * Select fields use arrays. \n * Content reference fields use contentId strings or arrays for multiple references, and you can get contentIds from microcms_get_list tool. \n * Custom field exepect below struct:\n ```json\n <field Id in apiFields> {\n \"fieldId\": \"<target custom field id in customFields>\"\n \"key1\": \"<value1>\",\n \"key2\": \"<value2>\",\n }\n ```\n ";
|
|
1
|
+
export declare const FIELD_FORMATS_DESCRIPTION = "\n Create new content in microCMS and publish it immediately. \n\n ## Important\n Ensure that the \"content\" you submit strictly adheres to the following specifications.\n In particular, take extra care when handling custom fields and iframe fields, as mistakes are common in their structure. \n Read the instructions thoroughly and construct the data precisely as described.\n In particular, for extended fields (iframe fields), you need to take care to call microcms_get_list tool beforehand, and set its structure to the \"data\" field (Detail is described below).\n \n ## Field type specifications\n \n * Image fields require URL string uploaded to microCMS media library (e.g., \"https://images.microcms-assets.io/assets/xxx/yyy/sample.png\"). \n * Multiple image fields use array format. \n * Rich editor fields expect HTML strings. \n * Date fields use ISO 8601 format. \n * Select fields use arrays. \n * Content reference fields use contentId strings or arrays for multiple references, and you can get contentIds from microcms_get_list tool. \n * Custom field exepect below struct:\n ```json\n <field Id in apiFields> {\n \"fieldId\": \"<target custom field id in customFields>\"\n \"key1\": \"<value1>\",\n \"key2\": \"<value2>\",\n }\n ```\n* iframe field (Extension field) expects the following structure for CREATE/UPDATE:\n```json\n {\n \"id\": \"some-id\",\n \"title\": \"some-title\",\n \"description\": \"some-description\",\n \"imageUrl\": \"https://images.microcms-assets.io/assets/xxxx/yyyy/{fileName}.png\",\n \"updatedAt\": \"2024-01-01T00:00:00Z\",\n \"data\": { \"key1\": \"value1\", \"key2\": \"value2\" }\n }\n```\n * **IMPORTANT**: When retrieving content via API, only the \"data\" object content is returned (without the wrapper).\n * **IMPORTANT**: When creating/updating content, you MUST provide the full structure including id, title, description, imageUrl, updatedAt, and data.\n * To understand the \"data\" structure, ALWAYS use microcms_get_list to retrieve existing content first and examine the field structure.\n * \"id\", \"title\", \"description\", \"imageUrl\" are metadata displayed in the admin screen and are not included in the API GET response.\n ";
|
|
2
2
|
//# sourceMappingURL=constants.d.ts.map
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,yBAAyB,
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,yBAAyB,+sEAwCnC,CAAC"}
|
package/dist/constants.js
CHANGED
|
@@ -3,8 +3,9 @@ export const FIELD_FORMATS_DESCRIPTION = `
|
|
|
3
3
|
|
|
4
4
|
## Important
|
|
5
5
|
Ensure that the "content" you submit strictly adheres to the following specifications.
|
|
6
|
-
In particular, take extra care when handling custom fields, as mistakes are common in their structure.
|
|
6
|
+
In particular, take extra care when handling custom fields and iframe fields, as mistakes are common in their structure.
|
|
7
7
|
Read the instructions thoroughly and construct the data precisely as described.
|
|
8
|
+
In particular, for extended fields (iframe fields), you need to take care to call microcms_get_list tool beforehand, and set its structure to the "data" field (Detail is described below).
|
|
8
9
|
|
|
9
10
|
## Field type specifications
|
|
10
11
|
|
|
@@ -22,5 +23,20 @@ export const FIELD_FORMATS_DESCRIPTION = `
|
|
|
22
23
|
"key2": "<value2>",
|
|
23
24
|
}
|
|
24
25
|
\`\`\`
|
|
26
|
+
* iframe field (Extension field) expects the following structure for CREATE/UPDATE:
|
|
27
|
+
\`\`\`json
|
|
28
|
+
{
|
|
29
|
+
"id": "some-id",
|
|
30
|
+
"title": "some-title",
|
|
31
|
+
"description": "some-description",
|
|
32
|
+
"imageUrl": "https://images.microcms-assets.io/assets/xxxx/yyyy/{fileName}.png",
|
|
33
|
+
"updatedAt": "2024-01-01T00:00:00Z",
|
|
34
|
+
"data": { "key1": "value1", "key2": "value2" }
|
|
35
|
+
}
|
|
36
|
+
\`\`\`
|
|
37
|
+
* **IMPORTANT**: When retrieving content via API, only the "data" object content is returned (without the wrapper).
|
|
38
|
+
* **IMPORTANT**: When creating/updating content, you MUST provide the full structure including id, title, description, imageUrl, updatedAt, and data.
|
|
39
|
+
* To understand the "data" structure, ALWAYS use microcms_get_list to retrieve existing content first and examine the field structure.
|
|
40
|
+
* "id", "title", "description", "imageUrl" are metadata displayed in the admin screen and are not included in the API GET response.
|
|
25
41
|
`;
|
|
26
42
|
//# sourceMappingURL=constants.js.map
|
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,yBAAyB,GAAG
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,yBAAyB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCtC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,36 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { parseFullConfig } from './config.js';
|
|
3
|
+
import { createMcpServer, initializeClients } from './server.js';
|
|
4
|
+
import { startTransport } from './transport/index.js';
|
|
3
5
|
async function main() {
|
|
4
|
-
|
|
6
|
+
try {
|
|
7
|
+
// Parse full configuration (services + transport + auth)
|
|
8
|
+
const fullConfig = parseFullConfig();
|
|
9
|
+
// Initialize microCMS clients
|
|
10
|
+
const serviceConfig = initializeClients();
|
|
11
|
+
// Log mode information
|
|
12
|
+
if (serviceConfig.mode === 'single') {
|
|
13
|
+
// biome-ignore lint/suspicious/noConsole: intentional startup log to stderr
|
|
14
|
+
console.error(`microCMS MCP Server starting in single-service mode (service: ${serviceConfig.serviceDomain})`);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
const serviceIds = serviceConfig.services.map((s) => s.id).join(', ');
|
|
18
|
+
// biome-ignore lint/suspicious/noConsole: intentional startup log to stderr
|
|
19
|
+
console.error(`microCMS MCP Server starting in multi-service mode (services: ${serviceIds})`);
|
|
20
|
+
}
|
|
21
|
+
// Start transport
|
|
22
|
+
await startTransport(createMcpServer, fullConfig);
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
if (error instanceof Error &&
|
|
26
|
+
(error.message.includes('microCMS credentials') ||
|
|
27
|
+
error.message.includes('MICROCMS_SERVICES'))) {
|
|
28
|
+
// biome-ignore lint/suspicious/noConsole: intentional error output to stderr
|
|
29
|
+
console.error('Configuration Error:', error.message);
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
5
34
|
}
|
|
6
35
|
main();
|
|
7
36
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,KAAK,UAAU,IAAI;IACjB,IAAI,CAAC;QACH,yDAAyD;QACzD,MAAM,UAAU,GAAG,eAAe,EAAE,CAAC;QAErC,8BAA8B;QAC9B,MAAM,aAAa,GAAG,iBAAiB,EAAE,CAAC;QAE1C,uBAAuB;QACvB,IAAI,aAAa,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACpC,4EAA4E;YAC5E,OAAO,CAAC,KAAK,CACX,iEAAiE,aAAa,CAAC,aAAa,GAAG,CAChG,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,MAAM,UAAU,GAAG,aAAa,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACtE,4EAA4E;YAC5E,OAAO,CAAC,KAAK,CACX,iEAAiE,UAAU,GAAG,CAC/E,CAAC;QACJ,CAAC;QAED,kBAAkB;QAClB,MAAM,cAAc,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;IACpD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IACE,KAAK,YAAY,KAAK;YACtB,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAC;gBAC7C,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAC,EAC9C,CAAC;YACD,6EAA6E;YAC7E,OAAO,CAAC,KAAK,CAAC,sBAAsB,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;YACrD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC"}
|
package/dist/server.d.ts
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
2
|
+
import { initializeClients } from './client.js';
|
|
3
|
+
/**
|
|
4
|
+
* Create a new MCP Server instance with all tools and resources registered.
|
|
5
|
+
* This factory function creates independent server instances for each connection.
|
|
6
|
+
*/
|
|
7
|
+
export declare function createMcpServer(): Server;
|
|
8
|
+
export { initializeClients };
|
|
2
9
|
//# sourceMappingURL=server.d.ts.map
|
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAQnE,OAAO,EAIL,iBAAiB,EAClB,MAAM,aAAa,CAAC;AAuHrB;;;GAGG;AACH,wBAAgB,eAAe,IAAI,MAAM,CA0IxC;AAGD,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|
package/dist/server.js
CHANGED
|
@@ -1,157 +1,196 @@
|
|
|
1
1
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { createContentDraftTool, handleCreateContentDraft } from './tools/create-content-draft.js';
|
|
10
|
-
import { updateContentPublishedTool, handleUpdateContentPublished } from './tools/update-content-published.js';
|
|
11
|
-
import { updateContentDraftTool, handleUpdateContentDraft } from './tools/update-content-draft.js';
|
|
12
|
-
import { patchContentTool, handlePatchContent } from './tools/patch-content.js';
|
|
13
|
-
import { patchContentStatusTool, handlePatchContentStatus } from './tools/patch-content-status.js';
|
|
14
|
-
import { patchContentCreatedByTool, handlePatchContentCreatedBy } from './tools/patch-content-created-by.js';
|
|
15
|
-
import { deleteContentTool, handleDeleteContent } from './tools/delete-content.js';
|
|
16
|
-
import { getMediaTool, handleGetMedia } from './tools/get-media.js';
|
|
17
|
-
import { uploadMediaTool, handleUploadMedia } from './tools/upload-media.js';
|
|
2
|
+
import { CallToolRequestSchema, ListResourcesRequestSchema, ListToolsRequestSchema, ReadResourceRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
|
|
3
|
+
import { fetchApisForService, getAppConfig, getServiceInfo, initializeClients, } from './client.js';
|
|
4
|
+
// Import tool definitions and handlers
|
|
5
|
+
import { createContentDraftTool, handleCreateContentDraft, } from './tools/create-content-draft.js';
|
|
6
|
+
import { createContentPublishedTool, handleCreateContentPublished, } from './tools/create-content-published.js';
|
|
7
|
+
import { createContentsBulkDraftTool, createContentsBulkPublishedTool, handleCreateContentsBulkDraft, handleCreateContentsBulkPublished, } from './tools/create-contents-bulk.js';
|
|
8
|
+
import { deleteContentTool, handleDeleteContent, } from './tools/delete-content.js';
|
|
18
9
|
import { deleteMediaTool, handleDeleteMedia } from './tools/delete-media.js';
|
|
19
10
|
import { getApiInfoTool, handleGetApiInfo } from './tools/get-api-info.js';
|
|
20
11
|
import { getApiListTool, handleGetApiList } from './tools/get-apis-list.js';
|
|
12
|
+
import { getContentTool, handleGetContent } from './tools/get-content.js';
|
|
13
|
+
import { getContentMetaTool, handleGetContentMeta, } from './tools/get-content-meta.js';
|
|
14
|
+
import { getListTool, handleGetList } from './tools/get-list.js';
|
|
15
|
+
import { getListMetaTool, handleGetListMeta } from './tools/get-list-meta.js';
|
|
16
|
+
import { getMediaTool, handleGetMedia } from './tools/get-media.js';
|
|
21
17
|
import { getMemberTool, handleGetMember } from './tools/get-member.js';
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
case 'microcms_get_media':
|
|
98
|
-
result = await handleGetMedia(params);
|
|
99
|
-
break;
|
|
100
|
-
case 'microcms_upload_media':
|
|
101
|
-
result = await handleUploadMedia(params);
|
|
102
|
-
break;
|
|
103
|
-
case 'microcms_delete_media':
|
|
104
|
-
result = await handleDeleteMedia(params);
|
|
105
|
-
break;
|
|
106
|
-
case 'microcms_get_api_info':
|
|
107
|
-
result = await handleGetApiInfo(params);
|
|
108
|
-
break;
|
|
109
|
-
case 'microcms_get_api_list':
|
|
110
|
-
result = await handleGetApiList(params);
|
|
111
|
-
break;
|
|
112
|
-
case 'microcms_get_member':
|
|
113
|
-
result = await handleGetMember(params);
|
|
114
|
-
break;
|
|
115
|
-
default:
|
|
116
|
-
throw new Error(`Unknown tool: ${name}`);
|
|
117
|
-
}
|
|
18
|
+
import { getServicesTool, handleGetServices } from './tools/get-services.js';
|
|
19
|
+
import { handlePatchContent, patchContentTool } from './tools/patch-content.js';
|
|
20
|
+
import { handlePatchContentCreatedBy, patchContentCreatedByTool, } from './tools/patch-content-created-by.js';
|
|
21
|
+
import { handlePatchContentStatus, patchContentStatusTool, } from './tools/patch-content-status.js';
|
|
22
|
+
import { handleUpdateContentDraft, updateContentDraftTool, } from './tools/update-content-draft.js';
|
|
23
|
+
import { handleUpdateContentPublished, updateContentPublishedTool, } from './tools/update-content-published.js';
|
|
24
|
+
import { handleUploadMedia, uploadMediaTool } from './tools/upload-media.js';
|
|
25
|
+
// Fixed tool list (21 tools)
|
|
26
|
+
const tools = [
|
|
27
|
+
getServicesTool,
|
|
28
|
+
getListTool,
|
|
29
|
+
getListMetaTool,
|
|
30
|
+
getContentTool,
|
|
31
|
+
getContentMetaTool,
|
|
32
|
+
createContentPublishedTool,
|
|
33
|
+
createContentDraftTool,
|
|
34
|
+
createContentsBulkPublishedTool,
|
|
35
|
+
createContentsBulkDraftTool,
|
|
36
|
+
updateContentPublishedTool,
|
|
37
|
+
updateContentDraftTool,
|
|
38
|
+
patchContentTool,
|
|
39
|
+
patchContentStatusTool,
|
|
40
|
+
patchContentCreatedByTool,
|
|
41
|
+
deleteContentTool,
|
|
42
|
+
getMediaTool,
|
|
43
|
+
uploadMediaTool,
|
|
44
|
+
deleteMediaTool,
|
|
45
|
+
getApiInfoTool,
|
|
46
|
+
getApiListTool,
|
|
47
|
+
getMemberTool,
|
|
48
|
+
];
|
|
49
|
+
// Tool handlers map - using 'any' for generic handler type that accepts multiple tool parameter types
|
|
50
|
+
const toolHandlers = {
|
|
51
|
+
microcms_get_services: handleGetServices,
|
|
52
|
+
microcms_get_list: handleGetList,
|
|
53
|
+
microcms_get_list_meta: handleGetListMeta,
|
|
54
|
+
microcms_get_content: handleGetContent,
|
|
55
|
+
microcms_get_content_meta: handleGetContentMeta,
|
|
56
|
+
microcms_create_content_published: handleCreateContentPublished,
|
|
57
|
+
microcms_create_content_draft: handleCreateContentDraft,
|
|
58
|
+
microcms_create_contents_bulk_published: (params, serviceId) => handleCreateContentsBulkPublished(params, serviceId),
|
|
59
|
+
microcms_create_contents_bulk_draft: (params, serviceId) => handleCreateContentsBulkDraft(params, serviceId),
|
|
60
|
+
microcms_update_content_published: handleUpdateContentPublished,
|
|
61
|
+
microcms_update_content_draft: handleUpdateContentDraft,
|
|
62
|
+
microcms_patch_content: handlePatchContent,
|
|
63
|
+
microcms_patch_content_status: handlePatchContentStatus,
|
|
64
|
+
microcms_patch_content_created_by: handlePatchContentCreatedBy,
|
|
65
|
+
microcms_delete_content: handleDeleteContent,
|
|
66
|
+
microcms_get_media: handleGetMedia,
|
|
67
|
+
microcms_upload_media: handleUploadMedia,
|
|
68
|
+
microcms_delete_media: handleDeleteMedia,
|
|
69
|
+
microcms_get_api_info: handleGetApiInfo,
|
|
70
|
+
microcms_get_api_list: handleGetApiList,
|
|
71
|
+
microcms_get_member: handleGetMember,
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Create a new MCP Server instance with all tools and resources registered.
|
|
75
|
+
* This factory function creates independent server instances for each connection.
|
|
76
|
+
*/
|
|
77
|
+
export function createMcpServer() {
|
|
78
|
+
const server = new Server({
|
|
79
|
+
name: 'microcms-mcp-server',
|
|
80
|
+
version: '0.8.0',
|
|
81
|
+
}, {
|
|
82
|
+
capabilities: {
|
|
83
|
+
tools: {},
|
|
84
|
+
resources: {},
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
// List available tools
|
|
88
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
89
|
+
return { tools };
|
|
90
|
+
});
|
|
91
|
+
// List available resources
|
|
92
|
+
server.setRequestHandler(ListResourcesRequestSchema, async () => {
|
|
118
93
|
return {
|
|
119
|
-
|
|
94
|
+
resources: [
|
|
120
95
|
{
|
|
121
|
-
|
|
122
|
-
|
|
96
|
+
uri: 'microcms://services',
|
|
97
|
+
name: 'Available microCMS Services',
|
|
98
|
+
description: 'List of configured microCMS services. In multi-service mode, use serviceId parameter in tools to specify which service to use.',
|
|
99
|
+
mimeType: 'application/json',
|
|
123
100
|
},
|
|
124
101
|
],
|
|
125
102
|
};
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
103
|
+
});
|
|
104
|
+
// Read resource
|
|
105
|
+
server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
|
|
106
|
+
const { uri } = request.params;
|
|
107
|
+
if (uri === 'microcms://services') {
|
|
108
|
+
const config = getAppConfig();
|
|
109
|
+
let content;
|
|
110
|
+
if (config.mode === 'single') {
|
|
111
|
+
const [apis, serviceInfo] = await Promise.all([
|
|
112
|
+
fetchApisForService(config.serviceDomain),
|
|
113
|
+
getServiceInfo(config.serviceDomain),
|
|
114
|
+
]);
|
|
115
|
+
content = {
|
|
116
|
+
mode: 'single',
|
|
117
|
+
description: 'Single service mode - serviceId parameter is optional',
|
|
118
|
+
services: [
|
|
119
|
+
{
|
|
120
|
+
id: config.serviceDomain,
|
|
121
|
+
name: serviceInfo.name,
|
|
122
|
+
apis,
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
// Fetch APIs and service info for all services in parallel
|
|
129
|
+
const servicesWithApis = await Promise.all(config.services.map(async (s) => {
|
|
130
|
+
const [apis, serviceInfo] = await Promise.all([
|
|
131
|
+
fetchApisForService(s.id),
|
|
132
|
+
getServiceInfo(s.id),
|
|
133
|
+
]);
|
|
134
|
+
return {
|
|
135
|
+
id: s.id,
|
|
136
|
+
name: serviceInfo.name,
|
|
137
|
+
apis,
|
|
138
|
+
};
|
|
139
|
+
}));
|
|
140
|
+
content = {
|
|
141
|
+
mode: 'multi',
|
|
142
|
+
description: 'Multi service mode - serviceId parameter is required for all tools. Use the serviceId that contains the endpoint you need.',
|
|
143
|
+
services: servicesWithApis,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
contents: [
|
|
148
|
+
{
|
|
149
|
+
uri,
|
|
150
|
+
mimeType: 'application/json',
|
|
151
|
+
text: JSON.stringify(content, null, 2),
|
|
152
|
+
},
|
|
153
|
+
],
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
throw new Error(`Unknown resource: ${uri}`);
|
|
157
|
+
});
|
|
158
|
+
// Handle tool calls
|
|
159
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
160
|
+
const { name, arguments: args } = request.params;
|
|
161
|
+
const params = args;
|
|
162
|
+
try {
|
|
163
|
+
const handler = toolHandlers[name];
|
|
164
|
+
if (!handler) {
|
|
165
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
166
|
+
}
|
|
167
|
+
// Extract serviceId from params and pass to handler
|
|
168
|
+
const { serviceId, ...restParams } = params;
|
|
169
|
+
const result = await handler(restParams, serviceId);
|
|
170
|
+
return {
|
|
171
|
+
content: [
|
|
172
|
+
{
|
|
173
|
+
type: 'text',
|
|
174
|
+
text: JSON.stringify(result, null, 2),
|
|
175
|
+
},
|
|
176
|
+
],
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
181
|
+
return {
|
|
182
|
+
content: [
|
|
183
|
+
{
|
|
184
|
+
type: 'text',
|
|
185
|
+
text: `Error: ${errorMessage}`,
|
|
186
|
+
},
|
|
187
|
+
],
|
|
188
|
+
isError: true,
|
|
189
|
+
};
|
|
153
190
|
}
|
|
154
|
-
|
|
155
|
-
|
|
191
|
+
});
|
|
192
|
+
return server;
|
|
156
193
|
}
|
|
194
|
+
// Re-export for use by transport layer
|
|
195
|
+
export { initializeClients };
|
|
157
196
|
//# sourceMappingURL=server.js.map
|