@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 CHANGED
@@ -1,323 +1,305 @@
1
1
  # Type Crafter MCP Server
2
2
 
3
- An MCP (Model Context Protocol) server for Type Crafter that allows AI assistants to generate type definitions from YAML specifications.
3
+ An MCP (Model Context Protocol) server that helps AI assistants write correct Type Crafter YAML specifications.
4
4
 
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
- ## Features
8
+ ## Why This MCP?
9
9
 
10
- The MCP server exposes the following tools:
10
+ LLMs often make mistakes when writing Type Crafter YAML specs:
11
11
 
12
- ### 1. `generate-types`
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
- Generate type definitions from a YAML specification file.
20
+ This MCP **teaches** LLMs the correct format and **validates** specs before generation.
15
21
 
16
- **Parameters:**
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
- **Example:**
24
+ ```bash
25
+ # Install MCP server
26
+ npm install -g @type-crafter/mcp-server
25
27
 
26
- ```json
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
- ### 2. `validate-spec`
37
-
38
- Validate a YAML specification file without generating types.
32
+ ## Configuration
39
33
 
40
- **Parameters:**
34
+ ### Claude Desktop
41
35
 
42
- - `specFilePath` (required): Path to the YAML specification file to validate
36
+ **macOS:** `~/Library/Application Support/Claude/claude_desktop_config.json`
43
37
 
44
- **Example:**
38
+ **Windows:** `%APPDATA%\Claude\claude_desktop_config.json`
45
39
 
46
40
  ```json
47
41
  {
48
- "specFilePath": "./types.yaml"
42
+ "mcpServers": {
43
+ "type-crafter": {
44
+ "command": "type-crafter-mcp"
45
+ }
46
+ }
49
47
  }
50
48
  ```
51
49
 
52
- ### 3. `list-languages`
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
- "specFilePath": "./types.yaml"
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
- ### 5. `get-spec-rules`
63
+ ## Tools
75
64
 
76
- Get comprehensive rules and guidelines for writing Type Crafter YAML specification files. This tool provides LLMs with detailed information about the YAML spec format, type mappings, nullable types, references, composition, best practices, and common patterns.
65
+ ### 1. `get-writing-guide`
77
66
 
78
- **Parameters:** None
67
+ **Call this FIRST.** Returns the writing guide and a sessionId.
79
68
 
80
- **Use this tool when:**
69
+ ```
70
+ Parameters: none
81
71
 
82
- - You need to create a new YAML specification file
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
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
- **Returns:** Complete specification rules documentation including:
79
+ ### 2. `get-rules-section`
88
80
 
89
- - Root structure requirements
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
- ## Prerequisites
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
- - Node.js >= 18.0.0
101
- - `type-crafter` CLI installed globally or locally
95
+ ### 3. `validate-spec`
102
96
 
103
- Install Type Crafter CLI:
97
+ Validate a YAML spec for correctness.
104
98
 
105
- ```bash
106
- npm install -g type-crafter
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
- ## Installation
110
-
111
- ### Option 1: Install from npm (Recommended)
110
+ ### 4. `get-spec-info`
112
111
 
113
- Install the MCP server globally:
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
- Or install locally in your project:
120
-
121
- ```bash
122
- npm install @type-crafter/mcp-server
118
+ Returns:
119
+ - Version and title
120
+ - List of all types
121
+ - List of all grouped types
123
122
  ```
124
123
 
125
- ### Option 2: Install from Source
124
+ ### 5. `list-languages`
126
125
 
127
- 1. Clone the repository:
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
- 2. Install dependencies:
135
-
136
- ```bash
137
- npm install
131
+ Returns:
132
+ - typescript
133
+ - typescript-with-decoders
138
134
  ```
139
135
 
140
- 3. Build the server:
136
+ ## Workflow
141
137
 
142
- ```bash
143
- npm run build
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
- ## Configuration
147
-
148
- ### Using with Claude Desktop (Global Installation)
149
-
150
- After installing globally via npm:
155
+ ## Session Enforcement
151
156
 
152
- Edit your Claude Desktop configuration file:
157
+ The MCP uses sessions to encourage reading the guide first:
153
158
 
154
- **macOS:** `~/Library/Application Support/Claude/claude_desktop_config.json`
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
- **Windows:** `%APPDATA%\Claude\claude_desktop_config.json`
164
+ ## YAML Quick Reference
157
165
 
158
- **For global installation:**
166
+ ```yaml
167
+ info:
168
+ version: '1.0.0'
169
+ title: 'My Types'
159
170
 
160
- ```json
161
- {
162
- "mcpServers": {
163
- "type-crafter": {
164
- "command": "type-crafter-mcp"
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
- **For local installation (from source):**
183
+ **Generated TypeScript:**
171
184
 
172
- ```json
173
- {
174
- "mcpServers": {
175
- "type-crafter": {
176
- "command": "node",
177
- "args": ["/absolute/path/to/type-crafter/mcp-server/dist/index.js"]
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
- **For project-local npm installation:**
193
+ ## Key Rules
184
194
 
185
- ```json
186
- {
187
- "mcpServers": {
188
- "type-crafter": {
189
- "command": "npx",
190
- "args": ["type-crafter-mcp"],
191
- "cwd": "/path/to/your/project"
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
- Once configured, you can use the MCP server through Claude Desktop:
206
+ ### Creating Types
200
207
 
201
- 1. **Get specification rules (before writing specs):**
208
+ ```
209
+ User: "Create types for a user API with id, email, and optional name"
202
210
 
203
- ```
204
- Show me the rules for writing Type Crafter YAML specification files
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
- 2. **Generate TypeScript types:**
218
+ ### Validating Specs
208
219
 
209
- ```
210
- Generate TypeScript types from my spec.yaml file and save them to ./types
211
- ```
220
+ ```
221
+ User: "Check if my types.yaml is valid"
212
222
 
213
- 3. **Validate a specification:**
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
- 4. **Get spec information:**
231
+ ```
232
+ User: "How do references work in Type Crafter?"
220
233
 
221
- ```
222
- Show me information about the types defined in my spec.yaml
223
- ```
234
+ LLM: [Calls get-rules-section with section: "references"]
235
+ "References in Type Crafter work like this..."
236
+ ```
224
237
 
225
- 5. **List available languages:**
226
- ```
227
- What languages does Type Crafter support?
228
- ```
238
+ ## Troubleshooting
229
239
 
230
- ## YAML Specification Format
240
+ ### "nullable: true" errors
231
241
 
232
- The YAML specification should follow this structure:
242
+ Type Crafter doesn't have a `nullable` property. Use the `required` array:
233
243
 
234
244
  ```yaml
235
- info:
236
- version: 0.0.0
237
- title: Title of your specification
238
-
239
- types:
240
- TypeName:
241
- type: object
242
- properties:
243
- propertyName:
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
- For more details on the specification format, see the [main Type Crafter README](../README.md).
256
+ ### Reference path errors
256
257
 
257
- ## Development
258
+ All paths are from project root (where you run the CLI), not relative to current file:
258
259
 
259
- ### Build
260
+ ```yaml
261
+ # Wrong
262
+ $ref: '../common/types.yaml#/User'
260
263
 
261
- ```bash
262
- npm run build
264
+ # Correct
265
+ $ref: './src/common/types.yaml#/User'
263
266
  ```
264
267
 
265
- ### Watch mode
266
-
267
- ```bash
268
- npm run dev
269
- ```
268
+ ### "Arrays cannot be top-level types"
270
269
 
271
- ### Linting
270
+ Arrays must be properties within objects:
272
271
 
273
- ```bash
274
- npm run lint
275
- npm run lint:fix
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
- ## Testing the Package Locally
279
-
280
- Before publishing or to test the installed package:
287
+ ## Development
281
288
 
282
289
  ```bash
283
- # Create a tarball
284
- npm pack
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
- - For global installation, you may need sudo: `sudo npm install -g @type-crafter/mcp-server`
315
- - Or configure npm to install global packages in your home directory
293
+ # Build
294
+ npm run build
316
295
 
317
- ## Contributing
296
+ # Watch mode
297
+ npm run dev
318
298
 
319
- Contributions are welcome! Please feel free to submit a Pull Request.
299
+ # Lint
300
+ npm run lint
301
+ ```
320
302
 
321
303
  ## License
322
304
 
323
- ISC - See [LICENSE](./LICENSE) file for details
305
+ ISC