@type-crafter/mcp 0.6.0 → 1.1.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 +203 -221
- package/dist/docs/RULES_COMPOSITION.md +343 -0
- package/dist/docs/RULES_NULLABLE.md +293 -0
- package/dist/docs/RULES_PATTERNS.md +516 -0
- package/dist/docs/RULES_REFERENCES.md +302 -0
- package/dist/docs/RULES_STRUCTURE.md +248 -0
- package/dist/docs/RULES_TYPES.md +291 -0
- package/dist/docs/WRITING_GUIDE.md +179 -0
- package/dist/index.js +321 -345
- package/package.json +3 -5
- package/src/GUIDE.md +0 -459
- package/src/SPEC_RULES.md +0 -1755
package/README.md
CHANGED
|
@@ -1,323 +1,305 @@
|
|
|
1
1
|
# Type Crafter MCP Server
|
|
2
2
|
|
|
3
|
-
An MCP (Model Context Protocol) server
|
|
3
|
+
An MCP (Model Context Protocol) server that helps AI assistants write correct Type Crafter YAML specifications.
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@type-crafter/mcp-server)
|
|
6
6
|
[](https://opensource.org/licenses/ISC)
|
|
7
7
|
|
|
8
|
-
##
|
|
8
|
+
## Why This MCP?
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
LLMs often make mistakes when writing Type Crafter YAML specs:
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
| Common Mistake | Why It Fails |
|
|
13
|
+
| ------------------ | ------------------------------- |
|
|
14
|
+
| `nullable: true` | Property doesn't exist |
|
|
15
|
+
| `optional: true` | Property doesn't exist |
|
|
16
|
+
| `name?: string` | Syntax not supported |
|
|
17
|
+
| Top-level arrays | Arrays must be properties |
|
|
18
|
+
| `../relative/path` | Paths must be from project root |
|
|
13
19
|
|
|
14
|
-
|
|
20
|
+
This MCP **teaches** LLMs the correct format and **validates** specs before generation.
|
|
15
21
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
- `language` (required): Target language - `typescript` or `typescript-with-decoders`
|
|
19
|
-
- `specFilePath` (required): Path to the YAML specification file
|
|
20
|
-
- `outputDirectory` (required): Directory where generated types will be written
|
|
21
|
-
- `typesWriterMode` (optional): `SingleFile` or `Files` (default: `SingleFile`)
|
|
22
|
-
- `groupedTypesWriterMode` (optional): `FolderWithFiles` or `SingleFile` (default: `SingleFile`)
|
|
22
|
+
## Installation
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
```bash
|
|
25
|
+
# Install MCP server
|
|
26
|
+
npm install -g @type-crafter/mcp-server
|
|
25
27
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"language": "typescript",
|
|
29
|
-
"specFilePath": "./types.yaml",
|
|
30
|
-
"outputDirectory": "./generated-types",
|
|
31
|
-
"typesWriterMode": "SingleFile",
|
|
32
|
-
"groupedTypesWriterMode": "FolderWithFiles"
|
|
33
|
-
}
|
|
28
|
+
# Also need type-crafter CLI for generation
|
|
29
|
+
npm install -g type-crafter
|
|
34
30
|
```
|
|
35
31
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
Validate a YAML specification file without generating types.
|
|
32
|
+
## Configuration
|
|
39
33
|
|
|
40
|
-
|
|
34
|
+
### Claude Desktop
|
|
41
35
|
|
|
42
|
-
|
|
36
|
+
**macOS:** `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
43
37
|
|
|
44
|
-
**
|
|
38
|
+
**Windows:** `%APPDATA%\Claude\claude_desktop_config.json`
|
|
45
39
|
|
|
46
40
|
```json
|
|
47
41
|
{
|
|
48
|
-
"
|
|
42
|
+
"mcpServers": {
|
|
43
|
+
"type-crafter": {
|
|
44
|
+
"command": "type-crafter-mcp"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
49
47
|
}
|
|
50
48
|
```
|
|
51
49
|
|
|
52
|
-
###
|
|
53
|
-
|
|
54
|
-
List all supported target languages for type generation.
|
|
55
|
-
|
|
56
|
-
**Parameters:** None
|
|
57
|
-
|
|
58
|
-
### 4. `get-spec-info`
|
|
59
|
-
|
|
60
|
-
Get detailed information about a YAML specification file including version, title, and all defined types.
|
|
61
|
-
|
|
62
|
-
**Parameters:**
|
|
63
|
-
|
|
64
|
-
- `specFilePath` (required): Path to the YAML specification file
|
|
65
|
-
|
|
66
|
-
**Example:**
|
|
50
|
+
### From Source
|
|
67
51
|
|
|
68
52
|
```json
|
|
69
53
|
{
|
|
70
|
-
"
|
|
54
|
+
"mcpServers": {
|
|
55
|
+
"type-crafter": {
|
|
56
|
+
"command": "node",
|
|
57
|
+
"args": ["/path/to/type-crafter/mcp/dist/index.js"]
|
|
58
|
+
}
|
|
59
|
+
}
|
|
71
60
|
}
|
|
72
61
|
```
|
|
73
62
|
|
|
74
|
-
|
|
63
|
+
## Tools
|
|
75
64
|
|
|
76
|
-
|
|
65
|
+
### 1. `get-writing-guide`
|
|
77
66
|
|
|
78
|
-
**
|
|
67
|
+
**Call this FIRST.** Returns the writing guide and a sessionId.
|
|
79
68
|
|
|
80
|
-
|
|
69
|
+
```
|
|
70
|
+
Parameters: none
|
|
81
71
|
|
|
82
|
-
|
|
83
|
-
-
|
|
84
|
-
-
|
|
85
|
-
-
|
|
72
|
+
Returns:
|
|
73
|
+
- sessionId (pass to other tools)
|
|
74
|
+
- Quick start guide
|
|
75
|
+
- Common mistakes to avoid
|
|
76
|
+
- Quick reference table
|
|
77
|
+
```
|
|
86
78
|
|
|
87
|
-
|
|
79
|
+
### 2. `get-rules-section`
|
|
88
80
|
|
|
89
|
-
|
|
90
|
-
- Data types and TypeScript mapping
|
|
91
|
-
- Nullable types rules (properties not in `required` become `Type | null`)
|
|
92
|
-
- Type definitions (objects, enums, arrays, nested objects)
|
|
93
|
-
- References (local, external, cyclic)
|
|
94
|
-
- Composition (oneOf unions, allOf intersections)
|
|
95
|
-
- Best practices and common patterns
|
|
96
|
-
- Complete examples with YAML and TypeScript side-by-side
|
|
81
|
+
Get detailed rules for a specific topic.
|
|
97
82
|
|
|
98
|
-
|
|
83
|
+
```
|
|
84
|
+
Parameters:
|
|
85
|
+
- sessionId (optional): From get-writing-guide
|
|
86
|
+
- section (required): One of:
|
|
87
|
+
- structure → Root structure, info, types vs groupedTypes
|
|
88
|
+
- types → Objects, enums, primitives, arrays
|
|
89
|
+
- nullable → How required array controls nullability
|
|
90
|
+
- references → $ref syntax, top-file vs non-top-file
|
|
91
|
+
- composition → oneOf (unions), allOf (intersections)
|
|
92
|
+
- patterns → Common patterns with examples
|
|
93
|
+
```
|
|
99
94
|
|
|
100
|
-
|
|
101
|
-
- `type-crafter` CLI installed globally or locally
|
|
95
|
+
### 3. `validate-spec`
|
|
102
96
|
|
|
103
|
-
|
|
97
|
+
Validate a YAML spec for correctness.
|
|
104
98
|
|
|
105
|
-
```
|
|
106
|
-
|
|
99
|
+
```
|
|
100
|
+
Parameters:
|
|
101
|
+
- sessionId (optional): From get-writing-guide
|
|
102
|
+
- specFilePath (required): Path to YAML file
|
|
103
|
+
|
|
104
|
+
Checks:
|
|
105
|
+
- Structure (info, types, groupedTypes)
|
|
106
|
+
- Common mistakes (nullable, optional, wrong paths)
|
|
107
|
+
- Reference rules (top-file vs non-top-file)
|
|
107
108
|
```
|
|
108
109
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
### Option 1: Install from npm (Recommended)
|
|
110
|
+
### 4. `get-spec-info`
|
|
112
111
|
|
|
113
|
-
|
|
112
|
+
Get information about an existing spec file.
|
|
114
113
|
|
|
115
|
-
```bash
|
|
116
|
-
npm install -g @type-crafter/mcp-server
|
|
117
114
|
```
|
|
115
|
+
Parameters:
|
|
116
|
+
- specFilePath (required): Path to YAML file
|
|
118
117
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
118
|
+
Returns:
|
|
119
|
+
- Version and title
|
|
120
|
+
- List of all types
|
|
121
|
+
- List of all grouped types
|
|
123
122
|
```
|
|
124
123
|
|
|
125
|
-
###
|
|
124
|
+
### 5. `list-languages`
|
|
126
125
|
|
|
127
|
-
|
|
126
|
+
List supported languages for type-crafter CLI.
|
|
128
127
|
|
|
129
|
-
```bash
|
|
130
|
-
git clone https://github.com/sinha-sahil/type-crafter.git
|
|
131
|
-
cd type-crafter/mcp-server
|
|
132
128
|
```
|
|
129
|
+
Parameters: none
|
|
133
130
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
npm install
|
|
131
|
+
Returns:
|
|
132
|
+
- typescript
|
|
133
|
+
- typescript-with-decoders
|
|
138
134
|
```
|
|
139
135
|
|
|
140
|
-
|
|
136
|
+
## Workflow
|
|
141
137
|
|
|
142
|
-
```
|
|
143
|
-
|
|
138
|
+
```
|
|
139
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
140
|
+
│ 1. get-writing-guide │
|
|
141
|
+
│ └─→ Returns sessionId + guide │
|
|
142
|
+
│ │
|
|
143
|
+
│ 2. Write YAML spec (following the guide) │
|
|
144
|
+
│ │
|
|
145
|
+
│ 3. validate-spec(sessionId, specFilePath) │
|
|
146
|
+
│ ├─→ Valid: "Run type-crafter generate..." │
|
|
147
|
+
│ └─→ Errors: Shows issues + suggests get-rules-section │
|
|
148
|
+
│ │
|
|
149
|
+
│ 4. Fix issues, re-validate │
|
|
150
|
+
│ │
|
|
151
|
+
│ 5. User runs: type-crafter generate typescript spec.yaml │
|
|
152
|
+
└─────────────────────────────────────────────────────────────┘
|
|
144
153
|
```
|
|
145
154
|
|
|
146
|
-
##
|
|
147
|
-
|
|
148
|
-
### Using with Claude Desktop (Global Installation)
|
|
149
|
-
|
|
150
|
-
After installing globally via npm:
|
|
155
|
+
## Session Enforcement
|
|
151
156
|
|
|
152
|
-
|
|
157
|
+
The MCP uses sessions to encourage reading the guide first:
|
|
153
158
|
|
|
154
|
-
|
|
159
|
+
- `get-writing-guide` returns a `sessionId`
|
|
160
|
+
- Pass `sessionId` to other tools
|
|
161
|
+
- If validation fails with common mistakes AND no sessionId → suggests reading the guide
|
|
162
|
+
- Sessions expire after 30 minutes
|
|
155
163
|
|
|
156
|
-
|
|
164
|
+
## YAML Quick Reference
|
|
157
165
|
|
|
158
|
-
|
|
166
|
+
```yaml
|
|
167
|
+
info:
|
|
168
|
+
version: '1.0.0'
|
|
169
|
+
title: 'My Types'
|
|
159
170
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}
|
|
171
|
+
types:
|
|
172
|
+
User:
|
|
173
|
+
type: object
|
|
174
|
+
required:
|
|
175
|
+
- id # Required → string
|
|
176
|
+
- email # Required → string
|
|
177
|
+
properties:
|
|
178
|
+
id: { type: string }
|
|
179
|
+
email: { type: string }
|
|
180
|
+
name: { type: string } # Not in required → string | null
|
|
168
181
|
```
|
|
169
182
|
|
|
170
|
-
**
|
|
183
|
+
**Generated TypeScript:**
|
|
171
184
|
|
|
172
|
-
```
|
|
173
|
-
{
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
185
|
+
```typescript
|
|
186
|
+
export type User = {
|
|
187
|
+
id: string;
|
|
188
|
+
email: string;
|
|
189
|
+
name: string | null;
|
|
190
|
+
};
|
|
181
191
|
```
|
|
182
192
|
|
|
183
|
-
|
|
193
|
+
## Key Rules
|
|
184
194
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
```
|
|
195
|
+
| Rule | Correct | Wrong |
|
|
196
|
+
| ------------------------- | ---------------------------------- | ----------------------- |
|
|
197
|
+
| Nullable fields | Omit from `required` array | `nullable: true` |
|
|
198
|
+
| Optional fields | Omit from `required` array | `optional: true` |
|
|
199
|
+
| Arrays | Property inside object | Top-level type |
|
|
200
|
+
| External refs | `./path/from/root/file.yaml#/Type` | `../relative/path.yaml` |
|
|
201
|
+
| Same-file refs (top file) | `#/types/TypeName` | - |
|
|
202
|
+
| Same-file refs (non-top) | `./this/file.yaml#/TypeName` | `#/TypeName` |
|
|
196
203
|
|
|
197
204
|
## Usage Examples
|
|
198
205
|
|
|
199
|
-
|
|
206
|
+
### Creating Types
|
|
200
207
|
|
|
201
|
-
|
|
208
|
+
```
|
|
209
|
+
User: "Create types for a user API with id, email, and optional name"
|
|
202
210
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
211
|
+
LLM: [Calls get-writing-guide]
|
|
212
|
+
[Reads the guide, notes required array controls nullability]
|
|
213
|
+
[Creates YAML spec]
|
|
214
|
+
[Calls validate-spec]
|
|
215
|
+
"Here's your valid spec. Run: type-crafter generate typescript ./types.yaml ./output"
|
|
216
|
+
```
|
|
206
217
|
|
|
207
|
-
|
|
218
|
+
### Validating Specs
|
|
208
219
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
```
|
|
220
|
+
```
|
|
221
|
+
User: "Check if my types.yaml is valid"
|
|
212
222
|
|
|
213
|
-
|
|
223
|
+
LLM: [Calls validate-spec]
|
|
224
|
+
"Found 2 issues:
|
|
225
|
+
1. Line 15: 'nullable: true' doesn't exist - use required array
|
|
226
|
+
2. Line 23: Wrong path format - use ./path/from/root"
|
|
227
|
+
```
|
|
214
228
|
|
|
215
|
-
|
|
216
|
-
Validate my types.yaml specification file
|
|
217
|
-
```
|
|
229
|
+
### Learning Specific Rules
|
|
218
230
|
|
|
219
|
-
|
|
231
|
+
```
|
|
232
|
+
User: "How do references work in Type Crafter?"
|
|
220
233
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
234
|
+
LLM: [Calls get-rules-section with section: "references"]
|
|
235
|
+
"References in Type Crafter work like this..."
|
|
236
|
+
```
|
|
224
237
|
|
|
225
|
-
|
|
226
|
-
```
|
|
227
|
-
What languages does Type Crafter support?
|
|
228
|
-
```
|
|
238
|
+
## Troubleshooting
|
|
229
239
|
|
|
230
|
-
|
|
240
|
+
### "nullable: true" errors
|
|
231
241
|
|
|
232
|
-
|
|
242
|
+
Type Crafter doesn't have a `nullable` property. Use the `required` array:
|
|
233
243
|
|
|
234
244
|
```yaml
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
type: string
|
|
245
|
-
|
|
246
|
-
groupedTypes:
|
|
247
|
-
GroupName:
|
|
248
|
-
TypeInGroup:
|
|
249
|
-
type: object
|
|
250
|
-
properties:
|
|
251
|
-
id:
|
|
252
|
-
type: string
|
|
245
|
+
# Properties in required → non-nullable
|
|
246
|
+
# Properties NOT in required → nullable (Type | null)
|
|
247
|
+
required:
|
|
248
|
+
- id
|
|
249
|
+
- email
|
|
250
|
+
properties:
|
|
251
|
+
id: { type: string } # string
|
|
252
|
+
email: { type: string } # string
|
|
253
|
+
name: { type: string } # string | null
|
|
253
254
|
```
|
|
254
255
|
|
|
255
|
-
|
|
256
|
+
### Reference path errors
|
|
256
257
|
|
|
257
|
-
|
|
258
|
+
All paths are from project root (where you run the CLI), not relative to current file:
|
|
258
259
|
|
|
259
|
-
|
|
260
|
+
```yaml
|
|
261
|
+
# Wrong
|
|
262
|
+
$ref: '../common/types.yaml#/User'
|
|
260
263
|
|
|
261
|
-
|
|
262
|
-
|
|
264
|
+
# Correct
|
|
265
|
+
$ref: './src/common/types.yaml#/User'
|
|
263
266
|
```
|
|
264
267
|
|
|
265
|
-
###
|
|
266
|
-
|
|
267
|
-
```bash
|
|
268
|
-
npm run dev
|
|
269
|
-
```
|
|
268
|
+
### "Arrays cannot be top-level types"
|
|
270
269
|
|
|
271
|
-
|
|
270
|
+
Arrays must be properties within objects:
|
|
272
271
|
|
|
273
|
-
```
|
|
274
|
-
|
|
275
|
-
|
|
272
|
+
```yaml
|
|
273
|
+
# Wrong
|
|
274
|
+
Tags:
|
|
275
|
+
type: array
|
|
276
|
+
items: { type: string }
|
|
277
|
+
|
|
278
|
+
# Correct
|
|
279
|
+
Post:
|
|
280
|
+
type: object
|
|
281
|
+
properties:
|
|
282
|
+
tags:
|
|
283
|
+
type: array
|
|
284
|
+
items: { type: string }
|
|
276
285
|
```
|
|
277
286
|
|
|
278
|
-
##
|
|
279
|
-
|
|
280
|
-
Before publishing or to test the installed package:
|
|
287
|
+
## Development
|
|
281
288
|
|
|
282
289
|
```bash
|
|
283
|
-
#
|
|
284
|
-
npm
|
|
285
|
-
|
|
286
|
-
# Install globally from tarball
|
|
287
|
-
npm install -g ./type-crafter-mcp-server-0.1.0.tgz
|
|
288
|
-
|
|
289
|
-
# Test it
|
|
290
|
-
type-crafter-mcp
|
|
291
|
-
```
|
|
292
|
-
|
|
293
|
-
See [PUBLISHING.md](./PUBLISHING.md) for detailed publishing instructions.
|
|
294
|
-
|
|
295
|
-
## Troubleshooting
|
|
296
|
-
|
|
297
|
-
### Server not connecting
|
|
298
|
-
|
|
299
|
-
- **Global installation:** Ensure `type-crafter-mcp` is in your PATH
|
|
300
|
-
- **Local installation:** Verify the path in your configuration is correct
|
|
301
|
-
- Check that the server was built successfully (`npm run build`)
|
|
302
|
-
- Restart Claude Desktop after modifying the configuration
|
|
303
|
-
- Check Node.js version (requires >= 18.0.0)
|
|
304
|
-
|
|
305
|
-
### Type generation errors
|
|
306
|
-
|
|
307
|
-
- Ensure `type-crafter` CLI is installed: `npm install -g type-crafter`
|
|
308
|
-
- Validate your YAML specification using the `validate-spec` tool
|
|
309
|
-
- Check that all file paths are absolute or relative to your working directory
|
|
310
|
-
- Ensure the output directory exists or the server has permissions to create it
|
|
311
|
-
|
|
312
|
-
### Permission denied error
|
|
290
|
+
# Install dependencies
|
|
291
|
+
npm install
|
|
313
292
|
|
|
314
|
-
|
|
315
|
-
|
|
293
|
+
# Build
|
|
294
|
+
npm run build
|
|
316
295
|
|
|
317
|
-
|
|
296
|
+
# Watch mode
|
|
297
|
+
npm run dev
|
|
318
298
|
|
|
319
|
-
|
|
299
|
+
# Lint
|
|
300
|
+
npm run lint
|
|
301
|
+
```
|
|
320
302
|
|
|
321
303
|
## License
|
|
322
304
|
|
|
323
|
-
ISC
|
|
305
|
+
ISC
|