@intlayer/mcp 8.1.2 → 8.1.3

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.
@@ -1,324 +1,2 @@
1
- import { relative } from "node:path";
2
- import { listProjects } from "@intlayer/chokidar/cli";
3
- import { build, extract, fill, init, listContentDeclarationRows, listMissingTranslations, pull, push } from "@intlayer/cli";
4
- import { Locales } from "@intlayer/types";
5
- import z from "zod/v3";
6
-
7
- //#region src/tools/cli.ts
8
- const loadCLITools = async (server) => {
9
- server.registerTool("intlayer-init", {
10
- title: "Initialize Intlayer",
11
- description: "Initialize Intlayer in the project",
12
- inputSchema: { projectRoot: z.string().describe("Project root directory") },
13
- annotations: { destructiveHint: true }
14
- }, async ({ projectRoot }) => {
15
- try {
16
- await init(projectRoot);
17
- return { content: [{
18
- type: "text",
19
- text: "Initialization successful."
20
- }] };
21
- } catch (error) {
22
- return { content: [{
23
- type: "text",
24
- text: `Initialization failed: ${error instanceof Error ? error.message : "An unknown error occurred"}`
25
- }] };
26
- }
27
- });
28
- server.registerTool("intlayer-build", {
29
- title: "Build Dictionaries",
30
- description: "Build the dictionaries. List all content declarations files `.content.{ts,tsx,js,json,...}` to update the content callable using the `useIntlayer` hook.",
31
- inputSchema: {
32
- watch: z.boolean().optional().describe("Watch for changes"),
33
- baseDir: z.string().optional().describe("Base directory"),
34
- env: z.string().optional().describe("Environment"),
35
- envFile: z.string().optional().describe("Environment file"),
36
- verbose: z.boolean().optional().describe("Verbose output"),
37
- prefix: z.string().optional().describe("Log prefix")
38
- },
39
- annotations: { destructiveHint: true }
40
- }, async ({ watch, baseDir, env, envFile, verbose, prefix }) => {
41
- try {
42
- const log = {};
43
- if (verbose) log.mode = "verbose";
44
- if (prefix) log.prefix = prefix;
45
- await build({
46
- watch,
47
- configOptions: {
48
- baseDir,
49
- env,
50
- envFile,
51
- override: { log }
52
- }
53
- });
54
- return { content: [{
55
- type: "text",
56
- text: "Build successful."
57
- }] };
58
- } catch (error) {
59
- return { content: [{
60
- type: "text",
61
- text: `Build failed: ${error instanceof Error ? error.message : "An unknown error occurred"}`
62
- }] };
63
- }
64
- });
65
- server.registerTool("intlayer-fill", {
66
- title: "Fill Translations",
67
- description: "Fill the dictionaries with missing translations / review translations using Intlayer servers",
68
- inputSchema: {
69
- sourceLocale: z.nativeEnum(Locales.ALL_LOCALES).optional().describe("Source locale"),
70
- outputLocales: z.union([z.nativeEnum(Locales.ALL_LOCALES), z.array(z.nativeEnum(Locales.ALL_LOCALES))]).optional().describe("Output locales"),
71
- file: z.union([z.string(), z.array(z.string())]).optional().describe("File path"),
72
- mode: z.enum(["complete", "review"]).optional().describe("Fill mode"),
73
- keys: z.union([z.string(), z.array(z.string())]).optional().describe("Keys to include"),
74
- excludedKeys: z.union([z.string(), z.array(z.string())]).optional().describe("Keys to exclude"),
75
- pathFilter: z.union([z.string(), z.array(z.string())]).optional().describe("Path filter"),
76
- gitOptions: z.object({
77
- gitDiff: z.boolean().optional(),
78
- gitDiffBase: z.string().optional(),
79
- gitDiffCurrent: z.string().optional(),
80
- uncommitted: z.boolean().optional(),
81
- unpushed: z.boolean().optional(),
82
- untracked: z.boolean().optional()
83
- }).optional().describe("Git options"),
84
- aiOptions: z.object({
85
- provider: z.string().optional(),
86
- temperature: z.number().optional(),
87
- model: z.string().optional(),
88
- apiKey: z.string().optional(),
89
- customPrompt: z.string().optional(),
90
- applicationContext: z.string().optional()
91
- }).optional().describe("AI options")
92
- },
93
- annotations: { destructiveHint: true }
94
- }, async (props) => {
95
- try {
96
- const { gitOptions, ...rest } = props;
97
- const fillOptions = {
98
- ...rest,
99
- gitOptions: void 0
100
- };
101
- if (gitOptions) {
102
- const { gitDiff, uncommitted, unpushed, untracked, ...restGit } = gitOptions;
103
- const mode = [];
104
- if (gitDiff) mode.push("gitDiff");
105
- if (uncommitted) mode.push("uncommitted");
106
- if (unpushed) mode.push("unpushed");
107
- if (untracked) mode.push("untracked");
108
- fillOptions.gitOptions = {
109
- ...restGit,
110
- mode
111
- };
112
- }
113
- await fill(fillOptions);
114
- return { content: [{
115
- type: "text",
116
- text: "Fill successful."
117
- }] };
118
- } catch (error) {
119
- return { content: [{
120
- type: "text",
121
- text: `Fill failed: ${error instanceof Error ? error.message : "An unknown error occurred"}`
122
- }] };
123
- }
124
- });
125
- server.registerTool("intlayer-push", {
126
- title: "Push Dictionaries",
127
- description: "Push local dictionaries to the server",
128
- inputSchema: {
129
- deleteLocaleDictionary: z.boolean().optional().describe("Delete local dictionary after push"),
130
- keepLocaleDictionary: z.boolean().optional().describe("Keep local dictionary after push"),
131
- dictionaries: z.array(z.string()).optional().describe("List of dictionaries to push"),
132
- gitOptions: z.object({
133
- gitDiff: z.boolean().optional(),
134
- gitDiffBase: z.string().optional(),
135
- gitDiffCurrent: z.string().optional(),
136
- uncommitted: z.boolean().optional(),
137
- unpushed: z.boolean().optional(),
138
- untracked: z.boolean().optional()
139
- }).optional().describe("Git options")
140
- },
141
- annotations: { destructiveHint: true }
142
- }, async (props) => {
143
- try {
144
- const { gitOptions, ...rest } = props;
145
- const pushOptions = {
146
- ...rest,
147
- gitOptions: void 0
148
- };
149
- if (gitOptions) {
150
- const { gitDiff, uncommitted, unpushed, untracked, ...restGit } = gitOptions;
151
- const mode = [];
152
- if (gitDiff) mode.push("gitDiff");
153
- if (uncommitted) mode.push("uncommitted");
154
- if (unpushed) mode.push("unpushed");
155
- if (untracked) mode.push("untracked");
156
- pushOptions.gitOptions = {
157
- ...restGit,
158
- mode
159
- };
160
- }
161
- await push(pushOptions);
162
- return { content: [{
163
- type: "text",
164
- text: "Push successful."
165
- }] };
166
- } catch (error) {
167
- return { content: [{
168
- type: "text",
169
- text: `Push failed: ${error instanceof Error ? error.message : "An unknown error occurred"}`
170
- }] };
171
- }
172
- });
173
- server.registerTool("intlayer-pull", {
174
- title: "Pull Dictionaries",
175
- description: "Pull dictionaries from the CMS",
176
- inputSchema: {
177
- dictionaries: z.array(z.string()).optional().describe("List of dictionaries to pull"),
178
- newDictionariesPath: z.string().optional().describe("Path to save new dictionaries")
179
- },
180
- annotations: { destructiveHint: true }
181
- }, async (props) => {
182
- try {
183
- await pull(props);
184
- return { content: [{
185
- type: "text",
186
- text: "Pull successful."
187
- }] };
188
- } catch (error) {
189
- return { content: [{
190
- type: "text",
191
- text: `Pull failed: ${error instanceof Error ? error.message : "An unknown error occurred"}`
192
- }] };
193
- }
194
- });
195
- server.registerTool("intlayer-content-list", {
196
- title: "List Content Declarations",
197
- description: "List the content declaration (.content.{ts,tsx,js,json,...}) files present in the project. That files contain the multilingual content of the application and are used to build the dictionaries.",
198
- inputSchema: {
199
- configOptions: z.object({
200
- baseDir: z.string().optional(),
201
- env: z.string().optional(),
202
- envFile: z.string().optional(),
203
- override: z.object({ log: z.object({
204
- prefix: z.string().optional(),
205
- verbose: z.boolean().optional()
206
- }).optional() }).optional()
207
- }).optional().describe("Configuration options"),
208
- absolute: z.boolean().optional().describe("Output the results as absolute paths instead of relative paths"),
209
- json: z.boolean().optional().describe("Output the results as JSON instead of formatted text")
210
- },
211
- annotations: { readOnlyHint: true }
212
- }, async (props) => {
213
- try {
214
- const rows = listContentDeclarationRows(props);
215
- return { content: [{
216
- type: "text",
217
- text: props.json ? JSON.stringify(rows) : JSON.stringify(rows, null, 2)
218
- }] };
219
- } catch (error) {
220
- return { content: [{
221
- type: "text",
222
- text: `Content list failed: ${error instanceof Error ? error.message : "An unknown error occurred"}`
223
- }] };
224
- }
225
- });
226
- server.registerTool("intlayer-content-test", {
227
- title: "Test Translations",
228
- description: "Test if there are missing translations in the content declaration files. That files contain the multilingual content of the application and are used to build the dictionaries.",
229
- inputSchema: { configOptions: z.object({
230
- baseDir: z.string().optional(),
231
- env: z.string().optional(),
232
- envFile: z.string().optional(),
233
- override: z.object({ log: z.object({
234
- prefix: z.string().optional(),
235
- verbose: z.boolean().optional()
236
- }).optional() }).optional()
237
- }).optional().describe("Configuration options") },
238
- annotations: { readOnlyHint: true }
239
- }, async (props) => {
240
- try {
241
- const missingTranslations = listMissingTranslations(props?.configOptions);
242
- return { content: [{
243
- type: "text",
244
- text: JSON.stringify(missingTranslations, null, 2)
245
- }] };
246
- } catch (error) {
247
- return { content: [{
248
- type: "text",
249
- text: `Content test failed: ${error instanceof Error ? error.message : "An unknown error occurred"}`
250
- }] };
251
- }
252
- });
253
- server.registerTool("intlayer-extract", {
254
- title: "Extract strings from Component",
255
- description: "Extract strings from an existing component to be placed in a .content file close to the component. Trigger this action to make an existing component multilingual. If the component does not exist, create a normal component including text in JSX, and then trigger this tool to extract it.",
256
- inputSchema: {
257
- file: z.union([z.string(), z.array(z.string())]).optional().describe("List of files to extract"),
258
- outputContentDeclarations: z.string().optional().describe("Path to output content declaration files"),
259
- configOptions: z.object({
260
- baseDir: z.string().optional(),
261
- env: z.string().optional(),
262
- envFile: z.string().optional(),
263
- override: z.object({ log: z.object({
264
- prefix: z.string().optional(),
265
- verbose: z.boolean().optional()
266
- }).optional() }).optional()
267
- }).optional().describe("Configuration options")
268
- },
269
- annotations: { destructiveHint: true }
270
- }, async (props) => {
271
- try {
272
- await extract({
273
- files: Array.isArray(props.file) ? props.file : props.file ? [props.file] : void 0,
274
- outputContentDeclarations: props.outputContentDeclarations,
275
- configOptions: props.configOptions
276
- });
277
- return { content: [{
278
- type: "text",
279
- text: "Extract successful."
280
- }] };
281
- } catch (error) {
282
- return { content: [{
283
- type: "text",
284
- text: `Extract failed: ${error instanceof Error ? error.message : "An unknown error occurred"}`
285
- }] };
286
- }
287
- });
288
- server.registerTool("intlayer-projects-list", {
289
- title: "List Projects",
290
- description: "List all Intlayer projects in the directory. Search for configuration files to find all Intlayer projects.",
291
- inputSchema: {
292
- baseDir: z.string().optional().describe("Base directory to search from"),
293
- gitRoot: z.boolean().optional().describe("Search from the git root directory instead of the base directory"),
294
- absolute: z.boolean().optional().describe("Output the results as absolute paths instead of relative paths"),
295
- json: z.boolean().optional().describe("Output the results as JSON instead of formatted text")
296
- },
297
- annotations: { readOnlyHint: true }
298
- }, async (props) => {
299
- try {
300
- const { searchDir, projectsPath } = await listProjects({
301
- baseDir: props.baseDir,
302
- gitRoot: props.gitRoot
303
- });
304
- const projectsRelativePath = projectsPath.map((projectPath) => props.absolute ? projectPath : relative(searchDir, projectPath)).map((projectPath) => projectPath === "" ? "." : projectPath);
305
- const outputPaths = props.absolute ? projectsPath : projectsRelativePath;
306
- return { content: [{
307
- type: "text",
308
- text: props.json ? JSON.stringify(outputPaths) : JSON.stringify({
309
- searchDir,
310
- projectsPath: outputPaths
311
- }, null, 2)
312
- }] };
313
- } catch (error) {
314
- return { content: [{
315
- type: "text",
316
- text: `Projects list failed: ${error instanceof Error ? error.message : "An unknown error occurred"}`
317
- }] };
318
- }
319
- });
320
- };
321
-
322
- //#endregion
323
- export { loadCLITools };
1
+ import{relative as e}from"node:path";import{listProjects as t}from"@intlayer/chokidar/cli";import{build as n,extract as r,fill as i,init as a,listContentDeclarationRows as o,listMissingTranslations as s,pull as c,push as l}from"@intlayer/cli";import{Locales as u}from"@intlayer/types";import d from"zod/v3";const f=async f=>{f.registerTool(`intlayer-init`,{title:`Initialize Intlayer`,description:`Initialize Intlayer in the project`,inputSchema:{projectRoot:d.string().describe(`Project root directory`)},annotations:{destructiveHint:!0}},async({projectRoot:e})=>{try{return await a(e),{content:[{type:`text`,text:`Initialization successful.`}]}}catch(e){return{content:[{type:`text`,text:`Initialization failed: ${e instanceof Error?e.message:`An unknown error occurred`}`}]}}}),f.registerTool(`intlayer-build`,{title:`Build Dictionaries`,description:"Build the dictionaries. List all content declarations files `.content.{ts,tsx,js,json,...}` to update the content callable using the `useIntlayer` hook.",inputSchema:{watch:d.boolean().optional().describe(`Watch for changes`),baseDir:d.string().optional().describe(`Base directory`),env:d.string().optional().describe(`Environment`),envFile:d.string().optional().describe(`Environment file`),verbose:d.boolean().optional().describe(`Verbose output`),prefix:d.string().optional().describe(`Log prefix`)},annotations:{destructiveHint:!0}},async({watch:e,baseDir:t,env:r,envFile:i,verbose:a,prefix:o})=>{try{let s={};return a&&(s.mode=`verbose`),o&&(s.prefix=o),await n({watch:e,configOptions:{baseDir:t,env:r,envFile:i,override:{log:s}}}),{content:[{type:`text`,text:`Build successful.`}]}}catch(e){return{content:[{type:`text`,text:`Build failed: ${e instanceof Error?e.message:`An unknown error occurred`}`}]}}}),f.registerTool(`intlayer-fill`,{title:`Fill Translations`,description:`Fill the dictionaries with missing translations / review translations using Intlayer servers`,inputSchema:{sourceLocale:d.nativeEnum(u.ALL_LOCALES).optional().describe(`Source locale`),outputLocales:d.union([d.nativeEnum(u.ALL_LOCALES),d.array(d.nativeEnum(u.ALL_LOCALES))]).optional().describe(`Output locales`),file:d.union([d.string(),d.array(d.string())]).optional().describe(`File path`),mode:d.enum([`complete`,`review`]).optional().describe(`Fill mode`),keys:d.union([d.string(),d.array(d.string())]).optional().describe(`Keys to include`),excludedKeys:d.union([d.string(),d.array(d.string())]).optional().describe(`Keys to exclude`),pathFilter:d.union([d.string(),d.array(d.string())]).optional().describe(`Path filter`),gitOptions:d.object({gitDiff:d.boolean().optional(),gitDiffBase:d.string().optional(),gitDiffCurrent:d.string().optional(),uncommitted:d.boolean().optional(),unpushed:d.boolean().optional(),untracked:d.boolean().optional()}).optional().describe(`Git options`),aiOptions:d.object({provider:d.string().optional(),temperature:d.number().optional(),model:d.string().optional(),apiKey:d.string().optional(),customPrompt:d.string().optional(),applicationContext:d.string().optional()}).optional().describe(`AI options`)},annotations:{destructiveHint:!0}},async e=>{try{let{gitOptions:t,...n}=e,r={...n,gitOptions:void 0};if(t){let{gitDiff:e,uncommitted:n,unpushed:i,untracked:a,...o}=t,s=[];e&&s.push(`gitDiff`),n&&s.push(`uncommitted`),i&&s.push(`unpushed`),a&&s.push(`untracked`),r.gitOptions={...o,mode:s}}return await i(r),{content:[{type:`text`,text:`Fill successful.`}]}}catch(e){return{content:[{type:`text`,text:`Fill failed: ${e instanceof Error?e.message:`An unknown error occurred`}`}]}}}),f.registerTool(`intlayer-push`,{title:`Push Dictionaries`,description:`Push local dictionaries to the server`,inputSchema:{deleteLocaleDictionary:d.boolean().optional().describe(`Delete local dictionary after push`),keepLocaleDictionary:d.boolean().optional().describe(`Keep local dictionary after push`),dictionaries:d.array(d.string()).optional().describe(`List of dictionaries to push`),gitOptions:d.object({gitDiff:d.boolean().optional(),gitDiffBase:d.string().optional(),gitDiffCurrent:d.string().optional(),uncommitted:d.boolean().optional(),unpushed:d.boolean().optional(),untracked:d.boolean().optional()}).optional().describe(`Git options`)},annotations:{destructiveHint:!0}},async e=>{try{let{gitOptions:t,...n}=e,r={...n,gitOptions:void 0};if(t){let{gitDiff:e,uncommitted:n,unpushed:i,untracked:a,...o}=t,s=[];e&&s.push(`gitDiff`),n&&s.push(`uncommitted`),i&&s.push(`unpushed`),a&&s.push(`untracked`),r.gitOptions={...o,mode:s}}return await l(r),{content:[{type:`text`,text:`Push successful.`}]}}catch(e){return{content:[{type:`text`,text:`Push failed: ${e instanceof Error?e.message:`An unknown error occurred`}`}]}}}),f.registerTool(`intlayer-pull`,{title:`Pull Dictionaries`,description:`Pull dictionaries from the CMS`,inputSchema:{dictionaries:d.array(d.string()).optional().describe(`List of dictionaries to pull`),newDictionariesPath:d.string().optional().describe(`Path to save new dictionaries`)},annotations:{destructiveHint:!0}},async e=>{try{return await c(e),{content:[{type:`text`,text:`Pull successful.`}]}}catch(e){return{content:[{type:`text`,text:`Pull failed: ${e instanceof Error?e.message:`An unknown error occurred`}`}]}}}),f.registerTool(`intlayer-content-list`,{title:`List Content Declarations`,description:`List the content declaration (.content.{ts,tsx,js,json,...}) files present in the project. That files contain the multilingual content of the application and are used to build the dictionaries.`,inputSchema:{configOptions:d.object({baseDir:d.string().optional(),env:d.string().optional(),envFile:d.string().optional(),override:d.object({log:d.object({prefix:d.string().optional(),verbose:d.boolean().optional()}).optional()}).optional()}).optional().describe(`Configuration options`),absolute:d.boolean().optional().describe(`Output the results as absolute paths instead of relative paths`),json:d.boolean().optional().describe(`Output the results as JSON instead of formatted text`)},annotations:{readOnlyHint:!0}},async e=>{try{let t=o(e);return{content:[{type:`text`,text:e.json?JSON.stringify(t):JSON.stringify(t,null,2)}]}}catch(e){return{content:[{type:`text`,text:`Content list failed: ${e instanceof Error?e.message:`An unknown error occurred`}`}]}}}),f.registerTool(`intlayer-content-test`,{title:`Test Translations`,description:`Test if there are missing translations in the content declaration files. That files contain the multilingual content of the application and are used to build the dictionaries.`,inputSchema:{configOptions:d.object({baseDir:d.string().optional(),env:d.string().optional(),envFile:d.string().optional(),override:d.object({log:d.object({prefix:d.string().optional(),verbose:d.boolean().optional()}).optional()}).optional()}).optional().describe(`Configuration options`)},annotations:{readOnlyHint:!0}},async e=>{try{let t=s(e?.configOptions);return{content:[{type:`text`,text:JSON.stringify(t,null,2)}]}}catch(e){return{content:[{type:`text`,text:`Content test failed: ${e instanceof Error?e.message:`An unknown error occurred`}`}]}}}),f.registerTool(`intlayer-extract`,{title:`Extract strings from Component`,description:`Extract strings from an existing component to be placed in a .content file close to the component. Trigger this action to make an existing component multilingual. If the component does not exist, create a normal component including text in JSX, and then trigger this tool to extract it.`,inputSchema:{file:d.union([d.string(),d.array(d.string())]).optional().describe(`List of files to extract`),outputContentDeclarations:d.string().optional().describe(`Path to output content declaration files`),configOptions:d.object({baseDir:d.string().optional(),env:d.string().optional(),envFile:d.string().optional(),override:d.object({log:d.object({prefix:d.string().optional(),verbose:d.boolean().optional()}).optional()}).optional()}).optional().describe(`Configuration options`)},annotations:{destructiveHint:!0}},async e=>{try{return await r({files:Array.isArray(e.file)?e.file:e.file?[e.file]:void 0,outputContentDeclarations:e.outputContentDeclarations,configOptions:e.configOptions}),{content:[{type:`text`,text:`Extract successful.`}]}}catch(e){return{content:[{type:`text`,text:`Extract failed: ${e instanceof Error?e.message:`An unknown error occurred`}`}]}}}),f.registerTool(`intlayer-projects-list`,{title:`List Projects`,description:`List all Intlayer projects in the directory. Search for configuration files to find all Intlayer projects.`,inputSchema:{baseDir:d.string().optional().describe(`Base directory to search from`),gitRoot:d.boolean().optional().describe(`Search from the git root directory instead of the base directory`),absolute:d.boolean().optional().describe(`Output the results as absolute paths instead of relative paths`),json:d.boolean().optional().describe(`Output the results as JSON instead of formatted text`)},annotations:{readOnlyHint:!0}},async n=>{try{let{searchDir:r,projectsPath:i}=await t({baseDir:n.baseDir,gitRoot:n.gitRoot}),a=i.map(t=>n.absolute?t:e(r,t)).map(e=>e===``?`.`:e),o=n.absolute?i:a;return{content:[{type:`text`,text:n.json?JSON.stringify(o):JSON.stringify({searchDir:r,projectsPath:o},null,2)}]}}catch(e){return{content:[{type:`text`,text:`Projects list failed: ${e instanceof Error?e.message:`An unknown error occurred`}`}]}}})};export{f as loadCLITools};
324
2
  //# sourceMappingURL=cli.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"cli.mjs","names":[],"sources":["../../../src/tools/cli.ts"],"sourcesContent":["import { relative } from 'node:path';\nimport { listProjects } from '@intlayer/chokidar/cli';\nimport {\n build,\n extract,\n fill,\n init,\n listContentDeclarationRows,\n listMissingTranslations,\n pull,\n push,\n} from '@intlayer/cli';\nimport { Locales, type LogConfig } from '@intlayer/types';\nimport type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport z from 'zod/v3';\n\ntype LoadCLITools = (server: McpServer) => Promise<void>;\n\nexport const loadCLITools: LoadCLITools = async (server) => {\n server.registerTool(\n 'intlayer-init',\n {\n title: 'Initialize Intlayer',\n description: 'Initialize Intlayer in the project',\n inputSchema: {\n projectRoot: z.string().describe('Project root directory'),\n },\n annotations: {\n destructiveHint: true,\n },\n },\n async ({ projectRoot }) => {\n try {\n await init(projectRoot);\n\n return {\n content: [\n {\n type: 'text',\n text: 'Initialization successful.',\n },\n ],\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : 'An unknown error occurred';\n return {\n content: [\n {\n type: 'text',\n text: `Initialization failed: ${errorMessage}`,\n },\n ],\n };\n }\n }\n );\n\n server.registerTool(\n 'intlayer-build',\n {\n title: 'Build Dictionaries',\n description:\n 'Build the dictionaries. List all content declarations files `.content.{ts,tsx,js,json,...}` to update the content callable using the `useIntlayer` hook.',\n inputSchema: {\n watch: z.boolean().optional().describe('Watch for changes'),\n baseDir: z.string().optional().describe('Base directory'),\n env: z.string().optional().describe('Environment'),\n envFile: z.string().optional().describe('Environment file'),\n verbose: z.boolean().optional().describe('Verbose output'),\n prefix: z.string().optional().describe('Log prefix'),\n },\n annotations: {\n destructiveHint: true,\n },\n },\n async ({ watch, baseDir, env, envFile, verbose, prefix }) => {\n try {\n const log: Partial<LogConfig> = {};\n if (verbose) {\n log.mode = 'verbose';\n }\n if (prefix) {\n log.prefix = prefix;\n }\n\n await build({\n watch,\n configOptions: {\n baseDir,\n env,\n envFile,\n override: {\n log,\n },\n },\n });\n\n return {\n content: [\n {\n type: 'text',\n text: 'Build successful.',\n },\n ],\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : 'An unknown error occurred';\n return {\n content: [\n {\n type: 'text',\n text: `Build failed: ${errorMessage}`,\n },\n ],\n };\n }\n }\n );\n\n server.registerTool(\n 'intlayer-fill',\n {\n title: 'Fill Translations',\n description:\n 'Fill the dictionaries with missing translations / review translations using Intlayer servers',\n inputSchema: {\n sourceLocale: z\n .nativeEnum(Locales.ALL_LOCALES)\n .optional()\n .describe('Source locale'),\n outputLocales: z\n .union([\n z.nativeEnum(Locales.ALL_LOCALES),\n z.array(z.nativeEnum(Locales.ALL_LOCALES)),\n ])\n .optional()\n .describe('Output locales'),\n file: z\n .union([z.string(), z.array(z.string())])\n .optional()\n .describe('File path'),\n mode: z.enum(['complete', 'review']).optional().describe('Fill mode'),\n keys: z\n .union([z.string(), z.array(z.string())])\n .optional()\n .describe('Keys to include'),\n excludedKeys: z\n .union([z.string(), z.array(z.string())])\n .optional()\n .describe('Keys to exclude'),\n pathFilter: z\n .union([z.string(), z.array(z.string())])\n .optional()\n .describe('Path filter'),\n gitOptions: z\n .object({\n gitDiff: z.boolean().optional(),\n gitDiffBase: z.string().optional(),\n gitDiffCurrent: z.string().optional(),\n uncommitted: z.boolean().optional(),\n unpushed: z.boolean().optional(),\n untracked: z.boolean().optional(),\n })\n .optional()\n .describe('Git options'),\n aiOptions: z\n .object({\n provider: z.string().optional(),\n temperature: z.number().optional(),\n model: z.string().optional(),\n apiKey: z.string().optional(),\n customPrompt: z.string().optional(),\n applicationContext: z.string().optional(),\n })\n .optional()\n .describe('AI options'),\n },\n annotations: {\n destructiveHint: true,\n },\n },\n async (props) => {\n try {\n const { gitOptions, ...rest } = props;\n const fillOptions: any = { ...rest, gitOptions: undefined };\n\n if (gitOptions) {\n const { gitDiff, uncommitted, unpushed, untracked, ...restGit } =\n gitOptions;\n const mode = [];\n if (gitDiff) mode.push('gitDiff');\n if (uncommitted) mode.push('uncommitted');\n if (unpushed) mode.push('unpushed');\n if (untracked) mode.push('untracked');\n\n fillOptions.gitOptions = { ...restGit, mode };\n }\n\n await fill(fillOptions);\n\n return {\n content: [\n {\n type: 'text',\n text: 'Fill successful.',\n },\n ],\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : 'An unknown error occurred';\n return {\n content: [\n {\n type: 'text',\n text: `Fill failed: ${errorMessage}`,\n },\n ],\n };\n }\n }\n );\n\n server.registerTool(\n 'intlayer-push',\n {\n title: 'Push Dictionaries',\n description: 'Push local dictionaries to the server',\n inputSchema: {\n deleteLocaleDictionary: z\n .boolean()\n .optional()\n .describe('Delete local dictionary after push'),\n keepLocaleDictionary: z\n .boolean()\n .optional()\n .describe('Keep local dictionary after push'),\n dictionaries: z\n .array(z.string())\n .optional()\n .describe('List of dictionaries to push'),\n gitOptions: z\n .object({\n gitDiff: z.boolean().optional(),\n gitDiffBase: z.string().optional(),\n gitDiffCurrent: z.string().optional(),\n uncommitted: z.boolean().optional(),\n unpushed: z.boolean().optional(),\n untracked: z.boolean().optional(),\n })\n .optional()\n .describe('Git options'),\n },\n annotations: {\n destructiveHint: true,\n },\n },\n async (props) => {\n try {\n const { gitOptions, ...rest } = props;\n const pushOptions: any = { ...rest, gitOptions: undefined };\n\n if (gitOptions) {\n const { gitDiff, uncommitted, unpushed, untracked, ...restGit } =\n gitOptions;\n const mode = [];\n if (gitDiff) mode.push('gitDiff');\n if (uncommitted) mode.push('uncommitted');\n if (unpushed) mode.push('unpushed');\n if (untracked) mode.push('untracked');\n\n pushOptions.gitOptions = { ...restGit, mode };\n }\n\n await push(pushOptions);\n\n return {\n content: [\n {\n type: 'text',\n text: 'Push successful.',\n },\n ],\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : 'An unknown error occurred';\n return {\n content: [\n {\n type: 'text',\n text: `Push failed: ${errorMessage}`,\n },\n ],\n };\n }\n }\n );\n\n server.registerTool(\n 'intlayer-pull',\n {\n title: 'Pull Dictionaries',\n description: 'Pull dictionaries from the CMS',\n inputSchema: {\n dictionaries: z\n .array(z.string())\n .optional()\n .describe('List of dictionaries to pull'),\n newDictionariesPath: z\n .string()\n .optional()\n .describe('Path to save new dictionaries'),\n },\n annotations: {\n destructiveHint: true,\n },\n },\n async (props) => {\n try {\n await pull(props);\n\n return {\n content: [\n {\n type: 'text',\n text: 'Pull successful.',\n },\n ],\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : 'An unknown error occurred';\n return {\n content: [\n {\n type: 'text',\n text: `Pull failed: ${errorMessage}`,\n },\n ],\n };\n }\n }\n );\n\n server.registerTool(\n 'intlayer-content-list',\n {\n title: 'List Content Declarations',\n description:\n 'List the content declaration (.content.{ts,tsx,js,json,...}) files present in the project. That files contain the multilingual content of the application and are used to build the dictionaries.',\n inputSchema: {\n configOptions: z\n .object({\n baseDir: z.string().optional(),\n env: z.string().optional(),\n envFile: z.string().optional(),\n override: z\n .object({\n log: z\n .object({\n prefix: z.string().optional(),\n verbose: z.boolean().optional(),\n })\n .optional(),\n })\n .optional(),\n })\n .optional()\n .describe('Configuration options'),\n absolute: z\n .boolean()\n .optional()\n .describe(\n 'Output the results as absolute paths instead of relative paths'\n ),\n json: z\n .boolean()\n .optional()\n .describe('Output the results as JSON instead of formatted text'),\n },\n annotations: {\n readOnlyHint: true,\n },\n },\n async (props) => {\n try {\n const rows = listContentDeclarationRows(props);\n return {\n content: [\n {\n type: 'text',\n text: props.json\n ? JSON.stringify(rows)\n : JSON.stringify(rows, null, 2),\n },\n ],\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : 'An unknown error occurred';\n return {\n content: [\n {\n type: 'text',\n text: `Content list failed: ${errorMessage}`,\n },\n ],\n };\n }\n }\n );\n\n server.registerTool(\n 'intlayer-content-test',\n {\n title: 'Test Translations',\n description:\n 'Test if there are missing translations in the content declaration files. That files contain the multilingual content of the application and are used to build the dictionaries.',\n inputSchema: {\n configOptions: z\n .object({\n baseDir: z.string().optional(),\n env: z.string().optional(),\n envFile: z.string().optional(),\n override: z\n .object({\n log: z\n .object({\n prefix: z.string().optional(),\n verbose: z.boolean().optional(),\n })\n .optional(),\n })\n .optional(),\n })\n .optional()\n .describe('Configuration options'),\n },\n annotations: {\n readOnlyHint: true,\n },\n },\n async (props) => {\n try {\n const missingTranslations = listMissingTranslations(\n props?.configOptions\n );\n return {\n content: [\n {\n type: 'text',\n text: JSON.stringify(missingTranslations, null, 2),\n },\n ],\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : 'An unknown error occurred';\n return {\n content: [\n {\n type: 'text',\n text: `Content test failed: ${errorMessage}`,\n },\n ],\n };\n }\n }\n );\n\n server.registerTool(\n 'intlayer-extract',\n {\n title: 'Extract strings from Component',\n description:\n 'Extract strings from an existing component to be placed in a .content file close to the component. Trigger this action to make an existing component multilingual. If the component does not exist, create a normal component including text in JSX, and then trigger this tool to extract it.',\n inputSchema: {\n file: z\n .union([z.string(), z.array(z.string())])\n .optional()\n .describe('List of files to extract'),\n outputContentDeclarations: z\n .string()\n .optional()\n .describe('Path to output content declaration files'),\n configOptions: z\n .object({\n baseDir: z.string().optional(),\n env: z.string().optional(),\n envFile: z.string().optional(),\n override: z\n .object({\n log: z\n .object({\n prefix: z.string().optional(),\n verbose: z.boolean().optional(),\n })\n .optional(),\n })\n .optional(),\n })\n .optional()\n .describe('Configuration options'),\n },\n annotations: {\n destructiveHint: true,\n },\n },\n async (props) => {\n try {\n await extract({\n files: Array.isArray(props.file)\n ? props.file\n : props.file\n ? [props.file]\n : undefined,\n outputContentDeclarations: props.outputContentDeclarations,\n configOptions: props.configOptions,\n });\n\n return {\n content: [\n {\n type: 'text',\n text: 'Extract successful.',\n },\n ],\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : 'An unknown error occurred';\n return {\n content: [\n {\n type: 'text',\n text: `Extract failed: ${errorMessage}`,\n },\n ],\n };\n }\n }\n );\n\n server.registerTool(\n 'intlayer-projects-list',\n {\n title: 'List Projects',\n description:\n 'List all Intlayer projects in the directory. Search for configuration files to find all Intlayer projects.',\n inputSchema: {\n baseDir: z\n .string()\n .optional()\n .describe('Base directory to search from'),\n gitRoot: z\n .boolean()\n .optional()\n .describe(\n 'Search from the git root directory instead of the base directory'\n ),\n absolute: z\n .boolean()\n .optional()\n .describe(\n 'Output the results as absolute paths instead of relative paths'\n ),\n json: z\n .boolean()\n .optional()\n .describe('Output the results as JSON instead of formatted text'),\n },\n annotations: {\n readOnlyHint: true,\n },\n },\n async (props) => {\n try {\n const { searchDir, projectsPath } = await listProjects({\n baseDir: props.baseDir,\n gitRoot: props.gitRoot,\n });\n\n // Handle absolute option similar to CLI command\n const projectsRelativePath = projectsPath\n .map((projectPath) =>\n props.absolute ? projectPath : relative(searchDir, projectPath)\n )\n .map((projectPath) => (projectPath === '' ? '.' : projectPath));\n\n const outputPaths = props.absolute\n ? projectsPath\n : projectsRelativePath;\n\n return {\n content: [\n {\n type: 'text',\n text: props.json\n ? JSON.stringify(outputPaths)\n : JSON.stringify(\n { searchDir, projectsPath: outputPaths },\n null,\n 2\n ),\n },\n ],\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : 'An unknown error occurred';\n return {\n content: [\n {\n type: 'text',\n text: `Projects list failed: ${errorMessage}`,\n },\n ],\n };\n }\n }\n );\n};\n"],"mappings":";;;;;;;AAkBA,MAAa,eAA6B,OAAO,WAAW;AAC1D,QAAO,aACL,iBACA;EACE,OAAO;EACP,aAAa;EACb,aAAa,EACX,aAAa,EAAE,QAAQ,CAAC,SAAS,yBAAyB,EAC3D;EACD,aAAa,EACX,iBAAiB,MAClB;EACF,EACD,OAAO,EAAE,kBAAkB;AACzB,MAAI;AACF,SAAM,KAAK,YAAY;AAEvB,UAAO,EACL,SAAS,CACP;IACE,MAAM;IACN,MAAM;IACP,CACF,EACF;WACM,OAAO;AAGd,UAAO,EACL,SAAS,CACP;IACE,MAAM;IACN,MAAM,0BALV,iBAAiB,QAAQ,MAAM,UAAU;IAMtC,CACF,EACF;;GAGN;AAED,QAAO,aACL,kBACA;EACE,OAAO;EACP,aACE;EACF,aAAa;GACX,OAAO,EAAE,SAAS,CAAC,UAAU,CAAC,SAAS,oBAAoB;GAC3D,SAAS,EAAE,QAAQ,CAAC,UAAU,CAAC,SAAS,iBAAiB;GACzD,KAAK,EAAE,QAAQ,CAAC,UAAU,CAAC,SAAS,cAAc;GAClD,SAAS,EAAE,QAAQ,CAAC,UAAU,CAAC,SAAS,mBAAmB;GAC3D,SAAS,EAAE,SAAS,CAAC,UAAU,CAAC,SAAS,iBAAiB;GAC1D,QAAQ,EAAE,QAAQ,CAAC,UAAU,CAAC,SAAS,aAAa;GACrD;EACD,aAAa,EACX,iBAAiB,MAClB;EACF,EACD,OAAO,EAAE,OAAO,SAAS,KAAK,SAAS,SAAS,aAAa;AAC3D,MAAI;GACF,MAAM,MAA0B,EAAE;AAClC,OAAI,QACF,KAAI,OAAO;AAEb,OAAI,OACF,KAAI,SAAS;AAGf,SAAM,MAAM;IACV;IACA,eAAe;KACb;KACA;KACA;KACA,UAAU,EACR,KACD;KACF;IACF,CAAC;AAEF,UAAO,EACL,SAAS,CACP;IACE,MAAM;IACN,MAAM;IACP,CACF,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ACtB,CAAC;AAEF,UAAO,EACL,SAAS,CACP;IACE,MAAM;IACN,MAAM;IACP,CACF,EACF;WACM,OAAO;AAGd,UAAO,EACL,SAAS,CACP;IACE,MAAM;IACN,MAAM,mBALV,iBAAiB,QAAQ,MAAM,UAAU;IAMtC,CACF,EACF;;GAGN;AAED,QAAO,aACL,0BACA;EACE,OAAO;EACP,aACE;EACF,aAAa;GACX,SAAS,EACN,QAAQ,CACR,UAAU,CACV,SAAS,gCAAgC;GAC5C,SAAS,EACN,SAAS,CACT,UAAU,CACV,SACC,mEACD;GACH,UAAU,EACP,SAAS,CACT,UAAU,CACV,SACC,iEACD;GACH,MAAM,EACH,SAAS,CACT,UAAU,CACV,SAAS,uDAAuD;GACpE;EACD,aAAa,EACX,cAAc,MACf;EACF,EACD,OAAO,UAAU;AACf,MAAI;GACF,MAAM,EAAE,WAAW,iBAAiB,MAAM,aAAa;IACrD,SAAS,MAAM;IACf,SAAS,MAAM;IAChB,CAAC;GAGF,MAAM,uBAAuB,aAC1B,KAAK,gBACJ,MAAM,WAAW,cAAc,SAAS,WAAW,YAAY,CAChE,CACA,KAAK,gBAAiB,gBAAgB,KAAK,MAAM,YAAa;GAEjE,MAAM,cAAc,MAAM,WACtB,eACA;AAEJ,UAAO,EACL,SAAS,CACP;IACE,MAAM;IACN,MAAM,MAAM,OACR,KAAK,UAAU,YAAY,GAC3B,KAAK,UACH;KAAE;KAAW,cAAc;KAAa,EACxC,MACA,EACD;IACN,CACF,EACF;WACM,OAAO;AAGd,UAAO,EACL,SAAS,CACP;IACE,MAAM;IACN,MAAM,yBALV,iBAAiB,QAAQ,MAAM,UAAU;IAMtC,CACF,EACF;;GAGN"}
1
+ {"version":3,"file":"cli.mjs","names":[],"sources":["../../../src/tools/cli.ts"],"sourcesContent":["import { relative } from 'node:path';\nimport { listProjects } from '@intlayer/chokidar/cli';\nimport {\n build,\n extract,\n fill,\n init,\n listContentDeclarationRows,\n listMissingTranslations,\n pull,\n push,\n} from '@intlayer/cli';\nimport { Locales, type LogConfig } from '@intlayer/types';\nimport type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport z from 'zod/v3';\n\ntype LoadCLITools = (server: McpServer) => Promise<void>;\n\nexport const loadCLITools: LoadCLITools = async (server) => {\n server.registerTool(\n 'intlayer-init',\n {\n title: 'Initialize Intlayer',\n description: 'Initialize Intlayer in the project',\n inputSchema: {\n projectRoot: z.string().describe('Project root directory'),\n },\n annotations: {\n destructiveHint: true,\n },\n },\n async ({ projectRoot }) => {\n try {\n await init(projectRoot);\n\n return {\n content: [\n {\n type: 'text',\n text: 'Initialization successful.',\n },\n ],\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : 'An unknown error occurred';\n return {\n content: [\n {\n type: 'text',\n text: `Initialization failed: ${errorMessage}`,\n },\n ],\n };\n }\n }\n );\n\n server.registerTool(\n 'intlayer-build',\n {\n title: 'Build Dictionaries',\n description:\n 'Build the dictionaries. List all content declarations files `.content.{ts,tsx,js,json,...}` to update the content callable using the `useIntlayer` hook.',\n inputSchema: {\n watch: z.boolean().optional().describe('Watch for changes'),\n baseDir: z.string().optional().describe('Base directory'),\n env: z.string().optional().describe('Environment'),\n envFile: z.string().optional().describe('Environment file'),\n verbose: z.boolean().optional().describe('Verbose output'),\n prefix: z.string().optional().describe('Log prefix'),\n },\n annotations: {\n destructiveHint: true,\n },\n },\n async ({ watch, baseDir, env, envFile, verbose, prefix }) => {\n try {\n const log: Partial<LogConfig> = {};\n if (verbose) {\n log.mode = 'verbose';\n }\n if (prefix) {\n log.prefix = prefix;\n }\n\n await build({\n watch,\n configOptions: {\n baseDir,\n env,\n envFile,\n override: {\n log,\n },\n },\n });\n\n return {\n content: [\n {\n type: 'text',\n text: 'Build successful.',\n },\n ],\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : 'An unknown error occurred';\n return {\n content: [\n {\n type: 'text',\n text: `Build failed: ${errorMessage}`,\n },\n ],\n };\n }\n }\n );\n\n server.registerTool(\n 'intlayer-fill',\n {\n title: 'Fill Translations',\n description:\n 'Fill the dictionaries with missing translations / review translations using Intlayer servers',\n inputSchema: {\n sourceLocale: z\n .nativeEnum(Locales.ALL_LOCALES)\n .optional()\n .describe('Source locale'),\n outputLocales: z\n .union([\n z.nativeEnum(Locales.ALL_LOCALES),\n z.array(z.nativeEnum(Locales.ALL_LOCALES)),\n ])\n .optional()\n .describe('Output locales'),\n file: z\n .union([z.string(), z.array(z.string())])\n .optional()\n .describe('File path'),\n mode: z.enum(['complete', 'review']).optional().describe('Fill mode'),\n keys: z\n .union([z.string(), z.array(z.string())])\n .optional()\n .describe('Keys to include'),\n excludedKeys: z\n .union([z.string(), z.array(z.string())])\n .optional()\n .describe('Keys to exclude'),\n pathFilter: z\n .union([z.string(), z.array(z.string())])\n .optional()\n .describe('Path filter'),\n gitOptions: z\n .object({\n gitDiff: z.boolean().optional(),\n gitDiffBase: z.string().optional(),\n gitDiffCurrent: z.string().optional(),\n uncommitted: z.boolean().optional(),\n unpushed: z.boolean().optional(),\n untracked: z.boolean().optional(),\n })\n .optional()\n .describe('Git options'),\n aiOptions: z\n .object({\n provider: z.string().optional(),\n temperature: z.number().optional(),\n model: z.string().optional(),\n apiKey: z.string().optional(),\n customPrompt: z.string().optional(),\n applicationContext: z.string().optional(),\n })\n .optional()\n .describe('AI options'),\n },\n annotations: {\n destructiveHint: true,\n },\n },\n async (props) => {\n try {\n const { gitOptions, ...rest } = props;\n const fillOptions: any = { ...rest, gitOptions: undefined };\n\n if (gitOptions) {\n const { gitDiff, uncommitted, unpushed, untracked, ...restGit } =\n gitOptions;\n const mode = [];\n if (gitDiff) mode.push('gitDiff');\n if (uncommitted) mode.push('uncommitted');\n if (unpushed) mode.push('unpushed');\n if (untracked) mode.push('untracked');\n\n fillOptions.gitOptions = { ...restGit, mode };\n }\n\n await fill(fillOptions);\n\n return {\n content: [\n {\n type: 'text',\n text: 'Fill successful.',\n },\n ],\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : 'An unknown error occurred';\n return {\n content: [\n {\n type: 'text',\n text: `Fill failed: ${errorMessage}`,\n },\n ],\n };\n }\n }\n );\n\n server.registerTool(\n 'intlayer-push',\n {\n title: 'Push Dictionaries',\n description: 'Push local dictionaries to the server',\n inputSchema: {\n deleteLocaleDictionary: z\n .boolean()\n .optional()\n .describe('Delete local dictionary after push'),\n keepLocaleDictionary: z\n .boolean()\n .optional()\n .describe('Keep local dictionary after push'),\n dictionaries: z\n .array(z.string())\n .optional()\n .describe('List of dictionaries to push'),\n gitOptions: z\n .object({\n gitDiff: z.boolean().optional(),\n gitDiffBase: z.string().optional(),\n gitDiffCurrent: z.string().optional(),\n uncommitted: z.boolean().optional(),\n unpushed: z.boolean().optional(),\n untracked: z.boolean().optional(),\n })\n .optional()\n .describe('Git options'),\n },\n annotations: {\n destructiveHint: true,\n },\n },\n async (props) => {\n try {\n const { gitOptions, ...rest } = props;\n const pushOptions: any = { ...rest, gitOptions: undefined };\n\n if (gitOptions) {\n const { gitDiff, uncommitted, unpushed, untracked, ...restGit } =\n gitOptions;\n const mode = [];\n if (gitDiff) mode.push('gitDiff');\n if (uncommitted) mode.push('uncommitted');\n if (unpushed) mode.push('unpushed');\n if (untracked) mode.push('untracked');\n\n pushOptions.gitOptions = { ...restGit, mode };\n }\n\n await push(pushOptions);\n\n return {\n content: [\n {\n type: 'text',\n text: 'Push successful.',\n },\n ],\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : 'An unknown error occurred';\n return {\n content: [\n {\n type: 'text',\n text: `Push failed: ${errorMessage}`,\n },\n ],\n };\n }\n }\n );\n\n server.registerTool(\n 'intlayer-pull',\n {\n title: 'Pull Dictionaries',\n description: 'Pull dictionaries from the CMS',\n inputSchema: {\n dictionaries: z\n .array(z.string())\n .optional()\n .describe('List of dictionaries to pull'),\n newDictionariesPath: z\n .string()\n .optional()\n .describe('Path to save new dictionaries'),\n },\n annotations: {\n destructiveHint: true,\n },\n },\n async (props) => {\n try {\n await pull(props);\n\n return {\n content: [\n {\n type: 'text',\n text: 'Pull successful.',\n },\n ],\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : 'An unknown error occurred';\n return {\n content: [\n {\n type: 'text',\n text: `Pull failed: ${errorMessage}`,\n },\n ],\n };\n }\n }\n );\n\n server.registerTool(\n 'intlayer-content-list',\n {\n title: 'List Content Declarations',\n description:\n 'List the content declaration (.content.{ts,tsx,js,json,...}) files present in the project. That files contain the multilingual content of the application and are used to build the dictionaries.',\n inputSchema: {\n configOptions: z\n .object({\n baseDir: z.string().optional(),\n env: z.string().optional(),\n envFile: z.string().optional(),\n override: z\n .object({\n log: z\n .object({\n prefix: z.string().optional(),\n verbose: z.boolean().optional(),\n })\n .optional(),\n })\n .optional(),\n })\n .optional()\n .describe('Configuration options'),\n absolute: z\n .boolean()\n .optional()\n .describe(\n 'Output the results as absolute paths instead of relative paths'\n ),\n json: z\n .boolean()\n .optional()\n .describe('Output the results as JSON instead of formatted text'),\n },\n annotations: {\n readOnlyHint: true,\n },\n },\n async (props) => {\n try {\n const rows = listContentDeclarationRows(props);\n return {\n content: [\n {\n type: 'text',\n text: props.json\n ? JSON.stringify(rows)\n : JSON.stringify(rows, null, 2),\n },\n ],\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : 'An unknown error occurred';\n return {\n content: [\n {\n type: 'text',\n text: `Content list failed: ${errorMessage}`,\n },\n ],\n };\n }\n }\n );\n\n server.registerTool(\n 'intlayer-content-test',\n {\n title: 'Test Translations',\n description:\n 'Test if there are missing translations in the content declaration files. That files contain the multilingual content of the application and are used to build the dictionaries.',\n inputSchema: {\n configOptions: z\n .object({\n baseDir: z.string().optional(),\n env: z.string().optional(),\n envFile: z.string().optional(),\n override: z\n .object({\n log: z\n .object({\n prefix: z.string().optional(),\n verbose: z.boolean().optional(),\n })\n .optional(),\n })\n .optional(),\n })\n .optional()\n .describe('Configuration options'),\n },\n annotations: {\n readOnlyHint: true,\n },\n },\n async (props) => {\n try {\n const missingTranslations = listMissingTranslations(\n props?.configOptions\n );\n return {\n content: [\n {\n type: 'text',\n text: JSON.stringify(missingTranslations, null, 2),\n },\n ],\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : 'An unknown error occurred';\n return {\n content: [\n {\n type: 'text',\n text: `Content test failed: ${errorMessage}`,\n },\n ],\n };\n }\n }\n );\n\n server.registerTool(\n 'intlayer-extract',\n {\n title: 'Extract strings from Component',\n description:\n 'Extract strings from an existing component to be placed in a .content file close to the component. Trigger this action to make an existing component multilingual. If the component does not exist, create a normal component including text in JSX, and then trigger this tool to extract it.',\n inputSchema: {\n file: z\n .union([z.string(), z.array(z.string())])\n .optional()\n .describe('List of files to extract'),\n outputContentDeclarations: z\n .string()\n .optional()\n .describe('Path to output content declaration files'),\n configOptions: z\n .object({\n baseDir: z.string().optional(),\n env: z.string().optional(),\n envFile: z.string().optional(),\n override: z\n .object({\n log: z\n .object({\n prefix: z.string().optional(),\n verbose: z.boolean().optional(),\n })\n .optional(),\n })\n .optional(),\n })\n .optional()\n .describe('Configuration options'),\n },\n annotations: {\n destructiveHint: true,\n },\n },\n async (props) => {\n try {\n await extract({\n files: Array.isArray(props.file)\n ? props.file\n : props.file\n ? [props.file]\n : undefined,\n outputContentDeclarations: props.outputContentDeclarations,\n configOptions: props.configOptions,\n });\n\n return {\n content: [\n {\n type: 'text',\n text: 'Extract successful.',\n },\n ],\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : 'An unknown error occurred';\n return {\n content: [\n {\n type: 'text',\n text: `Extract failed: ${errorMessage}`,\n },\n ],\n };\n }\n }\n );\n\n server.registerTool(\n 'intlayer-projects-list',\n {\n title: 'List Projects',\n description:\n 'List all Intlayer projects in the directory. Search for configuration files to find all Intlayer projects.',\n inputSchema: {\n baseDir: z\n .string()\n .optional()\n .describe('Base directory to search from'),\n gitRoot: z\n .boolean()\n .optional()\n .describe(\n 'Search from the git root directory instead of the base directory'\n ),\n absolute: z\n .boolean()\n .optional()\n .describe(\n 'Output the results as absolute paths instead of relative paths'\n ),\n json: z\n .boolean()\n .optional()\n .describe('Output the results as JSON instead of formatted text'),\n },\n annotations: {\n readOnlyHint: true,\n },\n },\n async (props) => {\n try {\n const { searchDir, projectsPath } = await listProjects({\n baseDir: props.baseDir,\n gitRoot: props.gitRoot,\n });\n\n // Handle absolute option similar to CLI command\n const projectsRelativePath = projectsPath\n .map((projectPath) =>\n props.absolute ? projectPath : relative(searchDir, projectPath)\n )\n .map((projectPath) => (projectPath === '' ? '.' : projectPath));\n\n const outputPaths = props.absolute\n ? projectsPath\n : projectsRelativePath;\n\n return {\n content: [\n {\n type: 'text',\n text: props.json\n ? JSON.stringify(outputPaths)\n : JSON.stringify(\n { searchDir, projectsPath: outputPaths },\n null,\n 2\n ),\n },\n ],\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : 'An unknown error occurred';\n return {\n content: [\n {\n type: 'text',\n text: `Projects list failed: ${errorMessage}`,\n },\n ],\n };\n }\n }\n );\n};\n"],"mappings":"mTAkBA,MAAa,EAA6B,KAAO,IAAW,CAC1D,EAAO,aACL,gBACA,CACE,MAAO,sBACP,YAAa,qCACb,YAAa,CACX,YAAa,EAAE,QAAQ,CAAC,SAAS,yBAAyB,CAC3D,CACD,YAAa,CACX,gBAAiB,GAClB,CACF,CACD,MAAO,CAAE,iBAAkB,CACzB,GAAI,CAGF,OAFA,MAAM,EAAK,EAAY,CAEhB,CACL,QAAS,CACP,CACE,KAAM,OACN,KAAM,6BACP,CACF,CACF,OACM,EAAO,CAGd,MAAO,CACL,QAAS,CACP,CACE,KAAM,OACN,KAAM,0BALV,aAAiB,MAAQ,EAAM,QAAU,8BAMtC,CACF,CACF,GAGN,CAED,EAAO,aACL,iBACA,CACE,MAAO,qBACP,YACE,2JACF,YAAa,CACX,MAAO,EAAE,SAAS,CAAC,UAAU,CAAC,SAAS,oBAAoB,CAC3D,QAAS,EAAE,QAAQ,CAAC,UAAU,CAAC,SA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AAM,EAAa,CAE3D,EAAc,EAAM,SACtB,EACA,EAEJ,MAAO,CACL,QAAS,CACP,CACE,KAAM,OACN,KAAM,EAAM,KACR,KAAK,UAAU,EAAY,CAC3B,KAAK,UACH,CAAE,YAAW,aAAc,EAAa,CACxC,KACA,EACD,CACN,CACF,CACF,OACM,EAAO,CAGd,MAAO,CACL,QAAS,CACP,CACE,KAAM,OACN,KAAM,yBALV,aAAiB,MAAQ,EAAM,QAAU,8BAMtC,CACF,CACF,GAGN"}
@@ -1,108 +1,3 @@
1
- import z from "zod/v3";
2
- import { getSearchAPI } from "@intlayer/api";
3
- import { getDoc, getDocBySlug, getDocMetadataRecord, getDocsKeys } from "@intlayer/docs";
4
-
5
- //#region src/tools/docs.ts
6
- const loadDocsTools = async (server) => {
7
- const docsKeys = getDocsKeys();
8
- server.registerTool("get-doc-list", {
9
- title: "Get Doc List",
10
- description: "Get the list of docs names and their metadata to get more details about what doc to retrieve",
11
- inputSchema: {},
12
- annotations: { readOnlyHint: true }
13
- }, async () => {
14
- try {
15
- const docsMetadataRecord = await getDocMetadataRecord();
16
- return { content: [{
17
- type: "text",
18
- text: JSON.stringify(docsMetadataRecord, null, 2)
19
- }] };
20
- } catch (error) {
21
- return { content: [{
22
- type: "text",
23
- text: `Get doc list failed: ${error instanceof Error ? error.message : "An unknown error occurred"}`
24
- }] };
25
- }
26
- });
27
- server.registerTool("get-doc", {
28
- title: "Get Doc by Key",
29
- description: "Get a doc by his key. Example: `./docs/en/getting-started.md`. List all docs metadata first to get more details about what doc key to retrieve.",
30
- inputSchema: { docKey: z.enum(docsKeys) },
31
- annotations: { readOnlyHint: true }
32
- }, async ({ docKey }) => {
33
- try {
34
- return { content: [{
35
- type: "text",
36
- text: await getDoc(docKey)
37
- }] };
38
- } catch (error) {
39
- return { content: [{
40
- type: "text",
41
- text: `Get doc failed: ${error instanceof Error ? error.message : "An unknown error occurred"}`
42
- }] };
43
- }
44
- });
45
- server.registerTool("get-doc-by-slug", {
46
- title: "Get Doc by Slug",
47
- description: "Get an array of docs by their slugs. If not slug is provided, return all docs (1.2Mb). List all docs metadata first to get more details about what doc to retrieve.",
48
- inputSchema: {
49
- slug: z.union([z.string(), z.array(z.string())]).optional().describe("Slug of the docs. If not provided, return all docs. If not provided, return all docs."),
50
- strict: z.boolean().optional().describe("Strict mode - only return docs that match all slugs, by excluding additional slugs")
51
- },
52
- annotations: { readOnlyHint: true }
53
- }, async ({ slug, strict }) => {
54
- try {
55
- return { content: (await getDocBySlug(slug ?? [], void 0, strict)).map((d) => ({
56
- type: "text",
57
- text: d
58
- })) };
59
- } catch (error) {
60
- return { content: [{
61
- type: "text",
62
- text: `Get doc by slug failed: ${error instanceof Error ? error.message : "An unknown error occurred"}`
63
- }] };
64
- }
65
- });
66
- server.registerTool("fetch-doc-chunks", {
67
- title: "Fetch Doc Chunks",
68
- description: "Fetch related doc chunks using keywords or questions. This tool will return the most relevant chunks of documentation based on the input query.",
69
- inputSchema: {
70
- query: z.string().describe("The keywords or question to search for"),
71
- limit: z.number().optional().describe("The number of chunks to retrieve (default: 10)")
72
- },
73
- annotations: { readOnlyHint: true }
74
- }, async ({ query, limit }) => {
75
- try {
76
- const { searchDoc } = getSearchAPI();
77
- const response = await searchDoc({
78
- input: query,
79
- limit: limit?.toString(),
80
- returnContent: "true"
81
- });
82
- if (!response.data || !Array.isArray(response.data)) return { content: [{
83
- type: "text",
84
- text: "No relevant chunks found."
85
- }] };
86
- return { content: response.data.map((chunk) => ({
87
- type: "text",
88
- text: [
89
- `File: ${chunk.fileKey}`,
90
- `Title: ${chunk.docName}`,
91
- `URL: ${chunk.docUrl}`,
92
- `Chunk: ${chunk.chunkNumber}`,
93
- `Content:`,
94
- chunk.content
95
- ].join("\n")
96
- })) };
97
- } catch (error) {
98
- return { content: [{
99
- type: "text",
100
- text: `Fetch doc chunks failed: ${error instanceof Error ? error.message : "An unknown error occurred"}`
101
- }] };
102
- }
103
- });
104
- };
105
-
106
- //#endregion
107
- export { loadDocsTools };
1
+ import e from"zod/v3";import{getSearchAPI as t}from"@intlayer/api";import{getDoc as n,getDocBySlug as r,getDocMetadataRecord as i,getDocsKeys as a}from"@intlayer/docs";const o=async o=>{let s=a();o.registerTool(`get-doc-list`,{title:`Get Doc List`,description:`Get the list of docs names and their metadata to get more details about what doc to retrieve`,inputSchema:{},annotations:{readOnlyHint:!0}},async()=>{try{let e=await i();return{content:[{type:`text`,text:JSON.stringify(e,null,2)}]}}catch(e){return{content:[{type:`text`,text:`Get doc list failed: ${e instanceof Error?e.message:`An unknown error occurred`}`}]}}}),o.registerTool(`get-doc`,{title:`Get Doc by Key`,description:"Get a doc by his key. Example: `./docs/en/getting-started.md`. List all docs metadata first to get more details about what doc key to retrieve.",inputSchema:{docKey:e.enum(s)},annotations:{readOnlyHint:!0}},async({docKey:e})=>{try{return{content:[{type:`text`,text:await n(e)}]}}catch(e){return{content:[{type:`text`,text:`Get doc failed: ${e instanceof Error?e.message:`An unknown error occurred`}`}]}}}),o.registerTool(`get-doc-by-slug`,{title:`Get Doc by Slug`,description:`Get an array of docs by their slugs. If not slug is provided, return all docs (1.2Mb). List all docs metadata first to get more details about what doc to retrieve.`,inputSchema:{slug:e.union([e.string(),e.array(e.string())]).optional().describe(`Slug of the docs. If not provided, return all docs. If not provided, return all docs.`),strict:e.boolean().optional().describe(`Strict mode - only return docs that match all slugs, by excluding additional slugs`)},annotations:{readOnlyHint:!0}},async({slug:e,strict:t})=>{try{return{content:(await r(e??[],void 0,t)).map(e=>({type:`text`,text:e}))}}catch(e){return{content:[{type:`text`,text:`Get doc by slug failed: ${e instanceof Error?e.message:`An unknown error occurred`}`}]}}}),o.registerTool(`fetch-doc-chunks`,{title:`Fetch Doc Chunks`,description:`Fetch related doc chunks using keywords or questions. This tool will return the most relevant chunks of documentation based on the input query.`,inputSchema:{query:e.string().describe(`The keywords or question to search for`),limit:e.number().optional().describe(`The number of chunks to retrieve (default: 10)`)},annotations:{readOnlyHint:!0}},async({query:e,limit:n})=>{try{let{searchDoc:r}=t(),i=await r({input:e,limit:n?.toString(),returnContent:`true`});return!i.data||!Array.isArray(i.data)?{content:[{type:`text`,text:`No relevant chunks found.`}]}:{content:i.data.map(e=>({type:`text`,text:[`File: ${e.fileKey}`,`Title: ${e.docName}`,`URL: ${e.docUrl}`,`Chunk: ${e.chunkNumber}`,`Content:`,e.content].join(`
2
+ `)}))}}catch(e){return{content:[{type:`text`,text:`Fetch doc chunks failed: ${e instanceof Error?e.message:`An unknown error occurred`}`}]}}})};export{o as loadDocsTools};
108
3
  //# sourceMappingURL=docs.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"docs.mjs","names":[],"sources":["../../../src/tools/docs.ts"],"sourcesContent":["import { getSearchAPI } from '@intlayer/api';\nimport type { DocKey } from '@intlayer/docs';\nimport {\n getDoc,\n getDocBySlug,\n getDocMetadataRecord,\n getDocsKeys,\n} from '@intlayer/docs';\nimport type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport z from 'zod/v3';\n\ntype LoadDocsTools = (server: McpServer) => Promise<void>;\n\nexport const loadDocsTools: LoadDocsTools = async (server) => {\n const docsKeys = getDocsKeys();\n\n server.registerTool(\n 'get-doc-list',\n {\n title: 'Get Doc List',\n description:\n 'Get the list of docs names and their metadata to get more details about what doc to retrieve',\n inputSchema: {},\n annotations: {\n readOnlyHint: true,\n },\n },\n async () => {\n try {\n const docsMetadataRecord = await getDocMetadataRecord();\n\n return {\n content: [\n {\n type: 'text',\n text: JSON.stringify(docsMetadataRecord, null, 2),\n },\n ],\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : 'An unknown error occurred';\n return {\n content: [\n { type: 'text', text: `Get doc list failed: ${errorMessage}` },\n ],\n };\n }\n }\n );\n\n server.registerTool(\n 'get-doc',\n {\n title: 'Get Doc by Key',\n description:\n 'Get a doc by his key. Example: `./docs/en/getting-started.md`. List all docs metadata first to get more details about what doc key to retrieve.',\n inputSchema: {\n docKey: z.enum(docsKeys as [string, ...string[]]),\n },\n annotations: {\n readOnlyHint: true,\n },\n },\n async ({ docKey }) => {\n try {\n const doc = await getDoc(docKey as DocKey);\n return {\n content: [{ type: 'text', text: doc }],\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : 'An unknown error occurred';\n return {\n content: [{ type: 'text', text: `Get doc failed: ${errorMessage}` }],\n };\n }\n }\n );\n\n server.registerTool(\n 'get-doc-by-slug',\n {\n title: 'Get Doc by Slug',\n description:\n 'Get an array of docs by their slugs. If not slug is provided, return all docs (1.2Mb). List all docs metadata first to get more details about what doc to retrieve.',\n inputSchema: {\n slug: z\n .union([z.string(), z.array(z.string())])\n .optional()\n .describe(\n 'Slug of the docs. If not provided, return all docs. If not provided, return all docs.'\n ),\n strict: z\n .boolean()\n .optional()\n .describe(\n 'Strict mode - only return docs that match all slugs, by excluding additional slugs'\n ),\n },\n annotations: {\n readOnlyHint: true,\n },\n },\n async ({ slug, strict }) => {\n try {\n const doc = await getDocBySlug(slug ?? [], undefined, strict);\n return {\n content: doc.map((d) => ({ type: 'text', text: d })),\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : 'An unknown error occurred';\n return {\n content: [\n { type: 'text', text: `Get doc by slug failed: ${errorMessage}` },\n ],\n };\n }\n }\n );\n\n server.registerTool(\n 'fetch-doc-chunks',\n {\n title: 'Fetch Doc Chunks',\n description:\n 'Fetch related doc chunks using keywords or questions. This tool will return the most relevant chunks of documentation based on the input query.',\n inputSchema: {\n query: z.string().describe('The keywords or question to search for'),\n limit: z\n .number()\n .optional()\n .describe('The number of chunks to retrieve (default: 10)'),\n },\n annotations: {\n readOnlyHint: true,\n },\n },\n async ({ query, limit }) => {\n try {\n const { searchDoc } = getSearchAPI();\n const response = await searchDoc({\n input: query,\n limit: limit?.toString(),\n returnContent: 'true',\n });\n\n if (!response.data || !Array.isArray(response.data)) {\n return {\n content: [{ type: 'text', text: 'No relevant chunks found.' }],\n };\n }\n\n const chunks = response.data;\n\n return {\n content: chunks.map((chunk: any) => ({\n type: 'text',\n text: [\n `File: ${chunk.fileKey}`,\n `Title: ${chunk.docName}`,\n `URL: ${chunk.docUrl}`,\n `Chunk: ${chunk.chunkNumber}`,\n `Content:`,\n chunk.content,\n ].join('\\n'),\n })),\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : 'An unknown error occurred';\n return {\n content: [\n { type: 'text', text: `Fetch doc chunks failed: ${errorMessage}` },\n ],\n };\n }\n }\n );\n};\n"],"mappings":";;;;;AAaA,MAAa,gBAA+B,OAAO,WAAW;CAC5D,MAAM,WAAW,aAAa;AAE9B,QAAO,aACL,gBACA;EACE,OAAO;EACP,aACE;EACF,aAAa,EAAE;EACf,aAAa,EACX,cAAc,MACf;EACF,EACD,YAAY;AACV,MAAI;GACF,MAAM,qBAAqB,MAAM,sBAAsB;AAEvD,UAAO,EACL,SAAS,CACP;IACE,MAAM;IACN,MAAM,KAAK,UAAU,oBAAoB,MAAM,EAAE;IAClD,CACF,EACF;WACM,OAAO;AAGd,UAAO,EACL,SAAS,CACP;IAAE,MAAM;IAAQ,MAAM,wBAHxB,iBAAiB,QAAQ,MAAM,UAAU;IAGuB,CAC/D,EACF;;GAGN;AAED,QAAO,aACL,WACA;EACE,OAAO;EACP,aACE;EACF,aAAa,EACX,QAAQ,EAAE,KAAK,SAAkC,EAClD;EACD,aAAa,EACX,cAAc,MACf;EACF,EACD,OAAO,EAAE,aAAa;AACpB,MAAI;AAEF,UAAO,EACL,SAAS,CAAC;IAAE,MAAM;IAAQ,MAFhB,MAAM,OAAO,OAAiB;IAEH,CAAC,EACvC;WACM,OAAO;AAGd,UAAO,EACL,SAAS,CAAC;IAAE,MAAM;IAAQ,MAAM,mBAFhC,iBAAiB,QAAQ,MAAM,UAAU;IAE0B,CAAC,EACrE;;GAGN;AAED,QAAO,aACL,mBACA;EACE,OAAO;EACP,aACE;EACF,aAAa;GACX,MAAM,EACH,MAAM,CAAC,EAAE,QAAQ,EAAE,EAAE,MAAM,EAAE,QAAQ,C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;;GAGN"}
1
+ {"version":3,"file":"docs.mjs","names":[],"sources":["../../../src/tools/docs.ts"],"sourcesContent":["import { getSearchAPI } from '@intlayer/api';\nimport type { DocKey } from '@intlayer/docs';\nimport {\n getDoc,\n getDocBySlug,\n getDocMetadataRecord,\n getDocsKeys,\n} from '@intlayer/docs';\nimport type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport z from 'zod/v3';\n\ntype LoadDocsTools = (server: McpServer) => Promise<void>;\n\nexport const loadDocsTools: LoadDocsTools = async (server) => {\n const docsKeys = getDocsKeys();\n\n server.registerTool(\n 'get-doc-list',\n {\n title: 'Get Doc List',\n description:\n 'Get the list of docs names and their metadata to get more details about what doc to retrieve',\n inputSchema: {},\n annotations: {\n readOnlyHint: true,\n },\n },\n async () => {\n try {\n const docsMetadataRecord = await getDocMetadataRecord();\n\n return {\n content: [\n {\n type: 'text',\n text: JSON.stringify(docsMetadataRecord, null, 2),\n },\n ],\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : 'An unknown error occurred';\n return {\n content: [\n { type: 'text', text: `Get doc list failed: ${errorMessage}` },\n ],\n };\n }\n }\n );\n\n server.registerTool(\n 'get-doc',\n {\n title: 'Get Doc by Key',\n description:\n 'Get a doc by his key. Example: `./docs/en/getting-started.md`. List all docs metadata first to get more details about what doc key to retrieve.',\n inputSchema: {\n docKey: z.enum(docsKeys as [string, ...string[]]),\n },\n annotations: {\n readOnlyHint: true,\n },\n },\n async ({ docKey }) => {\n try {\n const doc = await getDoc(docKey as DocKey);\n return {\n content: [{ type: 'text', text: doc }],\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : 'An unknown error occurred';\n return {\n content: [{ type: 'text', text: `Get doc failed: ${errorMessage}` }],\n };\n }\n }\n );\n\n server.registerTool(\n 'get-doc-by-slug',\n {\n title: 'Get Doc by Slug',\n description:\n 'Get an array of docs by their slugs. If not slug is provided, return all docs (1.2Mb). List all docs metadata first to get more details about what doc to retrieve.',\n inputSchema: {\n slug: z\n .union([z.string(), z.array(z.string())])\n .optional()\n .describe(\n 'Slug of the docs. If not provided, return all docs. If not provided, return all docs.'\n ),\n strict: z\n .boolean()\n .optional()\n .describe(\n 'Strict mode - only return docs that match all slugs, by excluding additional slugs'\n ),\n },\n annotations: {\n readOnlyHint: true,\n },\n },\n async ({ slug, strict }) => {\n try {\n const doc = await getDocBySlug(slug ?? [], undefined, strict);\n return {\n content: doc.map((d) => ({ type: 'text', text: d })),\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : 'An unknown error occurred';\n return {\n content: [\n { type: 'text', text: `Get doc by slug failed: ${errorMessage}` },\n ],\n };\n }\n }\n );\n\n server.registerTool(\n 'fetch-doc-chunks',\n {\n title: 'Fetch Doc Chunks',\n description:\n 'Fetch related doc chunks using keywords or questions. This tool will return the most relevant chunks of documentation based on the input query.',\n inputSchema: {\n query: z.string().describe('The keywords or question to search for'),\n limit: z\n .number()\n .optional()\n .describe('The number of chunks to retrieve (default: 10)'),\n },\n annotations: {\n readOnlyHint: true,\n },\n },\n async ({ query, limit }) => {\n try {\n const { searchDoc } = getSearchAPI();\n const response = await searchDoc({\n input: query,\n limit: limit?.toString(),\n returnContent: 'true',\n });\n\n if (!response.data || !Array.isArray(response.data)) {\n return {\n content: [{ type: 'text', text: 'No relevant chunks found.' }],\n };\n }\n\n const chunks = response.data;\n\n return {\n content: chunks.map((chunk: any) => ({\n type: 'text',\n text: [\n `File: ${chunk.fileKey}`,\n `Title: ${chunk.docName}`,\n `URL: ${chunk.docUrl}`,\n `Chunk: ${chunk.chunkNumber}`,\n `Content:`,\n chunk.content,\n ].join('\\n'),\n })),\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : 'An unknown error occurred';\n return {\n content: [\n { type: 'text', text: `Fetch doc chunks failed: ${errorMessage}` },\n ],\n };\n }\n }\n );\n};\n"],"mappings":"wKAaA,MAAa,EAA+B,KAAO,IAAW,CAC5D,IAAM,EAAW,GAAa,CAE9B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