@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.
Files changed (2) hide show
  1. package/README.md +192 -116
  2. 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
  [![npm version](https://badge.fury.io/js/@type-crafter%2Fmcp-server.svg)](https://www.npmjs.com/package/@type-crafter/mcp-server)
6
6
  [![License: ISC](https://img.shields.io/badge/License-ISC-blue.svg)](https://opensource.org/licenses/ISC)
7
7
 
8
- ## What This MCP Does
8
+ ## Why This MCP?
9
9
 
10
- This MCP server helps LLMs:
10
+ LLMs often make mistakes when writing Type Crafter YAML specs:
11
11
 
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)
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
- Type generation is handled by the `type-crafter` CLI in your project.
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
- **CALL THIS FIRST** - Returns the writing guide and a sessionId.
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
- **Parameters:**
37
-
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
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 file for correctness.
50
-
51
- **Parameters:**
97
+ Validate a YAML spec for correctness.
52
98
 
53
- - `sessionId` (optional): Session ID from get-writing-guide
54
- - `specFilePath` (required): Path to the YAML specification file
55
-
56
- **Checks:**
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
- - Top-file vs non-top-file reference rules
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
- **Parameters:**
67
-
68
- - `specFilePath` (required): Path to the YAML specification file
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 the type-crafter CLI.
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
- ## Recommended Workflow
136
+ ## Workflow
81
137
 
82
138
  ```
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
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
- ## Installation
104
-
105
- ### Prerequisites
164
+ ## YAML Quick Reference
106
165
 
107
- - Node.js >= 18.0.0
108
- - `type-crafter` CLI installed in your project
166
+ ```yaml
167
+ info:
168
+ version: '1.0.0'
169
+ title: 'My Types'
109
170
 
110
- ```bash
111
- npm install -g type-crafter
112
- # or locally
113
- npm install type-crafter
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
- ### Install MCP Server
183
+ **Generated TypeScript:**
117
184
 
118
- ```bash
119
- npm install -g @type-crafter/mcp-server
185
+ ```typescript
186
+ export type User = {
187
+ id: string;
188
+ email: string;
189
+ name: string | null;
190
+ };
120
191
  ```
121
192
 
122
- ## Configuration
193
+ ## Key Rules
123
194
 
124
- ### Claude Desktop
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
- Edit your Claude Desktop config:
204
+ ## Usage Examples
127
205
 
128
- **macOS:** `~/Library/Application Support/Claude/claude_desktop_config.json`
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
- ### From Source
143
-
144
- ```json
145
- {
146
- "mcpServers": {
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
- ## Usage Examples
156
-
157
- ### Learning the Format
218
+ ### Validating Specs
158
219
 
159
220
  ```
160
- User: "I need to create types for a user API"
221
+ User: "Check if my types.yaml is valid"
161
222
 
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]
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
- ### Validating Existing Spec
229
+ ### Learning Specific Rules
169
230
 
170
231
  ```
171
- User: "Check if my types.yaml is valid"
232
+ User: "How do references work in Type Crafter?"
172
233
 
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..."
234
+ LLM: [Calls get-rules-section with section: "references"]
235
+ "References in Type Crafter work like this..."
177
236
  ```
178
237
 
179
- ### Deep Dive on Rules
238
+ ## Troubleshooting
180
239
 
181
- ```
182
- User: "How do I make a field nullable?"
240
+ ### "nullable: true" errors
241
+
242
+ Type Crafter doesn't have a `nullable` property. Use the `required` array:
183
243
 
184
- LLM: [Calls get-rules-section with section: "nullable"]
185
- LLM: "In Type Crafter, nullability is controlled by the required array..."
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
- ## YAML Quick Reference
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
- info:
192
- version: '1.0.0'
193
- title: 'My Types'
261
+ # Wrong
262
+ $ref: '../common/types.yaml#/User'
194
263
 
195
- types:
196
- User:
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
- **Key Rules:**
268
+ ### "Arrays cannot be top-level types"
208
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
+ 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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@type-crafter/mcp",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "MCP server for Type Crafter - generate types from YAML specifications",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",