@macroforge/mcp-server 0.1.36 → 0.1.38

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.
@@ -8,18 +8,10 @@ including circular references.
8
8
 
9
9
  | Type | Generated Code | Description |
10
10
  |------|----------------|-------------|
11
- | Class | `toStringifiedJSON()`, `toObject()`, `__serialize(ctx)` | Instance methods |
12
- | Enum | `toStringifiedJSONEnumName(value)`, `__serializeEnumName` | Standalone functions |
13
- | Interface | `toStringifiedJSONInterfaceName(value)`, etc. | Standalone functions |
14
- | Type Alias | `toStringifiedJSONTypeName(value)`, etc. | Standalone functions |
15
-
16
- ## Configuration
17
-
18
- The `functionNamingStyle` option in `macroforge.json` controls naming:
19
- - `"suffix"` (default): Suffixes with type name (e.g., `toStringifiedJSONMyType`)
20
- - `"prefix"`: Prefixes with type name (e.g., `myTypeToStringifiedJSON`)
21
- - `"generic"`: Uses TypeScript generics (e.g., `toStringifiedJSON<T extends MyType>`)
22
- - `"namespace"`: Legacy namespace wrapping
11
+ | Class | `classNameSerialize(value)` + `static serialize(value)` | Standalone function + static wrapper method |
12
+ | Enum | `enumNameSerialize(value)`, `enumNameSerializeWithContext` | Standalone functions |
13
+ | Interface | `interfaceNameSerialize(value)`, etc. | Standalone functions |
14
+ | Type Alias | `typeNameSerialize(value)`, etc. | Standalone functions |
23
15
 
24
16
  ## Cycle Detection Protocol
25
17
 
@@ -45,11 +37,11 @@ When an object is serialized:
45
37
  |------|------------------------|
46
38
  | Primitives | Direct value |
47
39
  | `Date` | `toISOString()` |
48
- | Arrays | For primitive-like element types, pass through; for `Date`/`Date | null`, map to ISO strings; otherwise map and call `__serialize(ctx)` when available |
49
- | `Map<K,V>` | For primitive-like values, `Object.fromEntries(map.entries())`; for `Date`/`Date | null`, convert to ISO strings; otherwise call `__serialize(ctx)` per value when available |
40
+ | Arrays | For primitive-like element types, pass through; for `Date`/`Date | null`, map to ISO strings; otherwise map and call `SerializeWithContext(ctx)` when available |
41
+ | `Map<K,V>` | For primitive-like values, `Object.fromEntries(map.entries())`; for `Date`/`Date | null`, convert to ISO strings; otherwise call `SerializeWithContext(ctx)` per value when available |
50
42
  | `Set<T>` | Convert to array; element handling matches `Array<T>` |
51
- | Nullable | Include `null` explicitly; for primitive-like and `Date` unions the generator avoids runtime `__serialize` checks |
52
- | Objects | Call `__serialize(ctx)` if available (to support user-defined implementations) |
43
+ | Nullable | Include `null` explicitly; for primitive-like and `Date` unions the generator avoids runtime `SerializeWithContext` checks |
44
+ | Objects | Call `SerializeWithContext(ctx)` if available (to support user-defined implementations) |
53
45
 
54
46
  Note: the generator specializes some code paths based on the declared TypeScript type to
55
47
  avoid runtime feature detection on primitives and literal unions.
@@ -58,34 +50,144 @@ avoid runtime feature detection on primitives and literal unions.
58
50
 
59
51
  The `@serde` decorator supports:
60
52
 
61
- - `skip` / `skip_serializing` - Exclude field from serialization
53
+ - `skip` / `skipSerializing` - Exclude field from serialization
62
54
  - `rename = "jsonKey"` - Use different JSON property name
63
55
  - `flatten` - Merge nested object's fields into parent
64
56
 
65
57
  ## Example
66
58
 
67
- ```typescript
68
- @derive(Serialize)
59
+ ```typescript before
60
+ /** @derive(Serialize) */
69
61
  class User {
70
62
  id: number;
71
63
 
72
- @serde(rename = "userName")
64
+ /** @serde({ rename: "userName" }) */
73
65
  name: string;
74
66
 
75
- @serde(skip_serializing)
67
+ /** @serde({ skipSerializing: true }) */
76
68
  password: string;
77
69
 
78
- @serde(flatten)
70
+ /** @serde({ flatten: true }) */
79
71
  metadata: UserMetadata;
80
72
  }
73
+ ```
74
+
75
+ ```typescript after
76
+ import { SerializeContext } from 'macroforge/serde';
77
+
78
+ class User {
79
+ id: number;
81
80
 
82
- // Usage:
83
- const user = new User();
84
- const json = user.toStringifiedJSON();
85
- // => '{"__type":"User","__id":1,"id":1,"userName":"Alice",...}'
81
+ name: string;
82
+
83
+ password: string;
84
+
85
+ metadata: UserMetadata;
86
+ /** Serializes a value to a JSON string.
87
+ @param value - The value to serialize
88
+ @returns JSON string representation with cycle detection metadata */
89
+
90
+ static serialize(value: User): string {
91
+ return userSerialize(value);
92
+ }
93
+ /** @internal Serializes with an existing context for nested/cyclic object graphs.
94
+ @param value - The value to serialize
95
+ @param ctx - The serialization context */
96
+
97
+ static serializeWithContext(value: User, ctx: SerializeContext): Record<string, unknown> {
98
+ return userSerializeWithContext(value, ctx);
99
+ }
100
+ }
86
101
 
87
- const obj = user.toObject();
88
- // => { __type: "User", __id: 1, id: 1, userName: "Alice", ... }
102
+ /** Serializes a value to a JSON string.
103
+ @param value - The value to serialize
104
+ @returns JSON string representation with cycle detection metadata */ export function userSerialize(
105
+ value: User
106
+ ): string {
107
+ const ctx = SerializeContext.create();
108
+ return JSON.stringify(userSerializeWithContext(value, ctx));
109
+ } /** @internal Serializes with an existing context for nested/cyclic object graphs.
110
+ @param value - The value to serialize
111
+ @param ctx - The serialization context */
112
+ export function userSerializeWithContext(
113
+ value: User,
114
+ ctx: SerializeContext
115
+ ): Record<string, unknown> {
116
+ const existingId = ctx.getId(value);
117
+ if (existingId !== undefined) {
118
+ return { __ref: existingId };
119
+ }
120
+ const __id = ctx.register(value);
121
+ const result: Record<string, unknown> = { __type: 'User', __id };
122
+ result['id'] = value.id;
123
+ result['userName'] = value.name;
124
+ {
125
+ const __flattened = userMetadataSerializeWithContext(value.metadata, ctx);
126
+ const { __type: _, __id: __, ...rest } = __flattened as any;
127
+ Object.assign(result, rest);
128
+ }
129
+ return result;
130
+ }
131
+ ```
132
+
133
+ Generated output:
134
+
135
+ ```typescript
136
+ import { SerializeContext } from 'macroforge/serde';
137
+
138
+ class User {
139
+ id: number;
140
+
141
+ name: string;
142
+
143
+ password: string;
144
+
145
+ metadata: UserMetadata;
146
+ /** Serializes a value to a JSON string.
147
+ @param value - The value to serialize
148
+ @returns JSON string representation with cycle detection metadata */
149
+
150
+ static serialize(value: User): string {
151
+ return userSerialize(value);
152
+ }
153
+ /** @internal Serializes with an existing context for nested/cyclic object graphs.
154
+ @param value - The value to serialize
155
+ @param ctx - The serialization context */
156
+
157
+ static serializeWithContext(value: User, ctx: SerializeContext): Record<string, unknown> {
158
+ return userSerializeWithContext(value, ctx);
159
+ }
160
+ }
161
+
162
+ /** Serializes a value to a JSON string.
163
+ @param value - The value to serialize
164
+ @returns JSON string representation with cycle detection metadata */ export function userSerialize(
165
+ value: User
166
+ ): string {
167
+ const ctx = SerializeContext.create();
168
+ return JSON.stringify(userSerializeWithContext(value, ctx));
169
+ } /** @internal Serializes with an existing context for nested/cyclic object graphs.
170
+ @param value - The value to serialize
171
+ @param ctx - The serialization context */
172
+ export function userSerializeWithContext(
173
+ value: User,
174
+ ctx: SerializeContext
175
+ ): Record<string, unknown> {
176
+ const existingId = ctx.getId(value);
177
+ if (existingId !== undefined) {
178
+ return { __ref: existingId };
179
+ }
180
+ const __id = ctx.register(value);
181
+ const result: Record<string, unknown> = { __type: 'User', __id };
182
+ result['id'] = value.id;
183
+ result['userName'] = value.name;
184
+ {
185
+ const __flattened = userMetadataSerializeWithContext(value.metadata, ctx);
186
+ const { __type: _, __id: __, ...rest } = __flattened as any;
187
+ Object.assign(result, rest);
188
+ }
189
+ return result;
190
+ }
89
191
  ```
90
192
 
91
193
  ## Required Import
@@ -62,57 +62,48 @@ class User {
62
62
  ```
63
63
  **After:**
64
64
  ```
65
- import { SerializeContext } from 'macroforge/serde';
65
+ import { SerializeContext } from "macroforge/serde";
66
66
 
67
67
  class User {
68
- id: number;
69
-
70
- name: string;
68
+
69
+
70
+ id: number;
71
71
 
72
- password: string;
72
+ name: string;
73
73
 
74
- metadata: Record<string, unknown>;
74
+
75
+
76
+ password: string;
75
77
 
76
- toString(): string {
77
- const parts: string[] = [];
78
- parts.push('userId: ' + this.id);
79
- parts.push('name: ' + this.name);
80
- parts.push('metadata: ' + this.metadata);
81
- return 'User { ' + parts.join(', ') + ' }';
82
- }
78
+
79
+ metadata: Record<string, unknown>;
83
80
 
84
- toStringifiedJSON(): string {
85
- const ctx = SerializeContext.create();
86
- return JSON.stringify(this.__serialize(ctx));
87
- }
81
+ static toString(value: User): string {
82
+ return userToString(value);
83
+ }
84
+ /** Serializes a value to a JSON string.
85
+ @param value - The value to serialize
86
+ @returns JSON string representation with cycle detection metadata */
88
87
 
89
- toObject(): Record<string, unknown> {
90
- const ctx = SerializeContext.create();
91
- return this.__serialize(ctx);
92
- }
88
+ static serialize(value: User): string {
89
+ return userSerialize(value);
90
+ }
91
+ /** @internal Serializes with an existing context for nested/cyclic object graphs.
92
+ @param value - The value to serialize
93
+ @param ctx - The serialization context */
93
94
 
94
- __serialize(ctx: SerializeContext): Record<string, unknown> {
95
- const existingId = ctx.getId(this);
96
- if (existingId !== undefined) {
97
- return {
98
- __ref: existingId
99
- };
100
- }
101
- const __id = ctx.register(this);
102
- const result: Record<string, unknown> = {
103
- __type: 'User',
104
- __id
105
- };
106
- result['user_id'] = this.id;
107
- result['name'] = this.name;
108
- {
109
- const __flattened = __serializeRecord<string, unknown>(this.metadata, ctx);
110
- const { __type: _, __id: __, ...rest } = __flattened as any;
111
- Object.assign(result, rest);
112
- }
113
- return result;
114
- }
95
+ static serializeWithContext(value: User, ctx: SerializeContext): Record<string, unknown> {
96
+ return userSerializeWithContext(value, ctx);
97
+ }
115
98
  }
99
+
100
+ export function userToString(value: User): string {const parts: string[]= []; parts.push("userId: " + value.id); parts.push("name: " + value.name); parts.push("metadata: " + value.metadata); return "User { " + parts.join(", " )+ " }" ; }
101
+
102
+ /** Serializes a value to a JSON string.
103
+ @param value - The value to serialize
104
+ @returns JSON string representation with cycle detection metadata */export function userSerialize(value: User): string {const ctx = SerializeContext.create(); return JSON.stringify(userSerializeWithContext(value, ctx));}/** @internal Serializes with an existing context for nested/cyclic object graphs.
105
+ @param value - The value to serialize
106
+ @param ctx - The serialization context */export function userSerializeWithContext(value: User, ctx: SerializeContext): Record<string, unknown>{const existingId = ctx.getId(value); if(existingId!== undefined){return {__ref: existingId};}const __id = ctx.register(value); const result: Record<string, unknown>= {__type: "User" , __id,}; result["user_id" ]= value.id; result["name" ]= value.name; {const __flattened = record<string, unknown>SerializeWithContext(value.metadata, ctx); const {__type: _, __id: __,...rest}= __flattened as any; Object.assign(result, rest);}return result;}
116
107
  ``` Syntax rules:
117
108
  - Must be inside a JSDoc comment immediately before the field
118
109
  - Options use object literal syntax: `@attr({ key: value })`
@@ -18,12 +18,16 @@ class User {
18
18
  class User {
19
19
  name: string;
20
20
 
21
- toString(): string {
22
- const parts: string[] = [];
23
- parts.push('name: ' + this.name);
24
- return 'User { ' + parts.join(', ') + ' }';
21
+ static toString(value: User): string {
22
+ return userToString(value);
25
23
  }
26
24
  }
25
+
26
+ export function userToString(value: User): string {
27
+ const parts: string[] = [];
28
+ parts.push('name: ' + value.name);
29
+ return 'User { ' + parts.join(', ') + ' }';
30
+ }
27
31
  ``` ## Zero Runtime Overhead
28
32
  Because code generation happens at compile time, there's no:
29
33
  - Runtime reflection or metadata
@@ -30,33 +30,39 @@ export class User {
30
30
  this.email = email;
31
31
  }
32
32
 
33
- toString(): string {
34
- const parts: string[] = [];
35
- parts.push('name: ' + this.name);
36
- parts.push('age: ' + this.age);
37
- parts.push('email: ' + this.email);
38
- return 'User { ' + parts.join(', ') + ' }';
33
+ static toString(value: User): string {
34
+ return userToString(value);
39
35
  }
40
36
 
41
- clone(): User {
42
- const cloned = Object.create(Object.getPrototypeOf(this));
43
- cloned.name = this.name;
44
- cloned.age = this.age;
45
- cloned.email = this.email;
46
- return cloned;
37
+ static clone(value: User): User {
38
+ return userClone(value);
47
39
  }
48
40
 
49
- equals(other: unknown): boolean {
50
- if (this === other) return true;
51
- if (!(other instanceof User)) return false;
52
- const typedOther = other as User;
53
- return (
54
- this.name === typedOther.name &&
55
- this.age === typedOther.age &&
56
- this.email === typedOther.email
57
- );
41
+ static equals(a: User, b: User): boolean {
42
+ return userEquals(a, b);
58
43
  }
59
44
  }
45
+
46
+ export function userToString(value: User): string {
47
+ const parts: string[] = [];
48
+ parts.push('name: ' + value.name);
49
+ parts.push('age: ' + value.age);
50
+ parts.push('email: ' + value.email);
51
+ return 'User { ' + parts.join(', ') + ' }';
52
+ }
53
+
54
+ export function userClone(value: User): User {
55
+ const cloned = Object.create(Object.getPrototypeOf(value));
56
+ cloned.name = value.name;
57
+ cloned.age = value.age;
58
+ cloned.email = value.email;
59
+ return cloned;
60
+ }
61
+
62
+ export function userEquals(a: User, b: User): boolean {
63
+ if (a === b) return true;
64
+ return a.name === b.name && a.age === b.age && a.email === b.email;
65
+ }
60
66
  ``` ## Using the Generated Methods
61
67
  ```
62
68
  const user = new User("Alice", 30, "alice@example.com");
@@ -110,13 +116,17 @@ export class User {
110
116
  this.password = password;
111
117
  }
112
118
 
113
- toString(): string {
114
- const parts: string[] = [];
115
- parts.push('userId: ' + this.id);
116
- parts.push('name: ' + this.name);
117
- return 'User { ' + parts.join(', ') + ' }';
119
+ static toString(value: User): string {
120
+ return userToString(value);
118
121
  }
119
122
  }
123
+
124
+ export function userToString(value: User): string {
125
+ const parts: string[] = [];
126
+ parts.push('userId: ' + value.id);
127
+ parts.push('name: ' + value.name);
128
+ return 'User { ' + parts.join(', ') + ' }';
129
+ }
120
130
  ``` ```
121
131
  const user = new User(42, "Alice", "secret123");
122
132
  console.log(user.toString());
@@ -103,13 +103,91 @@
103
103
  "path": "builtin-macros/partial-ord.md",
104
104
  "use_cases": "compareTo, partial ordering, sorting, nullable comparison"
105
105
  },
106
+ {
107
+ "id": "serialize/overview",
108
+ "title": "Serialize: Overview",
109
+ "category": "builtin-macros",
110
+ "category_title": "Built-in Macros",
111
+ "path": "builtin-macros/serialize/overview.md",
112
+ "use_cases": "toJSON, serialization, serialize, classnameserialize(value), enumnameserialize(value), enumnameserializewithcontext",
113
+ "parent_id": "serialize"
114
+ },
115
+ {
116
+ "id": "serialize/type-specific-serialization",
117
+ "title": "Serialize: Type-Specific Serialization",
118
+ "category": "builtin-macros",
119
+ "category_title": "Built-in Macros",
120
+ "path": "builtin-macros/serialize/type-specific-serialization.md",
121
+ "use_cases": "toJSON, serialization, date, toisostring(), serializewithcontext(ctx)",
122
+ "parent_id": "serialize"
123
+ },
124
+ {
125
+ "id": "serialize/example",
126
+ "title": "Serialize: Example",
127
+ "category": "builtin-macros",
128
+ "category_title": "Built-in Macros",
129
+ "path": "builtin-macros/serialize/example.md",
130
+ "use_cases": "toJSON, serialization",
131
+ "parent_id": "serialize"
132
+ },
106
133
  {
107
134
  "id": "serialize",
108
135
  "title": "Serialize",
109
136
  "category": "builtin-macros",
110
137
  "category_title": "Built-in Macros",
111
138
  "path": "builtin-macros/serialize.md",
112
- "use_cases": "toJSON, serialization, json, api, data transfer"
139
+ "use_cases": "toJSON, serialization, json, api, data transfer",
140
+ "is_chunked": true,
141
+ "chunk_ids": [
142
+ "serialize/overview",
143
+ "serialize/type-specific-serialization",
144
+ "serialize/example"
145
+ ]
146
+ },
147
+ {
148
+ "id": "deserialize/overview",
149
+ "title": "Deserialize: Overview",
150
+ "category": "builtin-macros",
151
+ "category_title": "Built-in Macros",
152
+ "path": "builtin-macros/deserialize/overview.md",
153
+ "use_cases": "fromJSON, deserialization, deserialize, classnamedeserialize(input), enumnamedeserialize(input)",
154
+ "parent_id": "deserialize"
155
+ },
156
+ {
157
+ "id": "deserialize/cycleforward-reference-support",
158
+ "title": "Deserialize: Cycle/Forward-Reference Support",
159
+ "category": "builtin-macros",
160
+ "category_title": "Built-in Macros",
161
+ "path": "builtin-macros/deserialize/cycleforward-reference-support.md",
162
+ "use_cases": "fromJSON, deserialization, pendingref, ctx.applypatches(), __ref",
163
+ "parent_id": "deserialize"
164
+ },
165
+ {
166
+ "id": "deserialize/validation",
167
+ "title": "Deserialize: Validation",
168
+ "category": "builtin-macros",
169
+ "category_title": "Built-in Macros",
170
+ "path": "builtin-macros/deserialize/validation.md",
171
+ "use_cases": "fromJSON, deserialization, @serde(validate(...)), email, url, uuid",
172
+ "parent_id": "deserialize"
173
+ },
174
+ {
175
+ "id": "deserialize/union-type-deserialization",
176
+ "title": "Deserialize: Union Type Deserialization",
177
+ "category": "builtin-macros",
178
+ "category_title": "Built-in Macros",
179
+ "path": "builtin-macros/deserialize/union-type-deserialization.md",
180
+ "use_cases": "fromJSON, deserialization, typeof, __type",
181
+ "parent_id": "deserialize"
182
+ },
183
+ {
184
+ "id": "deserialize/example",
185
+ "title": "Deserialize: Example",
186
+ "category": "builtin-macros",
187
+ "category_title": "Built-in Macros",
188
+ "path": "builtin-macros/deserialize/example.md",
189
+ "use_cases": "fromJSON, deserialization",
190
+ "parent_id": "deserialize"
113
191
  },
114
192
  {
115
193
  "id": "deserialize",
@@ -117,7 +195,15 @@
117
195
  "category": "builtin-macros",
118
196
  "category_title": "Built-in Macros",
119
197
  "path": "builtin-macros/deserialize.md",
120
- "use_cases": "fromJSON, deserialization, parsing, validation, json"
198
+ "use_cases": "fromJSON, deserialization, parsing, validation, json",
199
+ "is_chunked": true,
200
+ "chunk_ids": [
201
+ "deserialize/overview",
202
+ "deserialize/cycleforward-reference-support",
203
+ "deserialize/validation",
204
+ "deserialize/union-type-deserialization",
205
+ "deserialize/example"
206
+ ]
121
207
  },
122
208
  {
123
209
  "id": "custom-overview",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@macroforge/mcp-server",
3
- "version": "0.1.36",
3
+ "version": "0.1.38",
4
4
  "description": "MCP server for Macroforge documentation and code analysis",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -29,7 +29,7 @@
29
29
  "typescript": "^5.7.0"
30
30
  },
31
31
  "peerDependencies": {
32
- "macroforge": "^0.1.36"
32
+ "macroforge": "^0.1.38"
33
33
  },
34
34
  "peerDependenciesMeta": {
35
35
  "macroforge": {