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