@skemacms/mcp-server 1.1.0 → 1.2.1

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 CHANGED
@@ -52,7 +52,6 @@ Ajoutez dans vos paramètres MCP :
52
52
  | Variable | Description | Requis |
53
53
  | ---------------- | ------------------------------------------------------- | ------ |
54
54
  | `SKEMA_API_KEY` | Clé API Skema (format `pk_live_xxx`) | Oui |
55
- | `SKEMA_BASE_URL` | URL de l'API Skema (défaut: `https://api.skemacms.com`) | Non |
56
55
 
57
56
  ## Outils disponibles (11 outils)
58
57
 
@@ -1,31 +1,18 @@
1
1
  /**
2
- * Client HTTP pour communiquer avec l'API publique Skema
2
+ * Client HTTP pour communiquer avec l'API MCP Skema (JSON-RPC 2.0)
3
3
  */
4
- export interface SkemaResponse<T = unknown> {
5
- data: T;
6
- count?: number;
7
- page?: number;
8
- totalPages?: number;
9
- message: string;
10
- statusCode: number;
11
- }
12
- export interface FetchOptions {
13
- method?: "GET" | "POST" | "PUT" | "DELETE";
14
- body?: unknown;
15
- params?: Record<string, string | number | boolean | undefined>;
16
- }
17
4
  /**
18
- * Effectue une requete vers l'API Skema
5
+ * Appelle un outil MCP via JSON-RPC
19
6
  */
20
- export declare const skemaFetch: <T = unknown>(path: string, options?: FetchOptions) => Promise<SkemaResponse<T>>;
7
+ export declare const mcpCall: <T = unknown>(toolName: string, args?: Record<string, unknown>) => Promise<T>;
21
8
  /**
22
9
  * Recupere la liste des collections
23
10
  */
24
- export declare const getCollections: () => Promise<SkemaResponse<unknown>>;
11
+ export declare const getCollections: () => Promise<unknown>;
25
12
  /**
26
13
  * Recupere le schema d'une collection
27
14
  */
28
- export declare const getCollection: (name: string) => Promise<SkemaResponse<unknown>>;
15
+ export declare const getCollection: (collection: string) => Promise<unknown>;
29
16
  /**
30
17
  * Liste les items d'une collection
31
18
  */
@@ -35,25 +22,25 @@ export declare const getItems: (collection: string, options?: {
35
22
  sort?: string;
36
23
  populate?: string;
37
24
  filters?: Record<string, unknown>;
38
- }) => Promise<SkemaResponse<unknown>>;
25
+ }) => Promise<unknown>;
39
26
  /**
40
27
  * Recupere un item par son ID
41
28
  */
42
29
  export declare const getItem: (collection: string, id: string, options?: {
43
30
  populate?: string;
44
- }) => Promise<SkemaResponse<unknown>>;
31
+ }) => Promise<unknown>;
45
32
  /**
46
33
  * Cree un nouvel item
47
34
  */
48
- export declare const createItem: (collection: string, data: Record<string, unknown>) => Promise<SkemaResponse<unknown>>;
35
+ export declare const createItem: (collection: string, data: Record<string, unknown>) => Promise<unknown>;
49
36
  /**
50
37
  * Met a jour un item
51
38
  */
52
- export declare const updateItem: (collection: string, id: string, data: Record<string, unknown>) => Promise<SkemaResponse<unknown>>;
39
+ export declare const updateItem: (collection: string, id: string, data: Record<string, unknown>) => Promise<unknown>;
53
40
  /**
54
41
  * Supprime un item
55
42
  */
56
- export declare const deleteItem: (collection: string, id: string) => Promise<SkemaResponse<unknown>>;
43
+ export declare const deleteItem: (collection: string, id: string) => Promise<unknown>;
57
44
  /**
58
45
  * Recherche dans une collection
59
46
  */
@@ -61,18 +48,18 @@ export declare const searchItems: (collection: string, query: string, options?:
61
48
  fields?: string;
62
49
  page?: number;
63
50
  perPage?: number;
64
- }) => Promise<SkemaResponse<unknown>>;
51
+ }) => Promise<unknown>;
65
52
  /**
66
53
  * Compte les items d'une collection
67
54
  */
68
- export declare const countItems: (collection: string, filters?: Record<string, unknown>) => Promise<SkemaResponse<unknown>>;
55
+ export declare const countItems: (collection: string, filters?: Record<string, unknown>) => Promise<unknown>;
69
56
  /**
70
57
  * Cree plusieurs items en une seule requete
71
58
  */
72
- export declare const batchCreate: (collection: string, items: Record<string, unknown>[]) => Promise<SkemaResponse<unknown>>;
59
+ export declare const batchCreate: (collection: string, items: Record<string, unknown>[]) => Promise<unknown>;
73
60
  /**
74
61
  * Met a jour plusieurs items en une seule requete
75
62
  */
76
63
  export declare const batchUpdate: (collection: string, items: Array<{
77
64
  id: string;
78
- } & Record<string, unknown>>) => Promise<SkemaResponse<unknown>>;
65
+ } & Record<string, unknown>>) => Promise<unknown>;
@@ -1,33 +1,29 @@
1
1
  /**
2
- * Client HTTP pour communiquer avec l'API publique Skema
2
+ * Client HTTP pour communiquer avec l'API MCP Skema (JSON-RPC 2.0)
3
3
  */
4
4
  const API_KEY = process.env.SKEMA_API_KEY || "";
5
5
  const BASE_URL = process.env.SKEMA_BASE_URL || "https://api.skemacms.com";
6
+ let requestId = 0;
6
7
  /**
7
- * Effectue une requete vers l'API Skema
8
+ * Appelle un outil MCP via JSON-RPC
8
9
  */
9
- export const skemaFetch = async (path, options = {}) => {
10
- const { method = "GET", body, params } = options;
11
- let url = `${BASE_URL}${path}`;
12
- if (params) {
13
- const searchParams = new URLSearchParams();
14
- Object.entries(params).forEach(([key, value]) => {
15
- if (value !== undefined) {
16
- searchParams.append(key, String(value));
17
- }
18
- });
19
- const queryString = searchParams.toString();
20
- if (queryString) {
21
- url += `?${queryString}`;
22
- }
23
- }
24
- const response = await fetch(url, {
25
- method,
10
+ export const mcpCall = async (toolName, args = {}) => {
11
+ requestId++;
12
+ const response = await fetch(`${BASE_URL}/mcp`, {
13
+ method: "POST",
26
14
  headers: {
27
- "X-API-Key": API_KEY,
15
+ Authorization: `Bearer ${API_KEY}`,
28
16
  "Content-Type": "application/json",
29
17
  },
30
- ...(body ? { body: JSON.stringify(body) } : {}),
18
+ body: JSON.stringify({
19
+ jsonrpc: "2.0",
20
+ id: requestId,
21
+ method: "tools/call",
22
+ params: {
23
+ name: toolName,
24
+ arguments: args,
25
+ },
26
+ }),
31
27
  });
32
28
  if (!response.ok) {
33
29
  const error = await response
@@ -35,82 +31,73 @@ export const skemaFetch = async (path, options = {}) => {
35
31
  .catch(() => ({ message: "Erreur inconnue" }));
36
32
  throw new Error(error.message || `Erreur HTTP ${response.status}`);
37
33
  }
38
- return response.json();
34
+ const jsonRpc = await response.json();
35
+ if (jsonRpc.error) {
36
+ throw new Error(jsonRpc.error.message);
37
+ }
38
+ if (!jsonRpc.result?.content?.[0]?.text) {
39
+ throw new Error("Reponse MCP invalide");
40
+ }
41
+ return JSON.parse(jsonRpc.result.content[0].text);
39
42
  };
40
43
  /**
41
44
  * Recupere la liste des collections
42
45
  */
43
- export const getCollections = () => skemaFetch("/public/collections");
46
+ export const getCollections = () => mcpCall("get_collections");
44
47
  /**
45
48
  * Recupere le schema d'une collection
46
49
  */
47
- export const getCollection = (name) => skemaFetch(`/public/collections/${name}`);
50
+ export const getCollection = (collection) => mcpCall("get_collection", { collection });
48
51
  /**
49
52
  * Liste les items d'une collection
50
53
  */
51
- export const getItems = (collection, options) => skemaFetch(`/public/${collection}`, {
52
- params: {
53
- page: options?.page,
54
- perPage: options?.perPage,
55
- sort: options?.sort,
56
- populate: options?.populate,
57
- ...(options?.filters && { filters: JSON.stringify(options.filters) }),
58
- },
54
+ export const getItems = (collection, options) => mcpCall("get_collection_items", {
55
+ collection,
56
+ page: options?.page,
57
+ perPage: options?.perPage,
58
+ sort: options?.sort,
59
+ populate: options?.populate,
60
+ filters: options?.filters,
59
61
  });
60
62
  /**
61
63
  * Recupere un item par son ID
62
64
  */
63
- export const getItem = (collection, id, options) => skemaFetch(`/public/${collection}/${id}`, {
64
- params: { populate: options?.populate },
65
+ export const getItem = (collection, id, options) => mcpCall("get_collection_item", {
66
+ collection,
67
+ id,
68
+ populate: options?.populate,
65
69
  });
66
70
  /**
67
71
  * Cree un nouvel item
68
72
  */
69
- export const createItem = (collection, data) => skemaFetch(`/public/${collection}`, {
70
- method: "POST",
71
- body: data,
72
- });
73
+ export const createItem = (collection, data) => mcpCall("create_collection_item", { collection, data });
73
74
  /**
74
75
  * Met a jour un item
75
76
  */
76
- export const updateItem = (collection, id, data) => skemaFetch(`/public/${collection}/${id}`, {
77
- method: "PUT",
78
- body: data,
79
- });
77
+ export const updateItem = (collection, id, data) => mcpCall("update_collection_item", { collection, id, data });
80
78
  /**
81
79
  * Supprime un item
82
80
  */
83
- export const deleteItem = (collection, id) => skemaFetch(`/public/${collection}/${id}`, {
84
- method: "DELETE",
85
- });
81
+ export const deleteItem = (collection, id) => mcpCall("delete_collection_item", { collection, id });
86
82
  /**
87
83
  * Recherche dans une collection
88
84
  */
89
- export const searchItems = (collection, query, options) => skemaFetch(`/public/${collection}/search`, {
90
- params: {
91
- q: query,
92
- fields: options?.fields,
93
- page: options?.page,
94
- perPage: options?.perPage,
95
- },
85
+ export const searchItems = (collection, query, options) => mcpCall("search_collection_items", {
86
+ collection,
87
+ query,
88
+ fields: options?.fields,
89
+ page: options?.page,
90
+ perPage: options?.perPage,
96
91
  });
97
92
  /**
98
93
  * Compte les items d'une collection
99
94
  */
100
- export const countItems = (collection, filters) => skemaFetch(`/public/${collection}/count`, {
101
- params: filters ? { filters: JSON.stringify(filters) } : undefined,
102
- });
95
+ export const countItems = (collection, filters) => mcpCall("count_collection_items", { collection, filters });
103
96
  /**
104
97
  * Cree plusieurs items en une seule requete
105
98
  */
106
- export const batchCreate = (collection, items) => skemaFetch(`/public/${collection}/batch`, {
107
- method: "POST",
108
- body: items,
109
- });
99
+ export const batchCreate = (collection, items) => mcpCall("batch_create_items", { collection, items });
110
100
  /**
111
101
  * Met a jour plusieurs items en une seule requete
112
102
  */
113
- export const batchUpdate = (collection, items) => skemaFetch(`/public/${collection}/batch`, {
114
- method: "PUT",
115
- body: items,
116
- });
103
+ export const batchUpdate = (collection, items) => mcpCall("batch_update_items", { collection, items });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skemacms/mcp-server",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "Serveur MCP officiel pour Skema CMS - Connectez Claude Desktop a vos donnees",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",