@mantine/mcp-server 9.0.0-alpha.4 → 9.0.0-alpha.6

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/cjs/server.cjs CHANGED
@@ -1,271 +1,263 @@
1
- 'use client';
2
- 'use strict';
3
-
4
- var dataClient = require('./data-client.cjs');
5
-
1
+ "use client";
2
+ const require_data_client = require("./data-client.cjs");
3
+ //#region packages/@mantine/mcp-server/src/server.ts
6
4
  const TOOL_DEFINITIONS = [
7
- {
8
- name: "list_items",
9
- description: "List Mantine documentation items. Supports filtering by kind (component|hook), package and text query.",
10
- inputSchema: {
11
- type: "object",
12
- properties: {
13
- kind: { type: "string", enum: ["component", "hook"] },
14
- package: { type: "string" },
15
- query: { type: "string" },
16
- limit: { type: "number" }
17
- },
18
- additionalProperties: false
19
- }
20
- },
21
- {
22
- name: "get_item_doc",
23
- description: "Get the LLM-ready markdown documentation for a Mantine item by name or id.",
24
- inputSchema: {
25
- type: "object",
26
- properties: {
27
- name: { type: "string" },
28
- kind: { type: "string", enum: ["component", "hook"] }
29
- },
30
- required: ["name"],
31
- additionalProperties: false
32
- }
33
- },
34
- {
35
- name: "get_item_props",
36
- description: "Get normalized props metadata for a Mantine item by name or id.",
37
- inputSchema: {
38
- type: "object",
39
- properties: {
40
- name: { type: "string" },
41
- kind: { type: "string", enum: ["component", "hook"] }
42
- },
43
- required: ["name"],
44
- additionalProperties: false
45
- }
46
- },
47
- {
48
- name: "search_docs",
49
- description: "Search Mantine docs by free text query and return ranked matches.",
50
- inputSchema: {
51
- type: "object",
52
- properties: {
53
- kind: { type: "string", enum: ["component", "hook"] },
54
- query: { type: "string" },
55
- limit: { type: "number" }
56
- },
57
- required: ["query"],
58
- additionalProperties: false
59
- }
60
- }
5
+ {
6
+ name: "list_items",
7
+ description: "List Mantine documentation items. Supports filtering by kind (component|hook), package and text query.",
8
+ inputSchema: {
9
+ type: "object",
10
+ properties: {
11
+ kind: {
12
+ type: "string",
13
+ enum: ["component", "hook"]
14
+ },
15
+ package: { type: "string" },
16
+ query: { type: "string" },
17
+ limit: { type: "number" }
18
+ },
19
+ additionalProperties: false
20
+ }
21
+ },
22
+ {
23
+ name: "get_item_doc",
24
+ description: "Get the LLM-ready markdown documentation for a Mantine item by name or id.",
25
+ inputSchema: {
26
+ type: "object",
27
+ properties: {
28
+ name: { type: "string" },
29
+ kind: {
30
+ type: "string",
31
+ enum: ["component", "hook"]
32
+ }
33
+ },
34
+ required: ["name"],
35
+ additionalProperties: false
36
+ }
37
+ },
38
+ {
39
+ name: "get_item_props",
40
+ description: "Get normalized props metadata for a Mantine item by name or id.",
41
+ inputSchema: {
42
+ type: "object",
43
+ properties: {
44
+ name: { type: "string" },
45
+ kind: {
46
+ type: "string",
47
+ enum: ["component", "hook"]
48
+ }
49
+ },
50
+ required: ["name"],
51
+ additionalProperties: false
52
+ }
53
+ },
54
+ {
55
+ name: "search_docs",
56
+ description: "Search Mantine docs by free text query and return ranked matches.",
57
+ inputSchema: {
58
+ type: "object",
59
+ properties: {
60
+ kind: {
61
+ type: "string",
62
+ enum: ["component", "hook"]
63
+ },
64
+ query: { type: "string" },
65
+ limit: { type: "number" }
66
+ },
67
+ required: ["query"],
68
+ additionalProperties: false
69
+ }
70
+ }
61
71
  ];
62
72
  function createJsonRpcError(code, message) {
63
- return { code, message };
73
+ return {
74
+ code,
75
+ message
76
+ };
64
77
  }
65
78
  function toToolResult(content) {
66
- const text = typeof content === "string" ? content : JSON.stringify(content, null, 2);
67
- return {
68
- content: [{ type: "text", text }]
69
- };
79
+ return { content: [{
80
+ type: "text",
81
+ text: typeof content === "string" ? content : JSON.stringify(content, null, 2)
82
+ }] };
70
83
  }
71
84
  function toToolError(message) {
72
- return {
73
- isError: true,
74
- content: [{ type: "text", text: message }]
75
- };
85
+ return {
86
+ isError: true,
87
+ content: [{
88
+ type: "text",
89
+ text: message
90
+ }]
91
+ };
76
92
  }
77
93
  function parseListItemsArgs(args) {
78
- return {
79
- kind: args.kind === "component" || args.kind === "hook" ? args.kind : void 0,
80
- package: typeof args.package === "string" ? args.package : void 0,
81
- query: typeof args.query === "string" ? args.query : void 0,
82
- limit: typeof args.limit === "number" ? args.limit : void 0
83
- };
94
+ return {
95
+ kind: args.kind === "component" || args.kind === "hook" ? args.kind : void 0,
96
+ package: typeof args.package === "string" ? args.package : void 0,
97
+ query: typeof args.query === "string" ? args.query : void 0,
98
+ limit: typeof args.limit === "number" ? args.limit : void 0
99
+ };
84
100
  }
85
101
  function parseGetItemArgs(args) {
86
- if (typeof args.name !== "string" || args.name.length === 0) {
87
- return null;
88
- }
89
- return {
90
- name: args.name,
91
- kind: args.kind === "component" || args.kind === "hook" ? args.kind : void 0
92
- };
102
+ if (typeof args.name !== "string" || args.name.length === 0) return null;
103
+ return {
104
+ name: args.name,
105
+ kind: args.kind === "component" || args.kind === "hook" ? args.kind : void 0
106
+ };
93
107
  }
94
108
  function parseSearchDocsArgs(args) {
95
- if (typeof args.query !== "string" || args.query.length === 0) {
96
- return null;
97
- }
98
- return {
99
- query: args.query,
100
- kind: args.kind === "component" || args.kind === "hook" ? args.kind : void 0,
101
- limit: typeof args.limit === "number" ? args.limit : void 0
102
- };
109
+ if (typeof args.query !== "string" || args.query.length === 0) return null;
110
+ return {
111
+ query: args.query,
112
+ kind: args.kind === "component" || args.kind === "hook" ? args.kind : void 0,
113
+ limit: typeof args.limit === "number" ? args.limit : void 0
114
+ };
103
115
  }
104
116
  function writeMessage(payload) {
105
- const body = JSON.stringify(payload);
106
- const header = `Content-Length: ${Buffer.byteLength(body, "utf8")}\r
107
- \r
108
- `;
109
- process.stdout.write(header + body);
117
+ const body = JSON.stringify(payload);
118
+ const header = `Content-Length: ${Buffer.byteLength(body, "utf8")}\r\n\r\n`;
119
+ process.stdout.write(header + body);
110
120
  }
111
121
  function writeResponse(id, result) {
112
- writeMessage({ jsonrpc: "2.0", id, result });
122
+ writeMessage({
123
+ jsonrpc: "2.0",
124
+ id,
125
+ result
126
+ });
113
127
  }
114
128
  function writeError(id, code, message) {
115
- writeMessage({
116
- jsonrpc: "2.0",
117
- id,
118
- error: createJsonRpcError(code, message)
119
- });
129
+ writeMessage({
130
+ jsonrpc: "2.0",
131
+ id,
132
+ error: createJsonRpcError(code, message)
133
+ });
120
134
  }
121
135
  function readContentLength(rawHeaders) {
122
- const lines = rawHeaders.split("\r\n");
123
- const contentLengthHeader = lines.find(
124
- (line) => line.toLowerCase().startsWith("content-length:")
125
- );
126
- if (!contentLengthHeader) {
127
- return null;
128
- }
129
- const value = Number(contentLengthHeader.split(":")[1]?.trim());
130
- return Number.isFinite(value) ? value : null;
136
+ const contentLengthHeader = rawHeaders.split("\r\n").find((line) => line.toLowerCase().startsWith("content-length:"));
137
+ if (!contentLengthHeader) return null;
138
+ const value = Number(contentLengthHeader.split(":")[1]?.trim());
139
+ return Number.isFinite(value) ? value : null;
131
140
  }
132
141
  function startServer() {
133
- const timeoutMs = Number(process.env.MANTINE_MCP_TIMEOUT_MS || 1e4);
134
- const dataUrl = process.env.MANTINE_MCP_DATA_URL || "https://mantine.dev/mcp";
135
- const client = new dataClient.MantineMcpDataClient(dataUrl, timeoutMs);
136
- let buffer = Buffer.alloc(0);
137
- process.stdin.on("data", (chunk) => {
138
- buffer = Buffer.concat([buffer, chunk]);
139
- while (true) {
140
- const separatorIndex = buffer.indexOf("\r\n\r\n");
141
- if (separatorIndex === -1) {
142
- return;
143
- }
144
- const headersBuffer = buffer.subarray(0, separatorIndex);
145
- const headers = headersBuffer.toString("utf8");
146
- const contentLength = readContentLength(headers);
147
- if (contentLength == null) {
148
- writeError(null, -32600, "Invalid request: missing Content-Length header");
149
- buffer = Buffer.alloc(0);
150
- return;
151
- }
152
- const bodyStart = separatorIndex + 4;
153
- const bodyEnd = bodyStart + contentLength;
154
- if (buffer.length < bodyEnd) {
155
- return;
156
- }
157
- const bodyBuffer = buffer.subarray(bodyStart, bodyEnd);
158
- buffer = buffer.subarray(bodyEnd);
159
- let request;
160
- try {
161
- request = JSON.parse(bodyBuffer.toString("utf8"));
162
- } catch {
163
- writeError(null, -32700, "Parse error");
164
- continue;
165
- }
166
- void handleRequest(client, request);
167
- }
168
- });
169
- process.stdin.resume();
142
+ const timeoutMs = Number(process.env.MANTINE_MCP_TIMEOUT_MS || 1e4);
143
+ const client = new require_data_client.MantineMcpDataClient(process.env.MANTINE_MCP_DATA_URL || "https://mantine.dev/mcp", timeoutMs);
144
+ let buffer = Buffer.alloc(0);
145
+ process.stdin.on("data", (chunk) => {
146
+ buffer = Buffer.concat([buffer, chunk]);
147
+ while (true) {
148
+ const separatorIndex = buffer.indexOf("\r\n\r\n");
149
+ if (separatorIndex === -1) return;
150
+ const contentLength = readContentLength(buffer.subarray(0, separatorIndex).toString("utf8"));
151
+ if (contentLength == null) {
152
+ writeError(null, -32600, "Invalid request: missing Content-Length header");
153
+ buffer = Buffer.alloc(0);
154
+ return;
155
+ }
156
+ const bodyStart = separatorIndex + 4;
157
+ const bodyEnd = bodyStart + contentLength;
158
+ if (buffer.length < bodyEnd) return;
159
+ const bodyBuffer = buffer.subarray(bodyStart, bodyEnd);
160
+ buffer = buffer.subarray(bodyEnd);
161
+ let request;
162
+ try {
163
+ request = JSON.parse(bodyBuffer.toString("utf8"));
164
+ } catch {
165
+ writeError(null, -32700, "Parse error");
166
+ continue;
167
+ }
168
+ handleRequest(client, request);
169
+ }
170
+ });
171
+ process.stdin.resume();
170
172
  }
171
173
  async function handleRequest(client, request) {
172
- const id = request.id ?? null;
173
- if (!request || request.jsonrpc !== "2.0" || typeof request.method !== "string") {
174
- writeError(id, -32600, "Invalid request");
175
- return;
176
- }
177
- try {
178
- switch (request.method) {
179
- case "initialize": {
180
- writeResponse(id, {
181
- protocolVersion: "2024-11-05",
182
- capabilities: {
183
- tools: {}
184
- },
185
- serverInfo: {
186
- name: "@mantine/mcp-server",
187
- version: "9.0.0-alpha.1"
188
- }
189
- });
190
- return;
191
- }
192
- case "notifications/initialized": {
193
- return;
194
- }
195
- case "tools/list": {
196
- writeResponse(id, { tools: TOOL_DEFINITIONS });
197
- return;
198
- }
199
- case "tools/call": {
200
- const params = request.params && typeof request.params === "object" ? request.params : {};
201
- const name = typeof params.name === "string" ? params.name : "";
202
- const args = params.arguments && typeof params.arguments === "object" ? params.arguments : {};
203
- if (!name) {
204
- writeResponse(id, toToolError("Tool name is required"));
205
- return;
206
- }
207
- if (name === "list_items") {
208
- const result = await client.listItems(parseListItemsArgs(args));
209
- writeResponse(id, toToolResult(result));
210
- return;
211
- }
212
- if (name === "get_item_doc") {
213
- const parsed = parseGetItemArgs(args);
214
- if (!parsed) {
215
- writeResponse(id, toToolError('Argument "name" is required'));
216
- return;
217
- }
218
- const result = await client.getItemDoc(parsed);
219
- if (!result) {
220
- writeResponse(id, toToolError(`Item not found: ${parsed.name}`));
221
- return;
222
- }
223
- writeResponse(id, toToolResult(result));
224
- return;
225
- }
226
- if (name === "get_item_props") {
227
- const parsed = parseGetItemArgs(args);
228
- if (!parsed) {
229
- writeResponse(id, toToolError('Argument "name" is required'));
230
- return;
231
- }
232
- const result = await client.getItemProps(parsed);
233
- if (!result) {
234
- writeResponse(id, toToolError(`Item not found: ${parsed.name}`));
235
- return;
236
- }
237
- writeResponse(id, toToolResult(result));
238
- return;
239
- }
240
- if (name === "search_docs") {
241
- const parsed = parseSearchDocsArgs(args);
242
- if (!parsed) {
243
- writeResponse(id, toToolError('Argument "query" is required'));
244
- return;
245
- }
246
- const result = await client.searchDocs(parsed);
247
- writeResponse(id, toToolResult(result));
248
- return;
249
- }
250
- writeResponse(id, toToolError(`Unknown tool: ${name}`));
251
- return;
252
- }
253
- default: {
254
- if (id === null) {
255
- return;
256
- }
257
- writeError(id, -32601, `Method not found: ${request.method}`);
258
- }
259
- }
260
- } catch (error) {
261
- const message = error instanceof Error ? error.message : "Unexpected error";
262
- if (request.method === "tools/call") {
263
- writeResponse(id, toToolError(message));
264
- return;
265
- }
266
- writeError(id, -32e3, message);
267
- }
174
+ const id = request.id ?? null;
175
+ if (!request || request.jsonrpc !== "2.0" || typeof request.method !== "string") {
176
+ writeError(id, -32600, "Invalid request");
177
+ return;
178
+ }
179
+ try {
180
+ switch (request.method) {
181
+ case "initialize":
182
+ writeResponse(id, {
183
+ protocolVersion: "2024-11-05",
184
+ capabilities: { tools: {} },
185
+ serverInfo: {
186
+ name: "@mantine/mcp-server",
187
+ version: "9.0.0-alpha.1"
188
+ }
189
+ });
190
+ return;
191
+ case "notifications/initialized": return;
192
+ case "tools/list":
193
+ writeResponse(id, { tools: TOOL_DEFINITIONS });
194
+ return;
195
+ case "tools/call": {
196
+ const params = request.params && typeof request.params === "object" ? request.params : {};
197
+ const name = typeof params.name === "string" ? params.name : "";
198
+ const args = params.arguments && typeof params.arguments === "object" ? params.arguments : {};
199
+ if (!name) {
200
+ writeResponse(id, toToolError("Tool name is required"));
201
+ return;
202
+ }
203
+ if (name === "list_items") {
204
+ writeResponse(id, toToolResult(await client.listItems(parseListItemsArgs(args))));
205
+ return;
206
+ }
207
+ if (name === "get_item_doc") {
208
+ const parsed = parseGetItemArgs(args);
209
+ if (!parsed) {
210
+ writeResponse(id, toToolError("Argument \"name\" is required"));
211
+ return;
212
+ }
213
+ const result = await client.getItemDoc(parsed);
214
+ if (!result) {
215
+ writeResponse(id, toToolError(`Item not found: ${parsed.name}`));
216
+ return;
217
+ }
218
+ writeResponse(id, toToolResult(result));
219
+ return;
220
+ }
221
+ if (name === "get_item_props") {
222
+ const parsed = parseGetItemArgs(args);
223
+ if (!parsed) {
224
+ writeResponse(id, toToolError("Argument \"name\" is required"));
225
+ return;
226
+ }
227
+ const result = await client.getItemProps(parsed);
228
+ if (!result) {
229
+ writeResponse(id, toToolError(`Item not found: ${parsed.name}`));
230
+ return;
231
+ }
232
+ writeResponse(id, toToolResult(result));
233
+ return;
234
+ }
235
+ if (name === "search_docs") {
236
+ const parsed = parseSearchDocsArgs(args);
237
+ if (!parsed) {
238
+ writeResponse(id, toToolError("Argument \"query\" is required"));
239
+ return;
240
+ }
241
+ writeResponse(id, toToolResult(await client.searchDocs(parsed)));
242
+ return;
243
+ }
244
+ writeResponse(id, toToolError(`Unknown tool: ${name}`));
245
+ return;
246
+ }
247
+ default:
248
+ if (id === null) return;
249
+ writeError(id, -32601, `Method not found: ${request.method}`);
250
+ }
251
+ } catch (error) {
252
+ const message = error instanceof Error ? error.message : "Unexpected error";
253
+ if (request.method === "tools/call") {
254
+ writeResponse(id, toToolError(message));
255
+ return;
256
+ }
257
+ writeError(id, -32e3, message);
258
+ }
268
259
  }
269
-
260
+ //#endregion
270
261
  exports.startServer = startServer;
271
- //# sourceMappingURL=server.cjs.map
262
+
263
+ //# sourceMappingURL=server.cjs.map