@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 CHANGED
@@ -1,162 +1,134 @@
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
+ ## What This MCP Does
9
9
 
10
- The MCP server exposes the following tools:
10
+ This MCP server helps LLMs:
11
11
 
12
- ### 1. `generate-types`
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
- Generate type definitions from a YAML specification file.
16
+ Type generation is handled by the `type-crafter` CLI in your project.
15
17
 
16
- **Parameters:**
18
+ ## Tools
17
19
 
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`)
20
+ ### 1. `get-writing-guide`
23
21
 
24
- **Example:**
22
+ **CALL THIS FIRST** - Returns the writing guide and a sessionId.
25
23
 
26
- ```json
27
- {
28
- "language": "typescript",
29
- "specFilePath": "./types.yaml",
30
- "outputDirectory": "./generated-types",
31
- "typesWriterMode": "SingleFile",
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. `validate-spec`
32
+ ### 2. `get-rules-section`
37
33
 
38
- Validate a YAML specification file without generating types.
34
+ Get detailed rules for a specific topic.
39
35
 
40
36
  **Parameters:**
41
37
 
42
- - `specFilePath` (required): Path to the YAML specification file to validate
43
-
44
- **Example:**
45
-
46
- ```json
47
- {
48
- "specFilePath": "./types.yaml"
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
- List all supported target languages for type generation.
47
+ ### 3. `validate-spec`
55
48
 
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.
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
- **Example:**
67
-
68
- ```json
69
- {
70
- "specFilePath": "./types.yaml"
71
- }
72
- ```
56
+ **Checks:**
73
57
 
74
- ### 5. `get-spec-rules`
58
+ - Structure (info, types, groupedTypes)
59
+ - Common mistakes (nullable, optional, wrong paths)
60
+ - Top-file vs non-top-file reference rules
75
61
 
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.
62
+ ### 4. `get-spec-info`
77
63
 
78
- **Parameters:** None
64
+ Get information about an existing spec file.
79
65
 
80
- **Use this tool when:**
66
+ **Parameters:**
81
67
 
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
68
+ - `specFilePath` (required): Path to the YAML specification file
86
69
 
87
- **Returns:** Complete specification rules documentation including:
70
+ **Returns:**
88
71
 
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
72
+ - Version and title
73
+ - List of all types
74
+ - List of all grouped types
97
75
 
98
- ## Prerequisites
76
+ ### 5. `list-languages`
99
77
 
100
- - Node.js >= 18.0.0
101
- - `type-crafter` CLI installed globally or locally
78
+ List supported languages for the type-crafter CLI.
102
79
 
103
- Install Type Crafter CLI:
80
+ ## Recommended Workflow
104
81
 
105
- ```bash
106
- npm install -g type-crafter
107
82
  ```
108
-
109
- ## Installation
110
-
111
- ### Option 1: Install from npm (Recommended)
112
-
113
- Install the MCP server globally:
114
-
115
- ```bash
116
- npm install -g @type-crafter/mcp-server
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
- Or install locally in your project:
94
+ ## Session Enforcement
120
95
 
121
- ```bash
122
- npm install @type-crafter/mcp-server
123
- ```
96
+ The MCP uses sessions to encourage reading the guide first:
124
97
 
125
- ### Option 2: Install from Source
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
- 1. Clone the repository:
103
+ ## Installation
128
104
 
129
- ```bash
130
- git clone https://github.com/sinha-sahil/type-crafter.git
131
- cd type-crafter/mcp-server
132
- ```
105
+ ### Prerequisites
133
106
 
134
- 2. Install dependencies:
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
- 3. Build the server:
116
+ ### Install MCP Server
141
117
 
142
118
  ```bash
143
- npm run build
119
+ npm install -g @type-crafter/mcp-server
144
120
  ```
145
121
 
146
122
  ## Configuration
147
123
 
148
- ### Using with Claude Desktop (Global Installation)
124
+ ### Claude Desktop
149
125
 
150
- After installing globally via npm:
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
- **For local installation (from source):**
142
+ ### From Source
171
143
 
172
144
  ```json
173
145
  {
174
146
  "mcpServers": {
175
147
  "type-crafter": {
176
148
  "command": "node",
177
- "args": ["/absolute/path/to/type-crafter/mcp-server/dist/index.js"]
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
- Once configured, you can use the MCP server through Claude Desktop:
200
-
201
- 1. **Get specification rules (before writing specs):**
157
+ ### Learning the Format
202
158
 
203
- ```
204
- Show me the rules for writing Type Crafter YAML specification files
205
- ```
206
-
207
- 2. **Generate TypeScript types:**
159
+ ```
160
+ User: "I need to create types for a user API"
208
161
 
209
- ```
210
- Generate TypeScript types from my spec.yaml file and save them to ./types
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
- 3. **Validate a specification:**
168
+ ### Validating Existing Spec
214
169
 
215
- ```
216
- Validate my types.yaml specification file
217
- ```
170
+ ```
171
+ User: "Check if my types.yaml is valid"
218
172
 
219
- 4. **Get spec information:**
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
- 5. **List available languages:**
226
- ```
227
- What languages does Type Crafter support?
228
- ```
181
+ ```
182
+ User: "How do I make a field nullable?"
229
183
 
230
- ## YAML Specification Format
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
- The YAML specification should follow this structure:
188
+ ## YAML Quick Reference
233
189
 
234
190
  ```yaml
235
191
  info:
236
- version: 0.0.0
237
- title: Title of your specification
192
+ version: '1.0.0'
193
+ title: 'My Types'
238
194
 
239
195
  types:
240
- TypeName:
196
+ User:
241
197
  type: object
198
+ required:
199
+ - id # Required → string
200
+ - email # Required → string
242
201
  properties:
243
- propertyName:
244
- type: string
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
- ### Watch mode
207
+ **Key Rules:**
266
208
 
267
- ```bash
268
- npm run dev
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
- ```bash
220
+ # Watch mode
282
221
  npm run dev
283
- ```
284
-
285
- ### Linting
286
222
 
287
- ```bash
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 - See [LICENSE](./LICENSE) file for details
229
+ ISC