@nestia/sdk 12.0.0-dev.20260601.1 → 12.0.0-dev.20260612.2

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 (209) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +93 -93
  3. package/assets/bundle/api/HttpError.ts +1 -1
  4. package/assets/bundle/api/IConnection.ts +1 -1
  5. package/assets/bundle/api/Primitive.ts +1 -1
  6. package/assets/bundle/api/Resolved.ts +1 -1
  7. package/assets/bundle/api/index.ts +4 -4
  8. package/assets/bundle/api/module.ts +6 -6
  9. package/assets/bundle/distribute/README.md +37 -37
  10. package/assets/bundle/distribute/package.json +28 -28
  11. package/assets/bundle/distribute/tsconfig.json +109 -109
  12. package/assets/bundle/e2e/index.ts +42 -42
  13. package/assets/config/nestia.config.ts +97 -97
  14. package/lib/NestiaSdkApplication.js +29 -7
  15. package/lib/NestiaSdkApplication.js.map +1 -1
  16. package/lib/NestiaSwaggerComposer.js +21 -13
  17. package/lib/NestiaSwaggerComposer.js.map +1 -1
  18. package/lib/analyses/AccessorAnalyzer.d.ts +4 -1
  19. package/lib/analyses/AccessorAnalyzer.js.map +1 -1
  20. package/lib/analyses/ConfigAnalyzer.js +1 -1
  21. package/lib/analyses/PathAnalyzer.d.ts +18 -3
  22. package/lib/analyses/PathAnalyzer.js +32 -0
  23. package/lib/analyses/PathAnalyzer.js.map +1 -1
  24. package/lib/analyses/ReflectControllerAnalyzer.js +3 -2
  25. package/lib/analyses/ReflectControllerAnalyzer.js.map +1 -1
  26. package/lib/analyses/ReflectHttpOperationAnalyzer.d.ts +1 -1
  27. package/lib/analyses/ReflectHttpOperationAnalyzer.js +1 -1
  28. package/lib/analyses/ReflectHttpOperationAnalyzer.js.map +1 -1
  29. package/lib/analyses/ReflectHttpOperationResponseAnalyzer.d.ts +1 -1
  30. package/lib/analyses/ReflectHttpOperationResponseAnalyzer.js +53 -20
  31. package/lib/analyses/ReflectHttpOperationResponseAnalyzer.js.map +1 -1
  32. package/lib/analyses/ReflectMcpOperationAnalyzer.d.ts +14 -0
  33. package/lib/analyses/ReflectMcpOperationAnalyzer.js +79 -0
  34. package/lib/analyses/ReflectMcpOperationAnalyzer.js.map +1 -0
  35. package/lib/analyses/TypedMcpRouteAnalyzer.d.ts +9 -0
  36. package/lib/analyses/TypedMcpRouteAnalyzer.js +31 -0
  37. package/lib/analyses/TypedMcpRouteAnalyzer.js.map +1 -0
  38. package/lib/executable/internal/NestiaConfigLoader.js +5 -1
  39. package/lib/executable/internal/NestiaConfigLoader.js.map +1 -1
  40. package/lib/executable/internal/NestiaSdkCommand.js +30 -14
  41. package/lib/executable/internal/NestiaSdkCommand.js.map +1 -1
  42. package/lib/executable/internal/NestiaSdkWatcher.d.ts +10 -0
  43. package/lib/executable/internal/NestiaSdkWatcher.js +322 -0
  44. package/lib/executable/internal/NestiaSdkWatcher.js.map +1 -0
  45. package/lib/executable/sdk.js +12 -12
  46. package/lib/executable/sdk.js.map +1 -1
  47. package/lib/generates/CloneGenerator.js +4 -2
  48. package/lib/generates/CloneGenerator.js.map +1 -1
  49. package/lib/generates/SdkGenerator.js +50 -1
  50. package/lib/generates/SdkGenerator.js.map +1 -1
  51. package/lib/generates/SwaggerGenerator.js +18 -2
  52. package/lib/generates/SwaggerGenerator.js.map +1 -1
  53. package/lib/generates/internal/E2eFileProgrammer.js +3 -1
  54. package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
  55. package/lib/generates/internal/ImportDictionary.d.ts +1 -0
  56. package/lib/generates/internal/ImportDictionary.js +9 -4
  57. package/lib/generates/internal/ImportDictionary.js.map +1 -1
  58. package/lib/generates/internal/SdkAliasCollection.d.ts +2 -0
  59. package/lib/generates/internal/SdkAliasCollection.js +11 -2
  60. package/lib/generates/internal/SdkAliasCollection.js.map +1 -1
  61. package/lib/generates/internal/SdkDistributionComposer.d.ts +1 -0
  62. package/lib/generates/internal/SdkDistributionComposer.js +3 -0
  63. package/lib/generates/internal/SdkDistributionComposer.js.map +1 -1
  64. package/lib/generates/internal/SdkFileProgrammer.js +4 -1
  65. package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
  66. package/lib/generates/internal/SdkHttpCloneReferencer.d.ts +1 -1
  67. package/lib/generates/internal/SdkHttpCloneReferencer.js +42 -9
  68. package/lib/generates/internal/SdkHttpCloneReferencer.js.map +1 -1
  69. package/lib/generates/internal/SdkHttpFunctionProgrammer.js +3 -4
  70. package/lib/generates/internal/SdkHttpFunctionProgrammer.js.map +1 -1
  71. package/lib/generates/internal/SdkHttpNamespaceProgrammer.js +2 -1
  72. package/lib/generates/internal/SdkHttpNamespaceProgrammer.js.map +1 -1
  73. package/lib/generates/internal/SdkHttpSimulationProgrammer.js +6 -3
  74. package/lib/generates/internal/SdkHttpSimulationProgrammer.js.map +1 -1
  75. package/lib/generates/internal/SdkMcpRouteProgrammer.d.ts +15 -0
  76. package/lib/generates/internal/SdkMcpRouteProgrammer.js +148 -0
  77. package/lib/generates/internal/SdkMcpRouteProgrammer.js.map +1 -0
  78. package/lib/generates/internal/SdkRouteDirectory.d.ts +2 -1
  79. package/lib/generates/internal/SdkRouteDirectory.js.map +1 -1
  80. package/lib/generates/internal/SdkWebSocketCloneProgrammer.d.ts +6 -0
  81. package/lib/generates/internal/SdkWebSocketCloneProgrammer.js +283 -0
  82. package/lib/generates/internal/SdkWebSocketCloneProgrammer.js.map +1 -0
  83. package/lib/generates/internal/SdkWebSocketRouteProgrammer.js +11 -9
  84. package/lib/generates/internal/SdkWebSocketRouteProgrammer.js.map +1 -1
  85. package/lib/generates/internal/SwaggerOperationParameterComposer.js +10 -2
  86. package/lib/generates/internal/SwaggerOperationParameterComposer.js.map +1 -1
  87. package/lib/generates/internal/SwaggerOperationResponseComposer.d.ts +1 -1
  88. package/lib/generates/internal/SwaggerOperationResponseComposer.js +6 -1
  89. package/lib/generates/internal/SwaggerOperationResponseComposer.js.map +1 -1
  90. package/lib/generates/internal/SwaggerReadonlyArrayEmender.d.ts +9 -0
  91. package/lib/generates/internal/SwaggerReadonlyArrayEmender.js +174 -0
  92. package/lib/generates/internal/SwaggerReadonlyArrayEmender.js.map +1 -0
  93. package/lib/structures/INestiaSdkInput.d.ts +9 -2
  94. package/lib/structures/IReflectController.d.ts +2 -1
  95. package/lib/structures/IReflectHttpOperationSuccess.d.ts +4 -2
  96. package/lib/structures/IReflectMcpOperation.d.ts +35 -0
  97. package/lib/structures/IReflectMcpOperation.js +3 -0
  98. package/lib/structures/IReflectMcpOperation.js.map +1 -0
  99. package/lib/structures/IReflectMcpOperationParameter.d.ts +19 -0
  100. package/lib/structures/IReflectMcpOperationParameter.js +3 -0
  101. package/lib/structures/IReflectMcpOperationParameter.js.map +1 -0
  102. package/lib/structures/ITypedApplication.d.ts +2 -1
  103. package/lib/structures/ITypedHttpRouteSuccess.d.ts +3 -1
  104. package/lib/structures/ITypedMcpRoute.d.ts +31 -0
  105. package/lib/structures/ITypedMcpRoute.js +3 -0
  106. package/lib/structures/ITypedMcpRoute.js.map +1 -0
  107. package/lib/utils/HttpResponseContentTypeUtil.d.ts +5 -0
  108. package/lib/utils/HttpResponseContentTypeUtil.js +22 -0
  109. package/lib/utils/HttpResponseContentTypeUtil.js.map +1 -0
  110. package/native/go.mod +52 -52
  111. package/native/go.sum +84 -54
  112. package/native/sdk/register.go +322 -165
  113. package/native/sdk/sdk.go +17 -17
  114. package/native/sdk/sdk_metadata_json.go +327 -327
  115. package/native/sdk/sdk_transform.go +1879 -1549
  116. package/package.json +11 -9
  117. package/src/INestiaConfig.ts +267 -267
  118. package/src/NestiaSdkApplication.ts +39 -8
  119. package/src/NestiaSwaggerComposer.ts +153 -142
  120. package/src/analyses/AccessorAnalyzer.ts +64 -67
  121. package/src/analyses/ConfigAnalyzer.ts +330 -330
  122. package/src/analyses/ImportAnalyzer.ts +92 -92
  123. package/src/analyses/PathAnalyzer.ts +130 -69
  124. package/src/analyses/ReflectControllerAnalyzer.ts +112 -105
  125. package/src/analyses/ReflectHttpOperationAnalyzer.ts +183 -183
  126. package/src/analyses/ReflectHttpOperationExceptionAnalyzer.ts +90 -90
  127. package/src/analyses/ReflectHttpOperationParameterAnalyzer.ts +350 -350
  128. package/src/analyses/ReflectHttpOperationResponseAnalyzer.ts +163 -130
  129. package/src/analyses/ReflectMcpOperationAnalyzer.ts +124 -0
  130. package/src/analyses/ReflectMetadataAnalyzer.ts +44 -44
  131. package/src/analyses/SecurityAnalyzer.ts +25 -25
  132. package/src/analyses/TypedMcpRouteAnalyzer.ts +34 -0
  133. package/src/decorators/OperationMetadata.ts +29 -29
  134. package/src/executable/internal/CommandParser.ts +15 -15
  135. package/src/executable/internal/NestiaConfigLoader.ts +451 -446
  136. package/src/executable/internal/NestiaSdkCommand.ts +124 -106
  137. package/src/executable/internal/NestiaSdkWatcher.ts +342 -0
  138. package/src/executable/sdk.ts +90 -88
  139. package/src/generates/CloneGenerator.ts +73 -66
  140. package/src/generates/E2eGenerator.ts +32 -32
  141. package/src/generates/SdkGenerator.ts +176 -118
  142. package/src/generates/SwaggerGenerator.ts +342 -310
  143. package/src/generates/internal/E2eFileProgrammer.ts +240 -233
  144. package/src/generates/internal/FilePrinter.ts +65 -65
  145. package/src/generates/internal/ImportDictionary.ts +209 -204
  146. package/src/generates/internal/SdkAliasCollection.ts +274 -261
  147. package/src/generates/internal/SdkDistributionComposer.ts +123 -116
  148. package/src/generates/internal/SdkFileProgrammer.ts +116 -112
  149. package/src/generates/internal/SdkHttpCloneProgrammer.ts +126 -126
  150. package/src/generates/internal/SdkHttpCloneReferencer.ts +131 -77
  151. package/src/generates/internal/SdkHttpFunctionProgrammer.ts +301 -301
  152. package/src/generates/internal/SdkHttpNamespaceProgrammer.ts +520 -510
  153. package/src/generates/internal/SdkHttpParameterProgrammer.ts +165 -165
  154. package/src/generates/internal/SdkHttpRouteProgrammer.ts +109 -109
  155. package/src/generates/internal/SdkHttpSimulationProgrammer.ts +331 -314
  156. package/src/generates/internal/SdkImportWizard.ts +62 -62
  157. package/src/generates/internal/SdkMcpRouteProgrammer.ts +452 -0
  158. package/src/generates/internal/SdkRouteDirectory.ts +21 -18
  159. package/src/generates/internal/SdkTypeTagProgrammer.ts +114 -114
  160. package/src/generates/internal/SdkWebSocketCloneProgrammer.ts +319 -0
  161. package/src/generates/internal/SdkWebSocketNamespaceProgrammer.ts +389 -389
  162. package/src/generates/internal/SdkWebSocketParameterProgrammer.ts +89 -89
  163. package/src/generates/internal/SdkWebSocketRouteProgrammer.ts +331 -323
  164. package/src/generates/internal/SwaggerDescriptionComposer.ts +64 -64
  165. package/src/generates/internal/SwaggerOperationComposer.ts +119 -119
  166. package/src/generates/internal/SwaggerOperationParameterComposer.ts +175 -162
  167. package/src/generates/internal/SwaggerOperationResponseComposer.ts +115 -110
  168. package/src/generates/internal/SwaggerReadonlyArrayEmender.ts +262 -0
  169. package/src/index.ts +4 -4
  170. package/src/internal/legacy.ts +492 -492
  171. package/src/module.ts +4 -4
  172. package/src/structures/INestiaProject.ts +10 -10
  173. package/src/structures/INestiaSdkInput.ts +27 -20
  174. package/src/structures/IOperationMetadata.ts +41 -41
  175. package/src/structures/IReflectController.ts +18 -15
  176. package/src/structures/IReflectHttpOperation.ts +26 -26
  177. package/src/structures/IReflectHttpOperationException.ts +18 -18
  178. package/src/structures/IReflectHttpOperationParameter.ts +79 -79
  179. package/src/structures/IReflectHttpOperationSuccess.ts +18 -21
  180. package/src/structures/IReflectImport.ts +6 -6
  181. package/src/structures/IReflectMcpOperation.ts +38 -0
  182. package/src/structures/IReflectMcpOperationParameter.ts +27 -0
  183. package/src/structures/IReflectOperationError.ts +26 -26
  184. package/src/structures/IReflectType.ts +4 -4
  185. package/src/structures/IReflectWebSocketOperation.ts +17 -17
  186. package/src/structures/ITypedApplication.ts +12 -11
  187. package/src/structures/ITypedHttpRoute.ts +41 -41
  188. package/src/structures/ITypedHttpRouteException.ts +15 -15
  189. package/src/structures/ITypedHttpRouteParameter.ts +41 -41
  190. package/src/structures/ITypedHttpRouteSuccess.ts +18 -22
  191. package/src/structures/ITypedMcpRoute.ts +33 -0
  192. package/src/structures/ITypedWebSocketRoute.ts +24 -24
  193. package/src/structures/ITypedWebSocketRouteParameter.ts +3 -3
  194. package/src/transform.ts +59 -59
  195. package/src/typings/get-function-location.d.ts +7 -7
  196. package/src/utils/ArrayUtil.ts +26 -26
  197. package/src/utils/EmittedJavaScriptPatcher.ts +88 -88
  198. package/src/utils/FileRetriever.ts +22 -22
  199. package/src/utils/HttpResponseContentTypeUtil.ts +30 -0
  200. package/src/utils/MapUtil.ts +14 -14
  201. package/src/utils/PathUtil.ts +10 -10
  202. package/src/utils/SourceFinder.ts +63 -63
  203. package/src/utils/StringUtil.ts +17 -17
  204. package/src/utils/TsConfigReader.ts +108 -108
  205. package/src/utils/TtscExecutor.ts +68 -68
  206. package/src/utils/VersioningStrategy.ts +28 -28
  207. package/src/validators/HttpHeadersValidator.ts +11 -11
  208. package/src/validators/HttpQueryValidator.ts +11 -11
  209. package/src/validators/TextPlainValidator.ts +17 -17
@@ -1,62 +1,62 @@
1
- import { ImportDictionary } from "./ImportDictionary";
2
-
3
- export namespace SdkImportWizard {
4
- export const Fetcher = (encrypted: boolean) =>
5
- encrypted ? EncryptedFetcher : PlainFetcher;
6
-
7
- export const HttpError = (importer: ImportDictionary) =>
8
- importer.external({
9
- declaration: true,
10
- file: "@nestia/fetcher",
11
- type: "element",
12
- name: "HttpError",
13
- });
14
-
15
- export const IConnection = (importer: ImportDictionary) =>
16
- importer.external({
17
- declaration: true,
18
- file: "@nestia/fetcher",
19
- type: "element",
20
- name: "IConnection",
21
- });
22
-
23
- export const Primitive = (importer: ImportDictionary) =>
24
- importer.external({
25
- declaration: true,
26
- file: "typia",
27
- type: "element",
28
- name: "Primitive",
29
- });
30
-
31
- export const Resolved = (importer: ImportDictionary) =>
32
- importer.external({
33
- declaration: true,
34
- file: "typia",
35
- type: "element",
36
- name: "Resolved",
37
- });
38
-
39
- export const typia = (importer: ImportDictionary) =>
40
- importer.external({
41
- declaration: false,
42
- file: "typia",
43
- type: "default",
44
- name: "typia",
45
- });
46
- }
47
-
48
- const PlainFetcher = (importer: ImportDictionary) =>
49
- importer.external({
50
- declaration: false,
51
- file: "@nestia/fetcher",
52
- type: "element",
53
- name: "PlainFetcher",
54
- });
55
-
56
- const EncryptedFetcher = (importer: ImportDictionary) =>
57
- importer.external({
58
- declaration: false,
59
- file: "@nestia/fetcher/lib/EncryptedFetcher",
60
- type: "element",
61
- name: "EncryptedFetcher",
62
- });
1
+ import { ImportDictionary } from "./ImportDictionary";
2
+
3
+ export namespace SdkImportWizard {
4
+ export const Fetcher = (encrypted: boolean) =>
5
+ encrypted ? EncryptedFetcher : PlainFetcher;
6
+
7
+ export const HttpError = (importer: ImportDictionary) =>
8
+ importer.external({
9
+ declaration: true,
10
+ file: "@nestia/fetcher",
11
+ type: "element",
12
+ name: "HttpError",
13
+ });
14
+
15
+ export const IConnection = (importer: ImportDictionary) =>
16
+ importer.external({
17
+ declaration: true,
18
+ file: "@nestia/fetcher",
19
+ type: "element",
20
+ name: "IConnection",
21
+ });
22
+
23
+ export const Primitive = (importer: ImportDictionary) =>
24
+ importer.external({
25
+ declaration: true,
26
+ file: "typia",
27
+ type: "element",
28
+ name: "Primitive",
29
+ });
30
+
31
+ export const Resolved = (importer: ImportDictionary) =>
32
+ importer.external({
33
+ declaration: true,
34
+ file: "typia",
35
+ type: "element",
36
+ name: "Resolved",
37
+ });
38
+
39
+ export const typia = (importer: ImportDictionary) =>
40
+ importer.external({
41
+ declaration: false,
42
+ file: "typia",
43
+ type: "default",
44
+ name: "typia",
45
+ });
46
+ }
47
+
48
+ const PlainFetcher = (importer: ImportDictionary) =>
49
+ importer.external({
50
+ declaration: false,
51
+ file: "@nestia/fetcher",
52
+ type: "element",
53
+ name: "PlainFetcher",
54
+ });
55
+
56
+ const EncryptedFetcher = (importer: ImportDictionary) =>
57
+ importer.external({
58
+ declaration: false,
59
+ file: "@nestia/fetcher/lib/EncryptedFetcher",
60
+ type: "element",
61
+ name: "EncryptedFetcher",
62
+ });
@@ -0,0 +1,452 @@
1
+ import {
2
+ IdentifierFactory,
3
+ Node,
4
+ NodeFlags,
5
+ SyntaxKind,
6
+ TypeScriptFactory,
7
+ } from "@nestia/factory";
8
+
9
+ import { INestiaProject } from "../../structures/INestiaProject";
10
+ import { ITypedMcpRoute } from "../../structures/ITypedMcpRoute";
11
+ import { FilePrinter } from "./FilePrinter";
12
+ import { ImportDictionary } from "./ImportDictionary";
13
+
14
+ /**
15
+ * Emits a typed client wrapper for an MCP tool.
16
+ *
17
+ * Object output types are wrapped in `Primitive<T>` because MCP round-trips
18
+ * values through JSON. Void MCP tools return `Promise<void>`.
19
+ *
20
+ * @author wildduck - https://github.com/wildduck2
21
+ */
22
+ export namespace SdkMcpRouteProgrammer {
23
+ export const write =
24
+ (project: INestiaProject) =>
25
+ (importer: ImportDictionary) =>
26
+ (route: ITypedMcpRoute): Node[] => [
27
+ FilePrinter.description(
28
+ writeFunction(project)(importer)(route),
29
+ writeDescription(route),
30
+ ),
31
+ writeNamespace(project)(importer)(route),
32
+ ];
33
+
34
+ const writeFunction =
35
+ (_project: INestiaProject) =>
36
+ (importer: ImportDictionary) =>
37
+ (route: ITypedMcpRoute): Node => {
38
+ const clientType = TypeScriptFactory.createTypeReferenceNode(
39
+ importer.external({
40
+ declaration: true,
41
+ file: "@modelcontextprotocol/sdk/client/index.js",
42
+ type: "element",
43
+ name: "Client",
44
+ alias: "McpClient",
45
+ }),
46
+ );
47
+ const callToolResultTypeName = importer.external({
48
+ declaration: true,
49
+ file: "@modelcontextprotocol/sdk/types.js",
50
+ type: "element",
51
+ name: "CallToolResult",
52
+ alias: "McpCallToolResult",
53
+ });
54
+ const isVoid = isVoidReturn(route);
55
+ if (!isVoid)
56
+ importer.external({
57
+ declaration: true,
58
+ file: "typia",
59
+ type: "element",
60
+ name: "Primitive",
61
+ });
62
+
63
+ const inputRef: Node = route.input
64
+ ? TypeScriptFactory.createTypeReferenceNode(`${route.name}.Input`)
65
+ : TypeScriptFactory.createTypeLiteralNode([]);
66
+ const outputRef: Node = TypeScriptFactory.createTypeReferenceNode(
67
+ `${route.name}.Output`,
68
+ );
69
+
70
+ const params: Node[] = [
71
+ TypeScriptFactory.createParameterDeclaration(
72
+ undefined,
73
+ undefined,
74
+ "client",
75
+ undefined,
76
+ clientType,
77
+ undefined,
78
+ ),
79
+ ];
80
+ if (route.input)
81
+ params.push(
82
+ TypeScriptFactory.createParameterDeclaration(
83
+ undefined,
84
+ undefined,
85
+ "args",
86
+ undefined,
87
+ inputRef,
88
+ undefined,
89
+ ),
90
+ );
91
+
92
+ const toolNameExpr = TypeScriptFactory.createPropertyAccessExpression(
93
+ TypeScriptFactory.createPropertyAccessExpression(
94
+ TypeScriptFactory.createIdentifier(route.name),
95
+ "METADATA",
96
+ ),
97
+ "tool",
98
+ );
99
+
100
+ const callToolParams: Node[] = [
101
+ TypeScriptFactory.createPropertyAssignment("name", toolNameExpr),
102
+ ];
103
+ if (route.input)
104
+ callToolParams.push(
105
+ TypeScriptFactory.createPropertyAssignment(
106
+ "arguments",
107
+ TypeScriptFactory.createAsExpression(
108
+ TypeScriptFactory.createAsExpression(
109
+ TypeScriptFactory.createIdentifier("args"),
110
+ TypeScriptFactory.createKeywordTypeNode(SyntaxKind.AnyKeyword),
111
+ ),
112
+ TypeScriptFactory.createTypeReferenceNode("Record", [
113
+ TypeScriptFactory.createKeywordTypeNode(
114
+ SyntaxKind.StringKeyword,
115
+ ),
116
+ TypeScriptFactory.createKeywordTypeNode(SyntaxKind.AnyKeyword),
117
+ ]),
118
+ ),
119
+ ),
120
+ );
121
+
122
+ const body = TypeScriptFactory.createBlock(
123
+ [
124
+ TypeScriptFactory.createVariableStatement(
125
+ undefined,
126
+ TypeScriptFactory.createVariableDeclarationList(
127
+ [
128
+ TypeScriptFactory.createVariableDeclaration(
129
+ "raw",
130
+ undefined,
131
+ undefined,
132
+ TypeScriptFactory.createAwaitExpression(
133
+ TypeScriptFactory.createCallExpression(
134
+ TypeScriptFactory.createPropertyAccessExpression(
135
+ TypeScriptFactory.createIdentifier("client"),
136
+ "callTool",
137
+ ),
138
+ undefined,
139
+ [
140
+ TypeScriptFactory.createObjectLiteralExpression(
141
+ callToolParams,
142
+ true,
143
+ ),
144
+ ],
145
+ ),
146
+ ),
147
+ ),
148
+ ],
149
+ NodeFlags.Const,
150
+ ),
151
+ ),
152
+ TypeScriptFactory.createIfStatement(
153
+ TypeScriptFactory.createCallExpression(
154
+ TypeScriptFactory.createPropertyAccessExpression(
155
+ TypeScriptFactory.createPropertyAccessExpression(
156
+ TypeScriptFactory.createPropertyAccessExpression(
157
+ TypeScriptFactory.createIdentifier("Object"),
158
+ "prototype",
159
+ ),
160
+ "hasOwnProperty",
161
+ ),
162
+ "call",
163
+ ),
164
+ undefined,
165
+ [
166
+ TypeScriptFactory.createIdentifier("raw"),
167
+ TypeScriptFactory.createStringLiteral("toolResult"),
168
+ ],
169
+ ),
170
+ throwToolError(
171
+ toolNameExpr,
172
+ '" returned a legacy (pre-2024-11-05) compatibility result',
173
+ ),
174
+ ),
175
+ TypeScriptFactory.createVariableStatement(
176
+ undefined,
177
+ TypeScriptFactory.createVariableDeclarationList(
178
+ [
179
+ TypeScriptFactory.createVariableDeclaration(
180
+ "result",
181
+ undefined,
182
+ TypeScriptFactory.createTypeReferenceNode(
183
+ callToolResultTypeName,
184
+ ),
185
+ TypeScriptFactory.createAsExpression(
186
+ TypeScriptFactory.createIdentifier("raw"),
187
+ TypeScriptFactory.createTypeReferenceNode(
188
+ callToolResultTypeName,
189
+ ),
190
+ ),
191
+ ),
192
+ ],
193
+ NodeFlags.Const,
194
+ ),
195
+ ),
196
+ TypeScriptFactory.createIfStatement(
197
+ TypeScriptFactory.createBinaryExpression(
198
+ TypeScriptFactory.createPropertyAccessExpression(
199
+ TypeScriptFactory.createIdentifier("result"),
200
+ "isError",
201
+ ),
202
+ TypeScriptFactory.createToken(SyntaxKind.EqualsEqualsEqualsToken),
203
+ TypeScriptFactory.createTrue(),
204
+ ),
205
+ throwToolError(toolNameExpr, '" returned isError'),
206
+ ),
207
+ ...(isVoid
208
+ ? [TypeScriptFactory.createReturnStatement()]
209
+ : [
210
+ TypeScriptFactory.createVariableStatement(
211
+ undefined,
212
+ TypeScriptFactory.createVariableDeclarationList(
213
+ [
214
+ TypeScriptFactory.createVariableDeclaration(
215
+ "first",
216
+ undefined,
217
+ undefined,
218
+ TypeScriptFactory.createCallExpression(
219
+ TypeScriptFactory.createPropertyAccessExpression(
220
+ TypeScriptFactory.createPropertyAccessExpression(
221
+ TypeScriptFactory.createIdentifier("result"),
222
+ "content",
223
+ ),
224
+ "find",
225
+ ),
226
+ undefined,
227
+ [
228
+ TypeScriptFactory.createArrowFunction(
229
+ undefined,
230
+ undefined,
231
+ [IdentifierFactory.parameter("entry")],
232
+ undefined,
233
+ undefined,
234
+ TypeScriptFactory.createBinaryExpression(
235
+ TypeScriptFactory.createPropertyAccessExpression(
236
+ TypeScriptFactory.createIdentifier("entry"),
237
+ "type",
238
+ ),
239
+ TypeScriptFactory.createToken(
240
+ SyntaxKind.EqualsEqualsEqualsToken,
241
+ ),
242
+ TypeScriptFactory.createStringLiteral("text"),
243
+ ),
244
+ ),
245
+ ],
246
+ ),
247
+ ),
248
+ ],
249
+ NodeFlags.Const,
250
+ ),
251
+ ),
252
+ TypeScriptFactory.createIfStatement(
253
+ TypeScriptFactory.createBinaryExpression(
254
+ TypeScriptFactory.createIdentifier("first"),
255
+ TypeScriptFactory.createToken(
256
+ SyntaxKind.EqualsEqualsEqualsToken,
257
+ ),
258
+ TypeScriptFactory.createIdentifier("undefined"),
259
+ ),
260
+ throwToolError(toolNameExpr, '" returned no text content'),
261
+ ),
262
+ TypeScriptFactory.createIfStatement(
263
+ TypeScriptFactory.createBinaryExpression(
264
+ TypeScriptFactory.createPropertyAccessExpression(
265
+ TypeScriptFactory.createIdentifier("first"),
266
+ "type",
267
+ ),
268
+ TypeScriptFactory.createToken(
269
+ SyntaxKind.EqualsEqualsEqualsToken,
270
+ ),
271
+ TypeScriptFactory.createStringLiteral("text"),
272
+ ),
273
+ TypeScriptFactory.createReturnStatement(
274
+ TypeScriptFactory.createAsExpression(
275
+ TypeScriptFactory.createCallExpression(
276
+ TypeScriptFactory.createPropertyAccessExpression(
277
+ TypeScriptFactory.createIdentifier("JSON"),
278
+ "parse",
279
+ ),
280
+ undefined,
281
+ [
282
+ TypeScriptFactory.createPropertyAccessExpression(
283
+ TypeScriptFactory.createIdentifier("first"),
284
+ "text",
285
+ ),
286
+ ],
287
+ ),
288
+ outputRef,
289
+ ),
290
+ ),
291
+ ),
292
+ throwToolError(toolNameExpr, '" returned no text content'),
293
+ ]),
294
+ ],
295
+ true,
296
+ );
297
+
298
+ return TypeScriptFactory.createFunctionDeclaration(
299
+ [
300
+ TypeScriptFactory.createModifier(SyntaxKind.ExportKeyword),
301
+ TypeScriptFactory.createModifier(SyntaxKind.AsyncKeyword),
302
+ ],
303
+ undefined,
304
+ route.name,
305
+ undefined,
306
+ params,
307
+ TypeScriptFactory.createTypeReferenceNode("Promise", [outputRef]),
308
+ body,
309
+ );
310
+ };
311
+
312
+ const writeNamespace =
313
+ (_project: INestiaProject) =>
314
+ (importer: ImportDictionary) =>
315
+ (route: ITypedMcpRoute): Node => {
316
+ const statements: Node[] = [];
317
+
318
+ if (route.input)
319
+ statements.push(
320
+ TypeScriptFactory.createTypeAliasDeclaration(
321
+ [TypeScriptFactory.createModifier(SyntaxKind.ExportKeyword)],
322
+ "Input",
323
+ undefined,
324
+ TypeScriptFactory.createTypeReferenceNode(route.input.type.name),
325
+ ),
326
+ );
327
+
328
+ const outputType: Node =
329
+ !isVoidReturn(route) && route.returnType !== null
330
+ ? TypeScriptFactory.createTypeReferenceNode(
331
+ importer.external({
332
+ declaration: true,
333
+ file: "typia",
334
+ type: "element",
335
+ name: "Primitive",
336
+ }),
337
+ [
338
+ TypeScriptFactory.createTypeReferenceNode(
339
+ unwrapPromise(route.returnType.name),
340
+ ),
341
+ ],
342
+ )
343
+ : TypeScriptFactory.createKeywordTypeNode(SyntaxKind.VoidKeyword);
344
+ statements.push(
345
+ TypeScriptFactory.createTypeAliasDeclaration(
346
+ [TypeScriptFactory.createModifier(SyntaxKind.ExportKeyword)],
347
+ "Output",
348
+ undefined,
349
+ outputType,
350
+ ),
351
+ );
352
+
353
+ statements.push(
354
+ TypeScriptFactory.createVariableStatement(
355
+ [TypeScriptFactory.createModifier(SyntaxKind.ExportKeyword)],
356
+ TypeScriptFactory.createVariableDeclarationList(
357
+ [
358
+ TypeScriptFactory.createVariableDeclaration(
359
+ "METADATA",
360
+ undefined,
361
+ undefined,
362
+ TypeScriptFactory.createAsExpression(
363
+ TypeScriptFactory.createObjectLiteralExpression(
364
+ [
365
+ TypeScriptFactory.createPropertyAssignment(
366
+ "protocol",
367
+ TypeScriptFactory.createStringLiteral("mcp"),
368
+ ),
369
+ TypeScriptFactory.createPropertyAssignment(
370
+ "tool",
371
+ TypeScriptFactory.createStringLiteral(route.toolName),
372
+ ),
373
+ TypeScriptFactory.createPropertyAssignment(
374
+ "title",
375
+ route.title === null
376
+ ? TypeScriptFactory.createNull()
377
+ : TypeScriptFactory.createStringLiteral(route.title),
378
+ ),
379
+ TypeScriptFactory.createPropertyAssignment(
380
+ "description",
381
+ route.toolDescription === null
382
+ ? TypeScriptFactory.createNull()
383
+ : TypeScriptFactory.createStringLiteral(
384
+ route.toolDescription,
385
+ ),
386
+ ),
387
+ ],
388
+ true,
389
+ ),
390
+ TypeScriptFactory.createTypeReferenceNode("const"),
391
+ ),
392
+ ),
393
+ ],
394
+ NodeFlags.Const,
395
+ ),
396
+ ),
397
+ );
398
+
399
+ return TypeScriptFactory.createModuleDeclaration(
400
+ [TypeScriptFactory.createModifier(SyntaxKind.ExportKeyword)],
401
+ TypeScriptFactory.createIdentifier(route.name),
402
+ TypeScriptFactory.createModuleBlock(statements),
403
+ NodeFlags.Namespace,
404
+ );
405
+ };
406
+
407
+ const writeDescription = (route: ITypedMcpRoute): string => {
408
+ const lines: string[] = [];
409
+ if (route.toolDescription) lines.push(...route.toolDescription.split("\n"));
410
+ else if (route.description) lines.push(...route.description.split("\n"));
411
+ if (lines.length) lines.push("");
412
+ lines.push(
413
+ `@controller ${route.controller.class.name}.${route.function.name || route.name}`,
414
+ `@tool ${route.toolName}`,
415
+ `@accessor ${["api", "functional", ...route.accessor].join(".")}`,
416
+ `@protocol mcp`,
417
+ `@nestia Generated by Nestia - https://github.com/samchon/nestia`,
418
+ );
419
+ return lines.join("\n");
420
+ };
421
+
422
+ const unwrapPromise = (name: string): string => {
423
+ const m = /^Promise<(.+)>$/.exec(name);
424
+ return m ? m[1]! : name;
425
+ };
426
+
427
+ const isVoidReturn = (route: ITypedMcpRoute): boolean =>
428
+ route.returnType === null ||
429
+ isVoidName(unwrapPromise(route.returnType.name));
430
+
431
+ const isVoidName = (name: string): boolean =>
432
+ name === "void" || name === "undefined";
433
+
434
+ const throwToolError = (toolNameExpr: Node, suffix: string): Node =>
435
+ TypeScriptFactory.createThrowStatement(
436
+ TypeScriptFactory.createNewExpression(
437
+ TypeScriptFactory.createIdentifier("Error"),
438
+ undefined,
439
+ [
440
+ TypeScriptFactory.createTemplateExpression(
441
+ TypeScriptFactory.createTemplateHead('MCP tool "'),
442
+ [
443
+ TypeScriptFactory.createTemplateSpan(
444
+ toolNameExpr,
445
+ TypeScriptFactory.createTemplateTail(suffix),
446
+ ),
447
+ ],
448
+ ),
449
+ ],
450
+ ),
451
+ );
452
+ }
@@ -1,18 +1,21 @@
1
- import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
2
- import { ITypedWebSocketRoute } from "../../structures/ITypedWebSocketRoute";
3
-
4
- export class SdkRouteDirectory {
5
- public readonly module: string;
6
- public readonly children: Map<string, SdkRouteDirectory>;
7
- public readonly routes: Array<ITypedHttpRoute | ITypedWebSocketRoute>;
8
-
9
- public constructor(
10
- readonly parent: SdkRouteDirectory | null,
11
- readonly name: string,
12
- ) {
13
- this.children = new Map();
14
- this.routes = [];
15
- this.module =
16
- this.parent !== null ? `${this.parent.module}.${name}` : `api.${name}`;
17
- }
18
- }
1
+ import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
2
+ import { ITypedMcpRoute } from "../../structures/ITypedMcpRoute";
3
+ import { ITypedWebSocketRoute } from "../../structures/ITypedWebSocketRoute";
4
+
5
+ export class SdkRouteDirectory {
6
+ public readonly module: string;
7
+ public readonly children: Map<string, SdkRouteDirectory>;
8
+ public readonly routes: Array<
9
+ ITypedHttpRoute | ITypedWebSocketRoute | ITypedMcpRoute
10
+ >;
11
+
12
+ public constructor(
13
+ readonly parent: SdkRouteDirectory | null,
14
+ readonly name: string,
15
+ ) {
16
+ this.children = new Map();
17
+ this.routes = [];
18
+ this.module =
19
+ this.parent !== null ? `${this.parent.module}.${name}` : `api.${name}`;
20
+ }
21
+ }