@type-crafter/mcp 1.0.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 +192 -116
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,23 +5,70 @@ An MCP (Model Context Protocol) server that helps AI assistants write correct Ty
|
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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 |
|
|
15
19
|
|
|
16
|
-
|
|
20
|
+
This MCP **teaches** LLMs the correct format and **validates** specs before generation.
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
# Install MCP server
|
|
26
|
+
npm install -g @type-crafter/mcp-server
|
|
27
|
+
|
|
28
|
+
# Also need type-crafter CLI for generation
|
|
29
|
+
npm install -g type-crafter
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Configuration
|
|
33
|
+
|
|
34
|
+
### Claude Desktop
|
|
35
|
+
|
|
36
|
+
**macOS:** `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
37
|
+
|
|
38
|
+
**Windows:** `%APPDATA%\Claude\claude_desktop_config.json`
|
|
39
|
+
|
|
40
|
+
```json
|
|
41
|
+
{
|
|
42
|
+
"mcpServers": {
|
|
43
|
+
"type-crafter": {
|
|
44
|
+
"command": "type-crafter-mcp"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### From Source
|
|
51
|
+
|
|
52
|
+
```json
|
|
53
|
+
{
|
|
54
|
+
"mcpServers": {
|
|
55
|
+
"type-crafter": {
|
|
56
|
+
"command": "node",
|
|
57
|
+
"args": ["/path/to/type-crafter/mcp/dist/index.js"]
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
```
|
|
17
62
|
|
|
18
63
|
## Tools
|
|
19
64
|
|
|
20
65
|
### 1. `get-writing-guide`
|
|
21
66
|
|
|
22
|
-
**
|
|
67
|
+
**Call this FIRST.** Returns the writing guide and a sessionId.
|
|
23
68
|
|
|
24
69
|
```
|
|
70
|
+
Parameters: none
|
|
71
|
+
|
|
25
72
|
Returns:
|
|
26
73
|
- sessionId (pass to other tools)
|
|
27
74
|
- Quick start guide
|
|
@@ -33,62 +80,76 @@ Returns:
|
|
|
33
80
|
|
|
34
81
|
Get detailed rules for a specific topic.
|
|
35
82
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
-
|
|
39
|
-
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
+
```
|
|
46
94
|
|
|
47
95
|
### 3. `validate-spec`
|
|
48
96
|
|
|
49
|
-
Validate a YAML spec
|
|
50
|
-
|
|
51
|
-
**Parameters:**
|
|
97
|
+
Validate a YAML spec for correctness.
|
|
52
98
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
99
|
+
```
|
|
100
|
+
Parameters:
|
|
101
|
+
- sessionId (optional): From get-writing-guide
|
|
102
|
+
- specFilePath (required): Path to YAML file
|
|
57
103
|
|
|
104
|
+
Checks:
|
|
58
105
|
- Structure (info, types, groupedTypes)
|
|
59
106
|
- Common mistakes (nullable, optional, wrong paths)
|
|
60
|
-
-
|
|
107
|
+
- Reference rules (top-file vs non-top-file)
|
|
108
|
+
```
|
|
61
109
|
|
|
62
110
|
### 4. `get-spec-info`
|
|
63
111
|
|
|
64
112
|
Get information about an existing spec file.
|
|
65
113
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
-
|
|
69
|
-
|
|
70
|
-
**Returns:**
|
|
114
|
+
```
|
|
115
|
+
Parameters:
|
|
116
|
+
- specFilePath (required): Path to YAML file
|
|
71
117
|
|
|
118
|
+
Returns:
|
|
72
119
|
- Version and title
|
|
73
120
|
- List of all types
|
|
74
121
|
- List of all grouped types
|
|
122
|
+
```
|
|
75
123
|
|
|
76
124
|
### 5. `list-languages`
|
|
77
125
|
|
|
78
|
-
List supported languages for
|
|
126
|
+
List supported languages for type-crafter CLI.
|
|
127
|
+
|
|
128
|
+
```
|
|
129
|
+
Parameters: none
|
|
130
|
+
|
|
131
|
+
Returns:
|
|
132
|
+
- typescript
|
|
133
|
+
- typescript-with-decoders
|
|
134
|
+
```
|
|
79
135
|
|
|
80
|
-
##
|
|
136
|
+
## Workflow
|
|
81
137
|
|
|
82
138
|
```
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
+
└─────────────────────────────────────────────────────────────┘
|
|
92
153
|
```
|
|
93
154
|
|
|
94
155
|
## Session Enforcement
|
|
@@ -100,120 +161,135 @@ The MCP uses sessions to encourage reading the guide first:
|
|
|
100
161
|
- If validation fails with common mistakes AND no sessionId → suggests reading the guide
|
|
101
162
|
- Sessions expire after 30 minutes
|
|
102
163
|
|
|
103
|
-
##
|
|
104
|
-
|
|
105
|
-
### Prerequisites
|
|
164
|
+
## YAML Quick Reference
|
|
106
165
|
|
|
107
|
-
|
|
108
|
-
|
|
166
|
+
```yaml
|
|
167
|
+
info:
|
|
168
|
+
version: '1.0.0'
|
|
169
|
+
title: 'My Types'
|
|
109
170
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
|
114
181
|
```
|
|
115
182
|
|
|
116
|
-
|
|
183
|
+
**Generated TypeScript:**
|
|
117
184
|
|
|
118
|
-
```
|
|
119
|
-
|
|
185
|
+
```typescript
|
|
186
|
+
export type User = {
|
|
187
|
+
id: string;
|
|
188
|
+
email: string;
|
|
189
|
+
name: string | null;
|
|
190
|
+
};
|
|
120
191
|
```
|
|
121
192
|
|
|
122
|
-
##
|
|
193
|
+
## Key Rules
|
|
123
194
|
|
|
124
|
-
|
|
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` |
|
|
125
203
|
|
|
126
|
-
|
|
204
|
+
## Usage Examples
|
|
127
205
|
|
|
128
|
-
|
|
206
|
+
### Creating Types
|
|
129
207
|
|
|
130
|
-
**Windows:** `%APPDATA%\Claude\claude_desktop_config.json`
|
|
131
|
-
|
|
132
|
-
```json
|
|
133
|
-
{
|
|
134
|
-
"mcpServers": {
|
|
135
|
-
"type-crafter": {
|
|
136
|
-
"command": "type-crafter-mcp"
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
208
|
```
|
|
209
|
+
User: "Create types for a user API with id, email, and optional name"
|
|
141
210
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
"type-crafter": {
|
|
148
|
-
"command": "node",
|
|
149
|
-
"args": ["/path/to/type-crafter/mcp/dist/index.js"]
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
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"
|
|
153
216
|
```
|
|
154
217
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
### Learning the Format
|
|
218
|
+
### Validating Specs
|
|
158
219
|
|
|
159
220
|
```
|
|
160
|
-
User: "
|
|
221
|
+
User: "Check if my types.yaml is valid"
|
|
161
222
|
|
|
162
|
-
LLM: [Calls
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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"
|
|
166
227
|
```
|
|
167
228
|
|
|
168
|
-
###
|
|
229
|
+
### Learning Specific Rules
|
|
169
230
|
|
|
170
231
|
```
|
|
171
|
-
User: "
|
|
232
|
+
User: "How do references work in Type Crafter?"
|
|
172
233
|
|
|
173
|
-
LLM: [Calls
|
|
174
|
-
|
|
175
|
-
1. Line 15: 'nullable: true' doesn't exist - use required array
|
|
176
|
-
2. Line 23: Wrong path format..."
|
|
234
|
+
LLM: [Calls get-rules-section with section: "references"]
|
|
235
|
+
"References in Type Crafter work like this..."
|
|
177
236
|
```
|
|
178
237
|
|
|
179
|
-
|
|
238
|
+
## Troubleshooting
|
|
180
239
|
|
|
181
|
-
|
|
182
|
-
|
|
240
|
+
### "nullable: true" errors
|
|
241
|
+
|
|
242
|
+
Type Crafter doesn't have a `nullable` property. Use the `required` array:
|
|
183
243
|
|
|
184
|
-
|
|
185
|
-
|
|
244
|
+
```yaml
|
|
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
|
|
186
254
|
```
|
|
187
255
|
|
|
188
|
-
|
|
256
|
+
### Reference path errors
|
|
257
|
+
|
|
258
|
+
All paths are from project root (where you run the CLI), not relative to current file:
|
|
189
259
|
|
|
190
260
|
```yaml
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
title: 'My Types'
|
|
261
|
+
# Wrong
|
|
262
|
+
$ref: '../common/types.yaml#/User'
|
|
194
263
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
type: object
|
|
198
|
-
required:
|
|
199
|
-
- id # Required → string
|
|
200
|
-
- email # Required → string
|
|
201
|
-
properties:
|
|
202
|
-
id: { type: string }
|
|
203
|
-
email: { type: string }
|
|
204
|
-
name: { type: string } # Not in required → string | null
|
|
264
|
+
# Correct
|
|
265
|
+
$ref: './src/common/types.yaml#/User'
|
|
205
266
|
```
|
|
206
267
|
|
|
207
|
-
|
|
268
|
+
### "Arrays cannot be top-level types"
|
|
208
269
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
270
|
+
Arrays must be properties within objects:
|
|
271
|
+
|
|
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 }
|
|
285
|
+
```
|
|
213
286
|
|
|
214
287
|
## Development
|
|
215
288
|
|
|
216
289
|
```bash
|
|
290
|
+
# Install dependencies
|
|
291
|
+
npm install
|
|
292
|
+
|
|
217
293
|
# Build
|
|
218
294
|
npm run build
|
|
219
295
|
|