@anri1214/dynamic-forms-mui-mcp 0.1.5

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.
Files changed (45) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +214 -0
  3. package/dist/index.d.ts +14 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +394 -0
  6. package/dist/prompts/generateBackendEndpoint.d.ts +5 -0
  7. package/dist/prompts/generateBackendEndpoint.d.ts.map +1 -0
  8. package/dist/prompts/generateBackendEndpoint.js +33 -0
  9. package/dist/prompts/generateFormConfig.d.ts +5 -0
  10. package/dist/prompts/generateFormConfig.d.ts.map +1 -0
  11. package/dist/prompts/generateFormConfig.js +94 -0
  12. package/dist/resources/examples.d.ts +9 -0
  13. package/dist/resources/examples.d.ts.map +1 -0
  14. package/dist/resources/examples.js +16 -0
  15. package/dist/resources/fieldDocs.d.ts +5 -0
  16. package/dist/resources/fieldDocs.d.ts.map +1 -0
  17. package/dist/resources/fieldDocs.js +39 -0
  18. package/dist/resources/jsonSchema.d.ts +5 -0
  19. package/dist/resources/jsonSchema.d.ts.map +1 -0
  20. package/dist/resources/jsonSchema.js +8 -0
  21. package/dist/schema/0.1/examples/crud.json +128 -0
  22. package/dist/schema/0.1/examples/filters.json +82 -0
  23. package/dist/schema/0.1/examples/registration.json +119 -0
  24. package/dist/schema/0.1/fieldTypes.json +213 -0
  25. package/dist/schema/0.1/formSchema.json +806 -0
  26. package/dist/schema/versions.json +6 -0
  27. package/dist/schemaLoader.d.ts +37 -0
  28. package/dist/schemaLoader.d.ts.map +1 -0
  29. package/dist/schemaLoader.js +89 -0
  30. package/dist/tools/generateSchema.d.ts +30 -0
  31. package/dist/tools/generateSchema.d.ts.map +1 -0
  32. package/dist/tools/generateSchema.js +58 -0
  33. package/dist/tools/getFieldConfig.d.ts +18 -0
  34. package/dist/tools/getFieldConfig.d.ts.map +1 -0
  35. package/dist/tools/getFieldConfig.js +25 -0
  36. package/dist/tools/listFieldTypes.d.ts +13 -0
  37. package/dist/tools/listFieldTypes.d.ts.map +1 -0
  38. package/dist/tools/listFieldTypes.js +14 -0
  39. package/dist/tools/validateSchema.d.ts +10 -0
  40. package/dist/tools/validateSchema.d.ts.map +1 -0
  41. package/dist/tools/validateSchema.js +32 -0
  42. package/dist/types.d.ts +19 -0
  43. package/dist/types.d.ts.map +1 -0
  44. package/dist/types.js +1 -0
  45. package/package.json +49 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 AI Hub
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md ADDED
@@ -0,0 +1,214 @@
1
+ # @ai-hub/dynamic-forms-mui-mcp
2
+
3
+ MCP (Model Context Protocol) server for **@ai-hub/dynamic-forms-mui** — exposes the `FormSchema` structure as tools, resources, and prompts for AI assistants.
4
+
5
+ ## Why?
6
+
7
+ Your backend can be written in **any language** (Python, Go, C#, Java, etc.) but it needs to return a JSON that matches the `FormSchema` type from `@ai-hub/dynamic-forms-mui`. This MCP server gives AI assistants full knowledge of the schema structure, so they can:
8
+
9
+ - **Validate** form configuration JSON
10
+ - **Generate** correct FormSchema JSON from natural language
11
+ - **Help backend developers** produce correct API endpoints in any language
12
+ - **Serve version-specific documentation** — different projects can use different library versions
13
+
14
+ ## Versioning
15
+
16
+ The MCP server supports **multiple versions** of `@ai-hub/dynamic-forms-mui` simultaneously. Versions are tracked as `major.minor` (e.g. `0.1`, `0.2`, `1.0`) — patch versions are ignored since they don't change the schema API.
17
+
18
+ Every tool (except `list_versions`) requires a mandatory `version` parameter. This ensures the AI always gets documentation matching the project's installed library version.
19
+
20
+ ```
21
+ AI reads package.json → version "0.1.3" → calls tool with version: "0.1" → gets correct docs
22
+ ```
23
+
24
+ ## Quick Start
25
+
26
+ ### 1. Install
27
+
28
+ ```bash
29
+ npm install @ai-hub/dynamic-forms-mui-mcp
30
+ # or run directly
31
+ npx @ai-hub/dynamic-forms-mui-mcp
32
+ ```
33
+
34
+ ### 2. Configure in your IDE
35
+
36
+ **Cursor** (`.cursor/mcp.json`):
37
+
38
+ ```json
39
+ {
40
+ "mcpServers": {
41
+ "dynamic-forms": {
42
+ "command": "npx",
43
+ "args": ["@ai-hub/dynamic-forms-mui-mcp"]
44
+ }
45
+ }
46
+ }
47
+ ```
48
+
49
+ **Claude Code:**
50
+
51
+ ```bash
52
+ claude mcp add dynamic-forms npx @ai-hub/dynamic-forms-mui-mcp
53
+ ```
54
+
55
+ **VS Code:**
56
+
57
+ ```bash
58
+ code --add-mcp '{"name":"dynamic-forms","type":"stdio","command":"npx","args":["@ai-hub/dynamic-forms-mui-mcp"]}'
59
+ ```
60
+
61
+ ### 3. Use it
62
+
63
+ Ask your AI assistant:
64
+
65
+ > "Generate a FormSchema for a user registration form with email, password, confirm password, first name, last name"
66
+
67
+ The AI will use the MCP server to understand the exact structure and generate valid JSON.
68
+
69
+ ## Tools
70
+
71
+ | Tool | Description |
72
+ |------|-------------|
73
+ | `list_versions` | List available library versions this MCP has documentation for. |
74
+ | `validate_form_schema` | Validate a JSON against the FormSchema spec. Returns errors if invalid. |
75
+ | `list_field_types` | List all 14 supported field types with descriptions and applicable validations. |
76
+ | `get_field_config` | Get detailed config for a specific field type (props, validations, example). |
77
+ | `generate_form_schema` | Generate a FormSchema from a list of field definitions. Auto-validates output. |
78
+
79
+ > All tools except `list_versions` require a `version` parameter (e.g. `"0.1"`).
80
+
81
+ ### Example: list_versions
82
+
83
+ Output:
84
+ ```json
85
+ {
86
+ "latest": "0.1",
87
+ "available": ["0.1"]
88
+ }
89
+ ```
90
+
91
+ ### Example: validate_form_schema
92
+
93
+ Input:
94
+ ```json
95
+ {
96
+ "version": "0.1",
97
+ "schema": "{\"sections\":[{\"id\":\"main\",\"title\":\"Form\",\"fields\":[\"email\"]}],\"fields\":{\"email\":{\"type\":\"email\",\"label\":\"Email\"}}}"
98
+ }
99
+ ```
100
+
101
+ Output:
102
+ ```json
103
+ {
104
+ "valid": true,
105
+ "errors": []
106
+ }
107
+ ```
108
+
109
+ ### Example: get_field_config
110
+
111
+ Input:
112
+ ```json
113
+ {
114
+ "version": "0.1",
115
+ "fieldType": "password"
116
+ }
117
+ ```
118
+
119
+ Output:
120
+ ```json
121
+ {
122
+ "type": "password",
123
+ "description": "Password input with masked characters",
124
+ "config": "TextFieldConfig",
125
+ "specificProps": ["autoComplete"],
126
+ "applicableValidations": ["required", "minLength", "maxLength", "hasUppercase", "hasLowercase", "hasNumber", "hasSpecialChar", "matchField"],
127
+ "example": {
128
+ "type": "password",
129
+ "label": "Password",
130
+ "validation": {
131
+ "required": true,
132
+ "minLength": 8,
133
+ "hasUppercase": true,
134
+ "hasLowercase": true,
135
+ "hasSpecialChar": true
136
+ }
137
+ }
138
+ }
139
+ ```
140
+
141
+ ## Resources
142
+
143
+ | URI | Description |
144
+ |-----|-------------|
145
+ | `schema://dynamic-forms/{version}/form-schema` | Complete JSON Schema for FormSchema |
146
+ | `schema://dynamic-forms/{version}/field-types` | Markdown documentation for all field types |
147
+ | `schema://dynamic-forms/{version}/examples/{name}` | Example schemas: `registration`, `crud`, `filters` |
148
+
149
+ ## Prompts
150
+
151
+ | Prompt | Description |
152
+ |--------|-------------|
153
+ | `generate-backend-endpoint` | Generate backend API endpoint code in any language/framework |
154
+ | `generate-form-config` | Generate a FormSchema JSON from a natural language description |
155
+
156
+ ### Example: generate-backend-endpoint
157
+
158
+ ```
159
+ Language: Python
160
+ Framework: FastAPI
161
+ Description: User registration with email, password, name, and terms acceptance
162
+ ```
163
+
164
+ The AI will generate a complete FastAPI endpoint returning a valid FormSchema JSON.
165
+
166
+ ## Supported Field Types
167
+
168
+ | Type | Description |
169
+ |------|-------------|
170
+ | `text` | Single-line text input |
171
+ | `password` | Password input with masking |
172
+ | `email` | Email input with validation |
173
+ | `number` | Numeric input with min/max/step |
174
+ | `textarea` | Multi-line text input |
175
+ | `select` | Single-value dropdown |
176
+ | `multiselect` | Multi-value dropdown (chips) |
177
+ | `autocomplete` | Single-value autocomplete with async search |
178
+ | `checkbox` | Boolean checkbox |
179
+ | `radio` | Radio button group |
180
+ | `switch` | Toggle switch |
181
+ | `date` | Date picker |
182
+ | `dateRange` | Date range picker |
183
+ | `file` | File upload |
184
+
185
+ ## Development
186
+
187
+ ```bash
188
+ # Install dependencies
189
+ npm install
190
+
191
+ # Generate JSON Schema from types (writes to src/schema/{version}/)
192
+ npm run build:schema
193
+
194
+ # Build TypeScript + copy schemas to dist
195
+ npm run build
196
+
197
+ # Run in development mode
198
+ npm run dev
199
+ ```
200
+
201
+ ### Adding a new schema version
202
+
203
+ When `@ai-hub/dynamic-forms-mui` gets a new minor version:
204
+
205
+ 1. Update the library's `package.json` version (e.g. `0.1.x` → `0.2.0`)
206
+ 2. Run `npm run build:schema` — automatically creates `src/schema/0.2/` and updates `versions.json`
207
+ 3. Adjust `fieldTypes.json` and `examples/` in the new version folder if the schema changed
208
+ 4. Run `npm run build`
209
+
210
+ Old version schemas are preserved — the MCP can serve docs for all versions simultaneously.
211
+
212
+ ## License
213
+
214
+ MIT
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * @ai-hub/dynamic-forms-mui-mcp
4
+ *
5
+ * MCP server that exposes the FormSchema structure of @ai-hub/dynamic-forms-mui
6
+ * as tools, resources, and prompts for AI assistants.
7
+ *
8
+ * All tools (except list_versions) require a `version` parameter to ensure
9
+ * the AI gets documentation matching the project's installed library version.
10
+ *
11
+ * Transport: stdio (for Cursor, Claude Code, VS Code, etc.)
12
+ */
13
+ export {};
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;GAUG"}
package/dist/index.js ADDED
@@ -0,0 +1,394 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * @ai-hub/dynamic-forms-mui-mcp
4
+ *
5
+ * MCP server that exposes the FormSchema structure of @ai-hub/dynamic-forms-mui
6
+ * as tools, resources, and prompts for AI assistants.
7
+ *
8
+ * All tools (except list_versions) require a `version` parameter to ensure
9
+ * the AI gets documentation matching the project's installed library version.
10
+ *
11
+ * Transport: stdio (for Cursor, Claude Code, VS Code, etc.)
12
+ */
13
+ import { createRequire } from 'node:module';
14
+ import { McpServer, ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js';
15
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
16
+ import { z } from 'zod';
17
+ // Schema loader
18
+ import { getAvailableVersions, resolveVersion } from './schemaLoader.js';
19
+ // Tools
20
+ import { validateFormSchema } from './tools/validateSchema.js';
21
+ import { listFieldTypes } from './tools/listFieldTypes.js';
22
+ import { getFieldConfig } from './tools/getFieldConfig.js';
23
+ import { generateFormSchema } from './tools/generateSchema.js';
24
+ // Resources
25
+ import { getFormSchemaResource } from './resources/jsonSchema.js';
26
+ import { getFieldDocsResource } from './resources/fieldDocs.js';
27
+ import { listExamples, getExample } from './resources/examples.js';
28
+ // Prompts
29
+ import { generateBackendEndpointPrompt } from './prompts/generateBackendEndpoint.js';
30
+ import { generateFormConfigPrompt } from './prompts/generateFormConfig.js';
31
+ // ── Read MCP server version from own package.json ──────────
32
+ const require = createRequire(import.meta.url);
33
+ const mcpPackageJson = require('../package.json');
34
+ // ── Create MCP Server ──────────────────────────────────────
35
+ const server = new McpServer({
36
+ name: '@ai-hub/dynamic-forms-mui-mcp',
37
+ version: mcpPackageJson.version,
38
+ });
39
+ // ── Shared version param description ───────────────────────
40
+ const versionParamDesc = 'The @ai-hub/dynamic-forms-mui library version as major.minor (e.g. "0.1"). Full semver like "0.1.0" is also accepted and normalized to "0.1". Use list_versions to see available versions.';
41
+ // ════════════════════════════════════════════════════════════
42
+ // TOOLS
43
+ // ════════════════════════════════════════════════════════════
44
+ // 1. list_versions (the only tool WITHOUT a version parameter)
45
+ server.tool('list_versions', 'List available @ai-hub/dynamic-forms-mui library versions that this MCP server has documentation for.', {}, async () => {
46
+ const versions = getAvailableVersions();
47
+ return {
48
+ content: [
49
+ {
50
+ type: 'text',
51
+ text: JSON.stringify(versions, null, 2),
52
+ },
53
+ ],
54
+ };
55
+ });
56
+ // 2. validate_form_schema
57
+ server.tool('validate_form_schema', 'Validate a JSON object against the dynamic-forms-mui FormSchema specification. Returns whether the schema is valid and any validation errors.', {
58
+ version: z.string().describe(versionParamDesc),
59
+ schema: z.string().describe('A JSON string representing the FormSchema to validate. Must have "sections" and "fields" top-level properties.'),
60
+ }, async ({ version, schema: schemaStr }) => {
61
+ try {
62
+ resolveVersion(version);
63
+ }
64
+ catch (err) {
65
+ return {
66
+ content: [{ type: 'text', text: err.message }],
67
+ };
68
+ }
69
+ let parsed;
70
+ try {
71
+ parsed = JSON.parse(schemaStr);
72
+ }
73
+ catch {
74
+ return {
75
+ content: [
76
+ {
77
+ type: 'text',
78
+ text: JSON.stringify({
79
+ valid: false,
80
+ errors: ['Invalid JSON: failed to parse the input string'],
81
+ }),
82
+ },
83
+ ],
84
+ };
85
+ }
86
+ const result = validateFormSchema(version, parsed);
87
+ return {
88
+ content: [
89
+ {
90
+ type: 'text',
91
+ text: JSON.stringify(result, null, 2),
92
+ },
93
+ ],
94
+ };
95
+ });
96
+ // 3. list_field_types
97
+ server.tool('list_field_types', 'List all supported field types in dynamic-forms-mui with their descriptions, config interfaces, specific props, and applicable validations.', {
98
+ version: z.string().describe(versionParamDesc),
99
+ }, async ({ version }) => {
100
+ try {
101
+ resolveVersion(version);
102
+ }
103
+ catch (err) {
104
+ return {
105
+ content: [{ type: 'text', text: err.message }],
106
+ };
107
+ }
108
+ const types = listFieldTypes(version);
109
+ return {
110
+ content: [
111
+ {
112
+ type: 'text',
113
+ text: JSON.stringify(types, null, 2),
114
+ },
115
+ ],
116
+ };
117
+ });
118
+ // 4. get_field_config
119
+ server.tool('get_field_config', 'Get detailed configuration information for a specific field type, including all props, applicable validations, and a working example.', {
120
+ version: z.string().describe(versionParamDesc),
121
+ fieldType: z
122
+ .string()
123
+ .describe('The field type to get details for. One of: text, password, email, number, textarea, select, multiselect, checkbox, radio, switch, date, dateRange, file'),
124
+ }, async ({ version, fieldType }) => {
125
+ try {
126
+ resolveVersion(version);
127
+ }
128
+ catch (err) {
129
+ return {
130
+ content: [{ type: 'text', text: err.message }],
131
+ };
132
+ }
133
+ const config = getFieldConfig(version, fieldType);
134
+ if (!config) {
135
+ return {
136
+ content: [
137
+ {
138
+ type: 'text',
139
+ text: `Unknown field type "${fieldType}". Use list_field_types to see available types for version ${version}.`,
140
+ },
141
+ ],
142
+ };
143
+ }
144
+ return {
145
+ content: [
146
+ {
147
+ type: 'text',
148
+ text: JSON.stringify(config, null, 2),
149
+ },
150
+ ],
151
+ };
152
+ });
153
+ // 5. generate_form_schema
154
+ server.tool('generate_form_schema', 'Generate a valid FormSchema JSON from a high-level description of fields. Validates the output automatically.', {
155
+ version: z.string().describe(versionParamDesc),
156
+ description: z.string().optional().describe('Description of the form (used as section title if no sections provided)'),
157
+ fields: z
158
+ .array(z.object({
159
+ name: z.string().describe('Unique field key (camelCase)'),
160
+ type: z.string().describe('Field type: text, password, email, number, textarea, select, multiselect, checkbox, radio, switch, date, dateRange, file'),
161
+ label: z.string().optional().describe('Display label (defaults to name)'),
162
+ required: z.boolean().optional().describe('Whether field is required'),
163
+ extraProps: z.record(z.unknown()).optional().describe('Additional field props (e.g. rows, min, max, options)'),
164
+ validationRules: z.record(z.unknown()).optional().describe('Additional validation rules (e.g. minLength, hasUppercase)'),
165
+ }))
166
+ .describe('Array of field definitions'),
167
+ sections: z
168
+ .array(z.object({
169
+ id: z.string().describe('Section ID'),
170
+ title: z.string().describe('Section title'),
171
+ fieldNames: z.array(z.string()).describe('Field keys in this section'),
172
+ }))
173
+ .optional()
174
+ .describe('Optional section groupings. If omitted, all fields go into a single section.'),
175
+ }, async ({ version, description, fields, sections }) => {
176
+ try {
177
+ resolveVersion(version);
178
+ }
179
+ catch (err) {
180
+ return {
181
+ content: [{ type: 'text', text: err.message }],
182
+ };
183
+ }
184
+ const result = generateFormSchema({ version, description, fields, sections });
185
+ return {
186
+ content: [
187
+ {
188
+ type: 'text',
189
+ text: JSON.stringify(result, null, 2),
190
+ },
191
+ ],
192
+ };
193
+ });
194
+ // ════════════════════════════════════════════════════════════
195
+ // RESOURCES
196
+ // ════════════════════════════════════════════════════════════
197
+ // 1. FormSchema JSON Schema (versioned)
198
+ server.resource('form-schema', new ResourceTemplate('schema://dynamic-forms/{version}/form-schema', {
199
+ list: async () => {
200
+ const { available } = getAvailableVersions();
201
+ return {
202
+ resources: available.map((v) => ({
203
+ uri: `schema://dynamic-forms/${v}/form-schema`,
204
+ name: `FormSchema JSON Schema (v${v})`,
205
+ description: `Complete JSON Schema for dynamic-forms-mui v${v}`,
206
+ mimeType: 'application/json',
207
+ })),
208
+ };
209
+ },
210
+ }), {
211
+ description: 'Complete JSON Schema for the dynamic-forms-mui FormSchema type. Use this as a reference for the expected structure.',
212
+ mimeType: 'application/json',
213
+ }, async (uri, { version }) => {
214
+ const v = Array.isArray(version) ? version[0] : version;
215
+ try {
216
+ resolveVersion(v);
217
+ }
218
+ catch {
219
+ return {
220
+ contents: [
221
+ {
222
+ uri: uri.href,
223
+ text: `Version "${v}" not found. Available: ${getAvailableVersions().available.join(', ')}`,
224
+ mimeType: 'text/plain',
225
+ },
226
+ ],
227
+ };
228
+ }
229
+ return {
230
+ contents: [
231
+ {
232
+ uri: uri.href,
233
+ text: getFormSchemaResource(v),
234
+ mimeType: 'application/json',
235
+ },
236
+ ],
237
+ };
238
+ });
239
+ // 2. Field Types Documentation (versioned)
240
+ server.resource('field-types-docs', new ResourceTemplate('schema://dynamic-forms/{version}/field-types', {
241
+ list: async () => {
242
+ const { available } = getAvailableVersions();
243
+ return {
244
+ resources: available.map((v) => ({
245
+ uri: `schema://dynamic-forms/${v}/field-types`,
246
+ name: `Field Types Documentation (v${v})`,
247
+ description: `Documentation for all field types in dynamic-forms-mui v${v}`,
248
+ mimeType: 'text/markdown',
249
+ })),
250
+ };
251
+ },
252
+ }), {
253
+ description: 'Comprehensive documentation for all field types including props, validations, and examples.',
254
+ mimeType: 'text/markdown',
255
+ }, async (uri, { version }) => {
256
+ const v = Array.isArray(version) ? version[0] : version;
257
+ try {
258
+ resolveVersion(v);
259
+ }
260
+ catch {
261
+ return {
262
+ contents: [
263
+ {
264
+ uri: uri.href,
265
+ text: `Version "${v}" not found. Available: ${getAvailableVersions().available.join(', ')}`,
266
+ mimeType: 'text/plain',
267
+ },
268
+ ],
269
+ };
270
+ }
271
+ return {
272
+ contents: [
273
+ {
274
+ uri: uri.href,
275
+ text: getFieldDocsResource(v),
276
+ mimeType: 'text/markdown',
277
+ },
278
+ ],
279
+ };
280
+ });
281
+ // 3. Example Schemas (versioned + dynamic name)
282
+ server.resource('example', new ResourceTemplate('schema://dynamic-forms/{version}/examples/{name}', {
283
+ list: async () => {
284
+ const { available } = getAvailableVersions();
285
+ const resources = [];
286
+ for (const v of available) {
287
+ const examples = listExamples(v);
288
+ for (const exName of examples) {
289
+ resources.push({
290
+ uri: `schema://dynamic-forms/${v}/examples/${exName}`,
291
+ name: `${exName} form example (v${v})`,
292
+ description: `Example FormSchema: ${exName} (v${v})`,
293
+ mimeType: 'application/json',
294
+ });
295
+ }
296
+ }
297
+ return { resources };
298
+ },
299
+ }), {
300
+ description: 'Example FormSchema configurations for common use cases.',
301
+ mimeType: 'application/json',
302
+ }, async (uri, { version, name }) => {
303
+ const v = Array.isArray(version) ? version[0] : version;
304
+ const exampleName = Array.isArray(name) ? name[0] : name;
305
+ try {
306
+ resolveVersion(v);
307
+ }
308
+ catch {
309
+ return {
310
+ contents: [
311
+ {
312
+ uri: uri.href,
313
+ text: `Version "${v}" not found. Available: ${getAvailableVersions().available.join(', ')}`,
314
+ mimeType: 'text/plain',
315
+ },
316
+ ],
317
+ };
318
+ }
319
+ const content = getExample(v, exampleName);
320
+ if (!content) {
321
+ const available = listExamples(v);
322
+ return {
323
+ contents: [
324
+ {
325
+ uri: uri.href,
326
+ text: `Example "${exampleName}" not found for version ${v}. Available: ${available.join(', ')}`,
327
+ mimeType: 'text/plain',
328
+ },
329
+ ],
330
+ };
331
+ }
332
+ return {
333
+ contents: [
334
+ {
335
+ uri: uri.href,
336
+ text: content,
337
+ mimeType: 'application/json',
338
+ },
339
+ ],
340
+ };
341
+ });
342
+ // ════════════════════════════════════════════════════════════
343
+ // PROMPTS
344
+ // ════════════════════════════════════════════════════════════
345
+ // 1. Generate Backend Endpoint
346
+ server.prompt('generate-backend-endpoint', 'Generate backend API endpoint code (in any language/framework) that returns a valid FormSchema JSON.', {
347
+ language: z.string().describe('Programming language (e.g. Python, Go, C#, Java, TypeScript)'),
348
+ framework: z.string().describe('Web framework (e.g. FastAPI, Gin, ASP.NET, Spring Boot, Express)'),
349
+ formDescription: z
350
+ .string()
351
+ .describe('Natural language description of the form (e.g. "User registration with email, password, and profile fields")'),
352
+ }, ({ language, framework, formDescription }) => ({
353
+ messages: [
354
+ {
355
+ role: 'user',
356
+ content: {
357
+ type: 'text',
358
+ text: generateBackendEndpointPrompt(language, framework, formDescription),
359
+ },
360
+ },
361
+ ],
362
+ }));
363
+ // 2. Generate Form Config
364
+ server.prompt('generate-form-config', 'Generate a complete FormSchema JSON configuration from a natural language description.', {
365
+ formDescription: z
366
+ .string()
367
+ .describe('Natural language description of the form and its fields'),
368
+ fieldHints: z
369
+ .string()
370
+ .optional()
371
+ .describe('Optional additional hints about specific fields, validations, or conditions'),
372
+ }, ({ formDescription, fieldHints }) => ({
373
+ messages: [
374
+ {
375
+ role: 'user',
376
+ content: {
377
+ type: 'text',
378
+ text: generateFormConfigPrompt(formDescription, fieldHints),
379
+ },
380
+ },
381
+ ],
382
+ }));
383
+ // ════════════════════════════════════════════════════════════
384
+ // START SERVER
385
+ // ════════════════════════════════════════════════════════════
386
+ async function main() {
387
+ const transport = new StdioServerTransport();
388
+ await server.connect(transport);
389
+ console.error(`🚀 @ai-hub/dynamic-forms-mui-mcp v${mcpPackageJson.version} server is running (stdio)`);
390
+ }
391
+ main().catch((error) => {
392
+ console.error('Fatal error:', error);
393
+ process.exit(1);
394
+ });
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Returns a prompt that helps generate backend code returning a valid FormSchema.
3
+ */
4
+ export declare function generateBackendEndpointPrompt(language: string, framework: string, formDescription: string): string;
5
+ //# sourceMappingURL=generateBackendEndpoint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateBackendEndpoint.d.ts","sourceRoot":"","sources":["../../src/prompts/generateBackendEndpoint.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,6BAA6B,CAC3C,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,MAAM,GACtB,MAAM,CA6BR"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Returns a prompt that helps generate backend code returning a valid FormSchema.
3
+ */
4
+ export function generateBackendEndpointPrompt(language, framework, formDescription) {
5
+ return `You are a backend developer writing a REST API endpoint that returns a FormSchema JSON object.
6
+
7
+ ## Target Stack
8
+ - Language: ${language}
9
+ - Framework: ${framework}
10
+
11
+ ## Form Requirements
12
+ ${formDescription}
13
+
14
+ ## Instructions
15
+ 1. Create an API endpoint (GET) that returns a JSON object conforming to the FormSchema structure.
16
+ 2. The response must have two top-level properties:
17
+ - "sections": an array of section objects, each with "id", "title", and "fields" (array of field key strings)
18
+ - "fields": a map of field key → field configuration objects
19
+ 3. Each field configuration must include at minimum: "type" and "label"
20
+ 4. Use appropriate field types from this list:
21
+ text, password, email, number, textarea, select, multiselect, checkbox, radio, switch, date, dateRange, file
22
+ 5. Add validation rules where appropriate (required, minLength, maxLength, email, pattern, min, max, etc.)
23
+ 6. If fields depend on each other (e.g., city depends on country), use "optionsSource" with "queryParams" and "dependsOn"
24
+ 7. For conditional visibility, use "showIf" with condition operators: equals, notEquals, in, notIn, isEmpty, isNotEmpty, gt, gte, lt, lte
25
+ 8. Include custom validation messages in the "messages" property for better UX
26
+
27
+ ## Important
28
+ - The endpoint should return ONLY the FormSchema JSON — the frontend @ai-hub/dynamic-forms-mui library will handle all rendering automatically.
29
+ - Do NOT include any HTML or UI code. The backend only provides the schema; the frontend renders it.
30
+ - Use proper HTTP status codes and error handling for your framework.
31
+
32
+ Generate the complete endpoint code.`;
33
+ }