@type-crafter/mcp 0.5.0 → 1.0.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 +113 -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 -1527
package/README.md
CHANGED
|
@@ -1,162 +1,134 @@
|
|
|
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
|
+
## What This MCP Does
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
This MCP server helps LLMs:
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
1. **Learn** the correct YAML specification format
|
|
13
|
+
2. **Validate** YAML specs before generation
|
|
14
|
+
3. **Avoid** common mistakes like `nullable: true` (which doesn't exist)
|
|
13
15
|
|
|
14
|
-
|
|
16
|
+
Type generation is handled by the `type-crafter` CLI in your project.
|
|
15
17
|
|
|
16
|
-
|
|
18
|
+
## Tools
|
|
17
19
|
|
|
18
|
-
|
|
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`)
|
|
20
|
+
### 1. `get-writing-guide`
|
|
23
21
|
|
|
24
|
-
**
|
|
22
|
+
**CALL THIS FIRST** - Returns the writing guide and a sessionId.
|
|
25
23
|
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"groupedTypesWriterMode": "FolderWithFiles"
|
|
33
|
-
}
|
|
24
|
+
```
|
|
25
|
+
Returns:
|
|
26
|
+
- sessionId (pass to other tools)
|
|
27
|
+
- Quick start guide
|
|
28
|
+
- Common mistakes to avoid
|
|
29
|
+
- Quick reference table
|
|
34
30
|
```
|
|
35
31
|
|
|
36
|
-
### 2. `
|
|
32
|
+
### 2. `get-rules-section`
|
|
37
33
|
|
|
38
|
-
|
|
34
|
+
Get detailed rules for a specific topic.
|
|
39
35
|
|
|
40
36
|
**Parameters:**
|
|
41
37
|
|
|
42
|
-
- `
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
### 3. `list-languages`
|
|
38
|
+
- `sessionId` (optional): Session ID from get-writing-guide
|
|
39
|
+
- `section` (required): One of:
|
|
40
|
+
- `structure` - Root structure, info section, types vs groupedTypes
|
|
41
|
+
- `types` - Objects, enums, primitives, arrays
|
|
42
|
+
- `nullable` - How `required` array controls nullability
|
|
43
|
+
- `references` - $ref syntax, top-file vs non-top-file rules
|
|
44
|
+
- `composition` - oneOf (unions), allOf (intersections)
|
|
45
|
+
- `patterns` - Common patterns with full examples
|
|
53
46
|
|
|
54
|
-
|
|
47
|
+
### 3. `validate-spec`
|
|
55
48
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
### 4. `get-spec-info`
|
|
59
|
-
|
|
60
|
-
Get detailed information about a YAML specification file including version, title, and all defined types.
|
|
49
|
+
Validate a YAML spec file for correctness.
|
|
61
50
|
|
|
62
51
|
**Parameters:**
|
|
63
52
|
|
|
53
|
+
- `sessionId` (optional): Session ID from get-writing-guide
|
|
64
54
|
- `specFilePath` (required): Path to the YAML specification file
|
|
65
55
|
|
|
66
|
-
**
|
|
67
|
-
|
|
68
|
-
```json
|
|
69
|
-
{
|
|
70
|
-
"specFilePath": "./types.yaml"
|
|
71
|
-
}
|
|
72
|
-
```
|
|
56
|
+
**Checks:**
|
|
73
57
|
|
|
74
|
-
|
|
58
|
+
- Structure (info, types, groupedTypes)
|
|
59
|
+
- Common mistakes (nullable, optional, wrong paths)
|
|
60
|
+
- Top-file vs non-top-file reference rules
|
|
75
61
|
|
|
76
|
-
|
|
62
|
+
### 4. `get-spec-info`
|
|
77
63
|
|
|
78
|
-
|
|
64
|
+
Get information about an existing spec file.
|
|
79
65
|
|
|
80
|
-
**
|
|
66
|
+
**Parameters:**
|
|
81
67
|
|
|
82
|
-
-
|
|
83
|
-
- You want to understand the Type Crafter spec format
|
|
84
|
-
- You need guidance on type mappings and nullable types
|
|
85
|
-
- You want to learn about references, composition, and best practices
|
|
68
|
+
- `specFilePath` (required): Path to the YAML specification file
|
|
86
69
|
|
|
87
|
-
**Returns:**
|
|
70
|
+
**Returns:**
|
|
88
71
|
|
|
89
|
-
-
|
|
90
|
-
-
|
|
91
|
-
-
|
|
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
|
|
72
|
+
- Version and title
|
|
73
|
+
- List of all types
|
|
74
|
+
- List of all grouped types
|
|
97
75
|
|
|
98
|
-
|
|
76
|
+
### 5. `list-languages`
|
|
99
77
|
|
|
100
|
-
|
|
101
|
-
- `type-crafter` CLI installed globally or locally
|
|
78
|
+
List supported languages for the type-crafter CLI.
|
|
102
79
|
|
|
103
|
-
|
|
80
|
+
## Recommended Workflow
|
|
104
81
|
|
|
105
|
-
```bash
|
|
106
|
-
npm install -g type-crafter
|
|
107
82
|
```
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
83
|
+
1. Call get-writing-guide
|
|
84
|
+
↓
|
|
85
|
+
2. Write YAML spec (following the guide)
|
|
86
|
+
↓
|
|
87
|
+
3. Call validate-spec
|
|
88
|
+
↓
|
|
89
|
+
4. Fix any issues (use get-rules-section for details)
|
|
90
|
+
↓
|
|
91
|
+
5. Run type-crafter CLI in your project
|
|
117
92
|
```
|
|
118
93
|
|
|
119
|
-
|
|
94
|
+
## Session Enforcement
|
|
120
95
|
|
|
121
|
-
|
|
122
|
-
npm install @type-crafter/mcp-server
|
|
123
|
-
```
|
|
96
|
+
The MCP uses sessions to encourage reading the guide first:
|
|
124
97
|
|
|
125
|
-
|
|
98
|
+
- `get-writing-guide` returns a `sessionId`
|
|
99
|
+
- Pass `sessionId` to other tools
|
|
100
|
+
- If validation fails with common mistakes AND no sessionId → suggests reading the guide
|
|
101
|
+
- Sessions expire after 30 minutes
|
|
126
102
|
|
|
127
|
-
|
|
103
|
+
## Installation
|
|
128
104
|
|
|
129
|
-
|
|
130
|
-
git clone https://github.com/sinha-sahil/type-crafter.git
|
|
131
|
-
cd type-crafter/mcp-server
|
|
132
|
-
```
|
|
105
|
+
### Prerequisites
|
|
133
106
|
|
|
134
|
-
|
|
107
|
+
- Node.js >= 18.0.0
|
|
108
|
+
- `type-crafter` CLI installed in your project
|
|
135
109
|
|
|
136
110
|
```bash
|
|
137
|
-
npm install
|
|
111
|
+
npm install -g type-crafter
|
|
112
|
+
# or locally
|
|
113
|
+
npm install type-crafter
|
|
138
114
|
```
|
|
139
115
|
|
|
140
|
-
|
|
116
|
+
### Install MCP Server
|
|
141
117
|
|
|
142
118
|
```bash
|
|
143
|
-
npm
|
|
119
|
+
npm install -g @type-crafter/mcp-server
|
|
144
120
|
```
|
|
145
121
|
|
|
146
122
|
## Configuration
|
|
147
123
|
|
|
148
|
-
###
|
|
124
|
+
### Claude Desktop
|
|
149
125
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
Edit your Claude Desktop configuration file:
|
|
126
|
+
Edit your Claude Desktop config:
|
|
153
127
|
|
|
154
128
|
**macOS:** `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
155
129
|
|
|
156
130
|
**Windows:** `%APPDATA%\Claude\claude_desktop_config.json`
|
|
157
131
|
|
|
158
|
-
**For global installation:**
|
|
159
|
-
|
|
160
132
|
```json
|
|
161
133
|
{
|
|
162
134
|
"mcpServers": {
|
|
@@ -167,28 +139,14 @@ Edit your Claude Desktop configuration file:
|
|
|
167
139
|
}
|
|
168
140
|
```
|
|
169
141
|
|
|
170
|
-
|
|
142
|
+
### From Source
|
|
171
143
|
|
|
172
144
|
```json
|
|
173
145
|
{
|
|
174
146
|
"mcpServers": {
|
|
175
147
|
"type-crafter": {
|
|
176
148
|
"command": "node",
|
|
177
|
-
"args": ["/
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
**For project-local npm installation:**
|
|
184
|
-
|
|
185
|
-
```json
|
|
186
|
-
{
|
|
187
|
-
"mcpServers": {
|
|
188
|
-
"type-crafter": {
|
|
189
|
-
"command": "npx",
|
|
190
|
-
"args": ["type-crafter-mcp"],
|
|
191
|
-
"cwd": "/path/to/your/project"
|
|
149
|
+
"args": ["/path/to/type-crafter/mcp/dist/index.js"]
|
|
192
150
|
}
|
|
193
151
|
}
|
|
194
152
|
}
|
|
@@ -196,142 +154,76 @@ Edit your Claude Desktop configuration file:
|
|
|
196
154
|
|
|
197
155
|
## Usage Examples
|
|
198
156
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
1. **Get specification rules (before writing specs):**
|
|
157
|
+
### Learning the Format
|
|
202
158
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
2. **Generate TypeScript types:**
|
|
159
|
+
```
|
|
160
|
+
User: "I need to create types for a user API"
|
|
208
161
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
162
|
+
LLM: [Calls get-writing-guide]
|
|
163
|
+
LLM: "I've read the Type Crafter guide. Here's what I learned..."
|
|
164
|
+
LLM: [Creates YAML following the rules]
|
|
165
|
+
LLM: [Calls validate-spec to verify]
|
|
166
|
+
```
|
|
212
167
|
|
|
213
|
-
|
|
168
|
+
### Validating Existing Spec
|
|
214
169
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
```
|
|
170
|
+
```
|
|
171
|
+
User: "Check if my types.yaml is valid"
|
|
218
172
|
|
|
219
|
-
|
|
173
|
+
LLM: [Calls validate-spec with the file path]
|
|
174
|
+
LLM: "Found 2 issues:
|
|
175
|
+
1. Line 15: 'nullable: true' doesn't exist - use required array
|
|
176
|
+
2. Line 23: Wrong path format..."
|
|
177
|
+
```
|
|
220
178
|
|
|
221
|
-
|
|
222
|
-
Show me information about the types defined in my spec.yaml
|
|
223
|
-
```
|
|
179
|
+
### Deep Dive on Rules
|
|
224
180
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
What languages does Type Crafter support?
|
|
228
|
-
```
|
|
181
|
+
```
|
|
182
|
+
User: "How do I make a field nullable?"
|
|
229
183
|
|
|
230
|
-
|
|
184
|
+
LLM: [Calls get-rules-section with section: "nullable"]
|
|
185
|
+
LLM: "In Type Crafter, nullability is controlled by the required array..."
|
|
186
|
+
```
|
|
231
187
|
|
|
232
|
-
|
|
188
|
+
## YAML Quick Reference
|
|
233
189
|
|
|
234
190
|
```yaml
|
|
235
191
|
info:
|
|
236
|
-
version:
|
|
237
|
-
title:
|
|
192
|
+
version: '1.0.0'
|
|
193
|
+
title: 'My Types'
|
|
238
194
|
|
|
239
195
|
types:
|
|
240
|
-
|
|
196
|
+
User:
|
|
241
197
|
type: object
|
|
198
|
+
required:
|
|
199
|
+
- id # Required → string
|
|
200
|
+
- email # Required → string
|
|
242
201
|
properties:
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
groupedTypes:
|
|
247
|
-
GroupName:
|
|
248
|
-
TypeInGroup:
|
|
249
|
-
type: object
|
|
250
|
-
properties:
|
|
251
|
-
id:
|
|
252
|
-
type: string
|
|
253
|
-
```
|
|
254
|
-
|
|
255
|
-
For more details on the specification format, see the [main Type Crafter README](../README.md).
|
|
256
|
-
|
|
257
|
-
## Development
|
|
258
|
-
|
|
259
|
-
### Build
|
|
260
|
-
|
|
261
|
-
```bash
|
|
262
|
-
npm run build
|
|
202
|
+
id: { type: string }
|
|
203
|
+
email: { type: string }
|
|
204
|
+
name: { type: string } # Not in required → string | null
|
|
263
205
|
```
|
|
264
206
|
|
|
265
|
-
|
|
207
|
+
**Key Rules:**
|
|
266
208
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
209
|
+
- `nullable: true` does NOT exist - use `required` array
|
|
210
|
+
- `optional: true` does NOT exist - use `required` array
|
|
211
|
+
- Arrays cannot be top-level types
|
|
212
|
+
- Paths are from project root, not relative to current file
|
|
270
213
|
|
|
271
214
|
## Development
|
|
272
215
|
|
|
273
|
-
### Building from Source
|
|
274
|
-
|
|
275
216
|
```bash
|
|
217
|
+
# Build
|
|
276
218
|
npm run build
|
|
277
|
-
```
|
|
278
|
-
|
|
279
|
-
### Watch Mode
|
|
280
219
|
|
|
281
|
-
|
|
220
|
+
# Watch mode
|
|
282
221
|
npm run dev
|
|
283
|
-
```
|
|
284
|
-
|
|
285
|
-
### Linting
|
|
286
222
|
|
|
287
|
-
|
|
223
|
+
# Lint
|
|
288
224
|
npm run lint
|
|
289
|
-
npm run lint:fix
|
|
290
|
-
```
|
|
291
|
-
|
|
292
|
-
## Testing the Package Locally
|
|
293
|
-
|
|
294
|
-
Before publishing or to test the installed package:
|
|
295
|
-
|
|
296
|
-
```bash
|
|
297
|
-
# Create a tarball
|
|
298
|
-
npm pack
|
|
299
|
-
|
|
300
|
-
# Install globally from tarball
|
|
301
|
-
npm install -g ./type-crafter-mcp-server-0.1.0.tgz
|
|
302
|
-
|
|
303
|
-
# Test it
|
|
304
|
-
type-crafter-mcp
|
|
305
225
|
```
|
|
306
226
|
|
|
307
|
-
See [PUBLISHING.md](./PUBLISHING.md) for detailed publishing instructions.
|
|
308
|
-
|
|
309
|
-
## Troubleshooting
|
|
310
|
-
|
|
311
|
-
### Server not connecting
|
|
312
|
-
|
|
313
|
-
- **Global installation:** Ensure `type-crafter-mcp` is in your PATH
|
|
314
|
-
- **Local installation:** Verify the path in your configuration is correct
|
|
315
|
-
- Check that the server was built successfully (`npm run build`)
|
|
316
|
-
- Restart Claude Desktop after modifying the configuration
|
|
317
|
-
- Check Node.js version (requires >= 18.0.0)
|
|
318
|
-
|
|
319
|
-
### Type generation errors
|
|
320
|
-
|
|
321
|
-
- Ensure `type-crafter` CLI is installed: `npm install -g type-crafter`
|
|
322
|
-
- Validate your YAML specification using the `validate-spec` tool
|
|
323
|
-
- Check that all file paths are absolute or relative to your working directory
|
|
324
|
-
- Ensure the output directory exists or the server has permissions to create it
|
|
325
|
-
|
|
326
|
-
### Permission denied error
|
|
327
|
-
|
|
328
|
-
- For global installation, you may need sudo: `sudo npm install -g @type-crafter/mcp-server`
|
|
329
|
-
- Or configure npm to install global packages in your home directory
|
|
330
|
-
|
|
331
|
-
## Contributing
|
|
332
|
-
|
|
333
|
-
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
334
|
-
|
|
335
227
|
## License
|
|
336
228
|
|
|
337
|
-
ISC
|
|
229
|
+
ISC
|