@xano/developer-mcp 2.0.5 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -224,9 +224,12 @@ console.log(`${dirResult.valid_files}/${dirResult.total_files} files valid`);
224
224
  ```typescript
225
225
  import { xanoscriptDocs } from '@xano/developer-mcp';
226
226
 
227
- // Get overview (README)
228
- const overview = xanoscriptDocs();
229
- console.log(overview.documentation);
227
+ // Get the compact topic index (the no-arg default; ~4KB / ~1K tokens)
228
+ const index = xanoscriptDocs();
229
+ console.log(index.documentation);
230
+
231
+ // Get the full prose overview (the previous no-arg default)
232
+ const overview = xanoscriptDocs({ topic: 'readme' });
230
233
 
231
234
  // Get specific topic
232
235
  const syntaxDocs = xanoscriptDocs({ topic: 'syntax' });
@@ -236,9 +239,6 @@ const apiDocs = xanoscriptDocs({ file_path: 'api/users/create_post.xs' });
236
239
 
237
240
  // Get compact quick reference
238
241
  const quickRef = xanoscriptDocs({ topic: 'database', mode: 'quick_reference' });
239
-
240
- // Get topic index with sizes
241
- const index = xanoscriptDocs({ mode: 'index' });
242
242
  ```
243
243
 
244
244
  ### Get Meta API Documentation
@@ -360,7 +360,7 @@ xano_validate_xanoscript({ directory: "src", pattern: "api/**/*.xs" })
360
360
 
361
361
  ### 2. `xano_xanoscript_docs`
362
362
 
363
- Retrieves XanoScript programming language documentation with context-aware support.
363
+ Retrieves XanoScript programming language documentation with context-aware support. Called with no parameters, it returns a compact topic index (~4KB / ~1K tokens) for orientation; use `topic='readme'` for the full prose overview, or `topic=`/`file_path=` to drill in.
364
364
 
365
365
  **Parameters:**
366
366
  | Parameter | Type | Required | Description |
@@ -368,7 +368,7 @@ Retrieves XanoScript programming language documentation with context-aware suppo
368
368
  | `topic` | string | No | Specific documentation topic to retrieve |
369
369
  | `file_path` | string | No | File path being edited for context-aware docs (e.g., `api/users/create_post.xs`) |
370
370
  | `mode` | string | No | `full` (default), `quick_reference` for compact syntax reference, or `index` for topic listing with sizes |
371
- | `tier` | string | No | Pre-packaged documentation tier for context-limited models: `survival` (~800 tokens) or `working` (~3500 tokens). Overrides topic/file_path/mode when set |
371
+ | `tier` | string | No | Pre-packaged documentation tier for context-limited models: `survival` (~1.2K tokens) or `working` (~4.4K tokens). Overrides topic/file_path/mode when set |
372
372
  | `max_tokens` | number | No | Maximum estimated token budget. Loads topics in priority order until budget is reached. Helps prevent context overflow for small-window models |
373
373
  | `exclude_topics` | string[] | No | Topic names to exclude from `file_path` results (e.g., topics already loaded) |
374
374
 
@@ -376,8 +376,8 @@ Retrieves XanoScript programming language documentation with context-aware suppo
376
376
 
377
377
  | Topic | Description |
378
378
  |-------|-------------|
379
- | `survival` | Minimal syntax survival kit (~3KB, ~800 tokens) for models with <16K context |
380
- | `working` | Complete working reference (~12KB, ~3500 tokens) for models with 16-64K context |
379
+ | `survival` | Minimal syntax survival kit (~5KB, ~1.2K tokens) for models with <16K context — reach via `tier='survival'` |
380
+ | `working` | Complete working reference (~17KB, ~4.4K tokens) for models with 16-64K context — reach via `tier='working'` |
381
381
  | `readme` | XanoScript overview, workspace structure, and quick reference |
382
382
  | `essentials` | Common patterns, quick reference, and common mistakes to avoid |
383
383
  | `syntax` | Expressions, operators, and filters for all XanoScript code |
@@ -415,13 +415,16 @@ Retrieves XanoScript programming language documentation with context-aware suppo
415
415
 
416
416
  **Examples:**
417
417
  ```
418
- // Get overview
418
+ // Get the compact topic index (no-arg default)
419
419
  xano_xanoscript_docs()
420
420
 
421
- // Get survival kit for small context models (~800 tokens)
421
+ // Get the full prose overview (previous no-arg default)
422
+ xano_xanoscript_docs({ topic: "readme" })
423
+
424
+ // Get survival kit for small context models (~1.2K tokens)
422
425
  xano_xanoscript_docs({ tier: "survival" })
423
426
 
424
- // Get working reference for medium context models (~3500 tokens)
427
+ // Get working reference for medium context models (~4.4K tokens)
425
428
  xano_xanoscript_docs({ tier: "working" })
426
429
 
427
430
  // Get essentials (recommended first stop)
@@ -563,8 +566,8 @@ The server also exposes XanoScript documentation as MCP resources for direct acc
563
566
 
564
567
  | Resource URI | Description |
565
568
  |--------------|-------------|
566
- | `xanoscript://docs/survival` | Minimal syntax survival kit (~800 tokens) |
567
- | `xanoscript://docs/working` | Complete working reference (~3500 tokens) |
569
+ | `xanoscript://docs/survival` | Minimal syntax survival kit (~1.2K tokens) |
570
+ | `xanoscript://docs/working` | Complete working reference (~4.4K tokens) |
568
571
  | `xanoscript://docs/readme` | Overview and quick reference |
569
572
  | `xanoscript://docs/essentials` | Common patterns, quick reference, and common mistakes to avoid |
570
573
  | `xanoscript://docs/syntax` | Expressions, operators, and filters |
@@ -35,9 +35,7 @@ export declare const toolSpecs: {
35
35
  warnings: z.ZodOptional<z.ZodNumber>;
36
36
  }>;
37
37
  readonly xano_xanoscript_docs: BuiltTool<{
38
- topic: z.ZodOptional<z.ZodEnum<{
39
- [x: string]: string;
40
- }>>;
38
+ topic: z.ZodOptional<z.ZodString>;
41
39
  file_path: z.ZodOptional<z.ZodString>;
42
40
  mode: z.ZodOptional<z.ZodEnum<{
43
41
  index: "index";
@@ -32,8 +32,8 @@ export declare function setXanoscriptDocsPath(path: string): void;
32
32
  * ```ts
33
33
  * import { xanoscriptDocs } from '@xano/developer-mcp';
34
34
  *
35
- * // Get overview
36
- * const overview = xanoscriptDocs();
35
+ * // Get compact topic index (use topic: 'readme' for the full prose overview)
36
+ * const index = xanoscriptDocs();
37
37
  *
38
38
  * // Get specific topic
39
39
  * const syntaxDocs = xanoscriptDocs({ topic: 'syntax' });
@@ -52,9 +52,7 @@ export declare function xanoscriptDocs(args?: XanoscriptDocsArgs): XanoscriptDoc
52
52
  */
53
53
  export declare function xanoscriptDocsTool(args?: XanoscriptDocsArgs): ToolResult;
54
54
  export declare const xanoscriptDocsToolSpec: import("./define_tool.js").BuiltTool<{
55
- topic: z.ZodOptional<z.ZodEnum<{
56
- [x: string]: string;
57
- }>>;
55
+ topic: z.ZodOptional<z.ZodString>;
58
56
  file_path: z.ZodOptional<z.ZodString>;
59
57
  mode: z.ZodOptional<z.ZodEnum<{
60
58
  index: "index";
@@ -8,7 +8,7 @@ import { readFileSync } from "fs";
8
8
  import { dirname, join } from "path";
9
9
  import { fileURLToPath } from "url";
10
10
  import { z } from "zod";
11
- import { readXanoscriptDocsV2, readXanoscriptDocsStructured, getXanoscriptDocsVersion, getTopicNames, getTopicDescriptions, } from "../xanoscript.js";
11
+ import { readXanoscriptDocsV2, readXanoscriptDocsStructured, getXanoscriptDocsVersion, getTopicDescriptions, getTierFacts, } from "../xanoscript.js";
12
12
  import { defineTool } from "./define_tool.js";
13
13
  // =============================================================================
14
14
  // Path Resolution
@@ -71,8 +71,8 @@ export function setXanoscriptDocsPath(path) {
71
71
  * ```ts
72
72
  * import { xanoscriptDocs } from '@xano/developer-mcp';
73
73
  *
74
- * // Get overview
75
- * const overview = xanoscriptDocs();
74
+ * // Get compact topic index (use topic: 'readme' for the full prose overview)
75
+ * const index = xanoscriptDocs();
76
76
  *
77
77
  * // Get specific topic
78
78
  * const syntaxDocs = xanoscriptDocs({ topic: 'syntax' });
@@ -156,12 +156,14 @@ export function xanoscriptDocsTool(args) {
156
156
  // =============================================================================
157
157
  // MCP Tool Definition
158
158
  // =============================================================================
159
- const topicEnumValues = getTopicNames();
159
+ // Derive tier size facts from the actual files so the advertised numbers can
160
+ // never drift stale (see getTierFacts). Computed once at module load.
161
+ const tierFacts = getTierFacts(getXanoscriptDocsPath());
160
162
  export const xanoscriptDocsToolSpec = defineTool({
161
163
  name: "xano_xanoscript_docs",
162
164
  description: "Get XanoScript programming language documentation for AI code generation. " +
163
- "Call without parameters for overview (README). " +
164
- "For context-limited models: use tier='survival' (~800 tokens) or tier='working' (~3500 tokens). " +
165
+ "Call without parameters for a compact index of all topics (~4KB, ~1K tokens); then drill in with topic= or file_path=. Use topic='readme' for the full prose overview (previously the no-arg default). " +
166
+ `For context-limited models: use tier='survival' (~${tierFacts.survival.tokens}) or tier='working' (~${tierFacts.working.tokens}). ` +
165
167
  "Use 'topic' for specific documentation, or 'file_path' for context-aware docs based on the file you're editing. " +
166
168
  "Use mode='quick_reference' for compact syntax reference (recommended for context efficiency). " +
167
169
  "Use max_tokens to limit documentation size to fit your context budget. " +
@@ -174,10 +176,11 @@ export const xanoscriptDocsToolSpec = defineTool({
174
176
  },
175
177
  inputShape: {
176
178
  topic: z
177
- .enum(topicEnumValues)
179
+ .string()
178
180
  .optional()
179
- .describe("Documentation topic to retrieve. Call without any parameters to get the README overview. " +
180
- "Example: topic='syntax' for language syntax, topic='database' for database operations, topic='types' for type system.\n\n" +
181
+ .describe("Documentation topic to retrieve. Call without any parameters to get the compact topic index; use topic='readme' for the full prose overview. " +
182
+ "Example: topic='syntax' for language syntax, topic='database' for database operations, topic='types' for type system. " +
183
+ "Common synonyms are accepted and resolved automatically (e.g. 'upload'/'storage' -> 'file-uploads'); an unrecognized topic returns the list of valid topics.\n\n" +
181
184
  "Available topics:\n" +
182
185
  getTopicDescriptions()),
183
186
  file_path: z
@@ -192,7 +195,8 @@ export const xanoscriptDocsToolSpec = defineTool({
192
195
  .optional()
193
196
  .describe("'full' = complete documentation with explanations and examples. " +
194
197
  "'quick_reference' = compact reference with just syntax patterns and signatures. " +
195
- "'index' = compact topic listing with descriptions and byte sizes (~1KB). " +
198
+ "'index' = compact topic listing with descriptions and byte sizes (~4KB, ~1K tokens). " +
199
+ "When set, 'index' takes precedence over topic and file_path. " +
196
200
  "Use 'index' to discover available topics before loading them. " +
197
201
  "Use 'quick_reference' to save context window space when you just need a reminder. " +
198
202
  "Default: 'full' for topic mode, 'quick_reference' for file_path mode."),
@@ -200,8 +204,8 @@ export const xanoscriptDocsToolSpec = defineTool({
200
204
  .enum(["survival", "working"])
201
205
  .optional()
202
206
  .describe("Pre-packaged documentation tier for context-limited models. " +
203
- "'survival' (~3KB, ~800 tokens): minimum syntax to write valid XanoScript. " +
204
- "'working' (~12KB, ~3500 tokens): complete reference for common tasks. " +
207
+ `'survival' (~${tierFacts.survival.kb}, ~${tierFacts.survival.tokens}): minimum syntax to write valid XanoScript. ` +
208
+ `'working' (~${tierFacts.working.kb}, ~${tierFacts.working.tokens}): complete reference for common tasks. ` +
205
209
  "Overrides topic/file_path/mode when set. " +
206
210
  "Use 'survival' for models with <16K context, 'working' for 16-64K context."),
207
211
  max_tokens: z
@@ -222,7 +226,7 @@ export const xanoscriptDocsToolSpec = defineTool({
222
226
  documentation: z
223
227
  .string()
224
228
  .optional()
225
- .describe("The documentation content (topic or README mode)."),
229
+ .describe("The documentation content (index, topic, tier, or file_path mode)."),
226
230
  file_path: z
227
231
  .string()
228
232
  .optional()
@@ -8,6 +8,11 @@ export interface DocConfig {
8
8
  file: string;
9
9
  applyTo: string[];
10
10
  description: string;
11
+ /**
12
+ * Load order under a `max_tokens` budget for file_path mode: LOWER loads
13
+ * first (and so survives truncation). Topics sharing a value fall back to
14
+ * docs_index.json declaration order. Omitted (undefined) sorts last (99).
15
+ */
11
16
  priority?: number;
12
17
  }
13
18
  export interface XanoscriptDocsArgs {
@@ -19,11 +24,37 @@ export interface XanoscriptDocsArgs {
19
24
  exclude_topics?: string[];
20
25
  }
21
26
  export declare const XANOSCRIPT_DOCS_V2: Record<string, DocConfig>;
27
+ /**
28
+ * Resolve a topic name or alias to a canonical topic name. Returns the input
29
+ * unchanged when it is already canonical or unknown, so callers can still
30
+ * surface the existing "Unknown topic" error for genuinely bad input.
31
+ */
32
+ export declare function resolveTopic(input?: string): string | undefined;
33
+ /** Get all alias names (keys of the alias -> canonical topic map). */
34
+ export declare function getAliasNames(): string[];
22
35
  /**
23
36
  * Clear all cached documentation content and version data.
24
37
  * Useful for testing or when docs files change at runtime.
25
38
  */
26
39
  export declare function clearDocsCache(): void;
40
+ export interface TierFact {
41
+ /** Human-readable size, e.g. "5KB". */
42
+ kb: string;
43
+ /** Human-readable token estimate, e.g. "1.2K tokens" or "320 tokens". */
44
+ tokens: string;
45
+ }
46
+ /**
47
+ * Single source of truth for the survival/working tier size facts.
48
+ *
49
+ * These numbers are advertised in the tool spec, the index output, and the
50
+ * README. Deriving them from the actual files (instead of hand-syncing literals
51
+ * in four places) is what stops them drifting stale — the recurring bug this
52
+ * helper exists to kill. Estimate ratio matches the tool spec: ~250 tokens/KB.
53
+ */
54
+ export declare function getTierFacts(docsPath: string): {
55
+ survival: TierFact;
56
+ working: TierFact;
57
+ };
27
58
  /**
28
59
  * Get list of topics that apply to a given file path based on applyTo patterns
29
60
  */
@@ -24,6 +24,45 @@ function buildDocsConfig() {
24
24
  return config;
25
25
  }
26
26
  export const XANOSCRIPT_DOCS_V2 = buildDocsConfig();
27
+ /**
28
+ * Map of alias -> canonical topic name, built from the `aliases` arrays in
29
+ * docs_index.json. Lets callers pass a natural synonym (e.g. "upload",
30
+ * "storage", "attachment") and have it resolve to the canonical topic
31
+ * ("file-uploads"). An alias that shadows a real topic name is skipped, and
32
+ * cross-topic collisions are resolved first-writer-wins.
33
+ */
34
+ const ALIAS_TO_TOPIC = (() => {
35
+ const map = {};
36
+ for (const [key, topic] of Object.entries(docsIndex.topics)) {
37
+ const aliases = topic.aliases;
38
+ if (!aliases)
39
+ continue;
40
+ for (const alias of aliases) {
41
+ if (alias in XANOSCRIPT_DOCS_V2)
42
+ continue; // never shadow a canonical topic name
43
+ if (alias in map)
44
+ continue; // first-writer-wins on cross-topic collisions
45
+ map[alias] = key;
46
+ }
47
+ }
48
+ return map;
49
+ })();
50
+ /**
51
+ * Resolve a topic name or alias to a canonical topic name. Returns the input
52
+ * unchanged when it is already canonical or unknown, so callers can still
53
+ * surface the existing "Unknown topic" error for genuinely bad input.
54
+ */
55
+ export function resolveTopic(input) {
56
+ if (!input)
57
+ return input;
58
+ if (input in XANOSCRIPT_DOCS_V2)
59
+ return input;
60
+ return ALIAS_TO_TOPIC[input] ?? input;
61
+ }
62
+ /** Get all alias names (keys of the alias -> canonical topic map). */
63
+ export function getAliasNames() {
64
+ return Object.keys(ALIAS_TO_TOPIC);
65
+ }
27
66
  // =============================================================================
28
67
  // Content Cache
29
68
  // =============================================================================
@@ -45,6 +84,31 @@ function cachedReadFile(filePath) {
45
84
  _fileCache.set(filePath, content);
46
85
  return content;
47
86
  }
87
+ /**
88
+ * Single source of truth for the survival/working tier size facts.
89
+ *
90
+ * These numbers are advertised in the tool spec, the index output, and the
91
+ * README. Deriving them from the actual files (instead of hand-syncing literals
92
+ * in four places) is what stops them drifting stale — the recurring bug this
93
+ * helper exists to kill. Estimate ratio matches the tool spec: ~250 tokens/KB.
94
+ */
95
+ export function getTierFacts(docsPath) {
96
+ const fact = (file) => {
97
+ let size = 0;
98
+ try {
99
+ size = cachedReadFile(join(docsPath, file)).length;
100
+ }
101
+ catch {
102
+ size = 0;
103
+ }
104
+ const estTokens = size / 4;
105
+ const tokens = estTokens >= 1000
106
+ ? `${(estTokens / 1000).toFixed(1)}K tokens`
107
+ : `${Math.ceil(estTokens)} tokens`;
108
+ return { kb: `${Math.round(size / 1024)}KB`, tokens };
109
+ };
110
+ return { survival: fact("survival.md"), working: fact("working.md") };
111
+ }
48
112
  // =============================================================================
49
113
  // Core Functions
50
114
  // =============================================================================
@@ -118,6 +182,46 @@ export function getXanoscriptDocsVersion(docsPath) {
118
182
  return "unknown";
119
183
  }
120
184
  }
185
+ /**
186
+ * Resolve the ordered, budget-bounded topic list for a file_path query.
187
+ *
188
+ * Shared by readXanoscriptDocsV2 and readXanoscriptDocsStructured so the
189
+ * exclude -> priority-sort -> token-budget -> empty-check logic stays identical
190
+ * across the string and structured response paths. It previously lived as two
191
+ * byte-for-byte copies that could silently diverge.
192
+ */
193
+ function selectTopicsForFilePath(docsPath, args, mode) {
194
+ let topics = getDocsForFilePath(args.file_path);
195
+ // Filter out excluded topics
196
+ if (args.exclude_topics && args.exclude_topics.length > 0) {
197
+ topics = topics.filter((t) => !args.exclude_topics.includes(t));
198
+ }
199
+ // Budget-aware loading: sort by priority and stop when budget is exceeded
200
+ if (args.max_tokens) {
201
+ let tokenBudget = args.max_tokens;
202
+ const sortedTopics = [...topics].sort((a, b) => {
203
+ const pa = XANOSCRIPT_DOCS_V2[a]?.priority ?? 99;
204
+ const pb = XANOSCRIPT_DOCS_V2[b]?.priority ?? 99;
205
+ return pa - pb;
206
+ });
207
+ const filteredTopics = [];
208
+ for (const t of sortedTopics) {
209
+ const config = XANOSCRIPT_DOCS_V2[t];
210
+ const content = cachedReadFile(join(docsPath, config.file));
211
+ const topicContent = mode === "quick_reference" ? extractQuickReference(content, t) : content;
212
+ const estimatedTokens = Math.ceil(topicContent.length / 4);
213
+ if (tokenBudget - estimatedTokens < 0 && filteredTopics.length > 0)
214
+ break;
215
+ filteredTopics.push(t);
216
+ tokenBudget -= estimatedTokens;
217
+ }
218
+ topics = filteredTopics;
219
+ }
220
+ if (topics.length === 0) {
221
+ throw new Error(`No documentation found for file pattern: ${args.file_path}\n\nAvailable topics: ${Object.keys(XANOSCRIPT_DOCS_V2).join(", ")}`);
222
+ }
223
+ return topics;
224
+ }
121
225
  /**
122
226
  * Read XanoScript documentation with v2 structure
123
227
  */
@@ -129,9 +233,17 @@ export function readXanoscriptDocsV2(docsPath, args) {
129
233
  const content = cachedReadFile(join(docsPath, tierFile));
130
234
  return `${content}\n\n---\nDocumentation version: ${version}`;
131
235
  }
132
- // Index mode: return compact topic listing with byte sizes and token estimates
133
- if (args?.mode === "index") {
134
- const rows = Object.entries(XANOSCRIPT_DOCS_V2).map(([name, config]) => {
236
+ // Index mode — also the default when no topic/file_path is given.
237
+ // Returns a compact topic listing with byte sizes and token estimates plus
238
+ // orientation pointers, so a bare discovery call costs ~4KB instead of the
239
+ // full README. The README is still reachable via topic='readme'.
240
+ if (args?.mode === "index" || (!args?.topic && !args?.file_path)) {
241
+ // survival/working are whole-corpus digests reached via tier=, not granular
242
+ // topic= targets — listing them as table rows invites topic='survival' calls
243
+ // (a different, non-tier code path). They are surfaced in Next steps instead.
244
+ const rows = Object.entries(XANOSCRIPT_DOCS_V2)
245
+ .filter(([name]) => name !== "survival" && name !== "working")
246
+ .map(([name, config]) => {
135
247
  let size;
136
248
  try {
137
249
  size = cachedReadFile(join(docsPath, config.file)).length;
@@ -143,59 +255,37 @@ export function readXanoscriptDocsV2(docsPath, args) {
143
255
  const estTokens = Math.ceil(size / 4);
144
256
  return `| ${name} | ${config.description} | ${sizeKb} KB | ~${estTokens} |`;
145
257
  });
258
+ const tiers = getTierFacts(docsPath);
146
259
  return [
147
260
  `# XanoScript Documentation Index`,
148
261
  ``,
149
- `Version: ${version}`,
262
+ `XanoScript is the declarative language for Xano backends (tables, APIs, functions, tasks, AI agents).`,
263
+ ``,
150
264
  `Topics: ${rows.length}`,
151
265
  ``,
152
266
  `| Topic | Description | Size | Est. Tokens |`,
153
267
  `|-------|-------------|------|-------------|`,
154
268
  ...rows,
155
269
  ``,
156
- `Use topic='<name>' to load a specific topic. Use mode='quick_reference' for compact output.`,
157
- `Use tier='survival' (~800 tokens) or tier='working' (~3500 tokens) for context-limited models.`,
270
+ `Next steps:`,
271
+ `- topic='readme' — full overview (workspace structure, core syntax patterns, type names)`,
272
+ `- topic='<name>' — load one topic (e.g. 'syntax', 'database', 'apis')`,
273
+ `- file_path='api/users/create.xs' — auto-select the docs for the file you're editing`,
274
+ `- tier='survival' (~${tiers.survival.tokens}) or tier='working' (~${tiers.working.tokens}) for context-limited models`,
275
+ `- mode='quick_reference' — compact output when you only need a reminder`,
276
+ `- max_tokens=4000 with file_path= — stop loading once the budget is reached`,
277
+ `- exclude_topics=['syntax'] with file_path= — skip topics you've already loaded`,
278
+ ``,
279
+ `---`,
280
+ `Documentation version: ${version}`,
158
281
  ].join("\n");
159
282
  }
160
283
  // Default to quick_reference for file_path mode (loads many topics),
161
284
  // full for topic mode (loads single topic)
162
285
  const mode = args?.mode || (args?.file_path ? "quick_reference" : "full");
163
- // Default: return README
164
- if (!args?.topic && !args?.file_path) {
165
- const readme = cachedReadFile(join(docsPath, "README.md"));
166
- return `${readme}\n\n---\nDocumentation version: ${version}`;
167
- }
168
286
  // Context-aware: return docs matching file pattern
169
287
  if (args?.file_path) {
170
- let topics = getDocsForFilePath(args.file_path);
171
- // Filter out excluded topics
172
- if (args.exclude_topics && args.exclude_topics.length > 0) {
173
- topics = topics.filter((t) => !args.exclude_topics.includes(t));
174
- }
175
- // Budget-aware loading: sort by priority and stop when budget is exceeded
176
- if (args.max_tokens) {
177
- let tokenBudget = args.max_tokens;
178
- const sortedTopics = [...topics].sort((a, b) => {
179
- const pa = XANOSCRIPT_DOCS_V2[a]?.priority ?? 99;
180
- const pb = XANOSCRIPT_DOCS_V2[b]?.priority ?? 99;
181
- return pa - pb;
182
- });
183
- const filteredTopics = [];
184
- for (const t of sortedTopics) {
185
- const config = XANOSCRIPT_DOCS_V2[t];
186
- const content = cachedReadFile(join(docsPath, config.file));
187
- const topicContent = mode === "quick_reference" ? extractQuickReference(content, t) : content;
188
- const estimatedTokens = Math.ceil(topicContent.length / 4);
189
- if (tokenBudget - estimatedTokens < 0 && filteredTopics.length > 0)
190
- break;
191
- filteredTopics.push(t);
192
- tokenBudget -= estimatedTokens;
193
- }
194
- topics = filteredTopics;
195
- }
196
- if (topics.length === 0) {
197
- throw new Error(`No documentation found for file pattern: ${args.file_path}\n\nAvailable topics: ${Object.keys(XANOSCRIPT_DOCS_V2).join(", ")}`);
198
- }
288
+ const topics = selectTopicsForFilePath(docsPath, args, mode);
199
289
  const docs = topics.map((t) => {
200
290
  const config = XANOSCRIPT_DOCS_V2[t];
201
291
  const content = cachedReadFile(join(docsPath, config.file));
@@ -206,15 +296,16 @@ export function readXanoscriptDocsV2(docsPath, args) {
206
296
  const header = `# XanoScript Documentation for: ${args.file_path}\n\nMatched topics: ${topics.join(", ")}\nMode: ${mode}\nVersion: ${version}\n\n---\n\n`;
207
297
  return header + docs.join("\n\n---\n\n");
208
298
  }
209
- // Topic-based: return specific doc
210
- const config = XANOSCRIPT_DOCS_V2[args.topic];
299
+ // Topic-based: return specific doc (resolve aliases to canonical names first)
300
+ const canonicalTopic = resolveTopic(args.topic);
301
+ const config = XANOSCRIPT_DOCS_V2[canonicalTopic];
211
302
  if (!config) {
212
303
  const availableTopics = Object.keys(XANOSCRIPT_DOCS_V2).join(", ");
213
304
  throw new Error(`Unknown topic "${args.topic}".\n\nAvailable topics: ${availableTopics}`);
214
305
  }
215
306
  const content = cachedReadFile(join(docsPath, config.file));
216
307
  const doc = mode === "quick_reference"
217
- ? extractQuickReference(content, args.topic)
308
+ ? extractQuickReference(content, canonicalTopic)
218
309
  : content;
219
310
  return `${doc}\n\n---\nDocumentation version: ${version}`;
220
311
  }
@@ -224,34 +315,7 @@ export function readXanoscriptDocsV2(docsPath, args) {
224
315
  */
225
316
  export function readXanoscriptDocsStructured(docsPath, args) {
226
317
  const mode = args.mode || "quick_reference";
227
- let topics = getDocsForFilePath(args.file_path);
228
- if (args.exclude_topics && args.exclude_topics.length > 0) {
229
- topics = topics.filter((t) => !args.exclude_topics.includes(t));
230
- }
231
- // Budget-aware loading
232
- if (args.max_tokens) {
233
- let tokenBudget = args.max_tokens;
234
- const sortedTopics = [...topics].sort((a, b) => {
235
- const pa = XANOSCRIPT_DOCS_V2[a]?.priority ?? 99;
236
- const pb = XANOSCRIPT_DOCS_V2[b]?.priority ?? 99;
237
- return pa - pb;
238
- });
239
- const filteredTopics = [];
240
- for (const t of sortedTopics) {
241
- const config = XANOSCRIPT_DOCS_V2[t];
242
- const content = cachedReadFile(join(docsPath, config.file));
243
- const topicContent = mode === "quick_reference" ? extractQuickReference(content, t) : content;
244
- const estimatedTokens = Math.ceil(topicContent.length / 4);
245
- if (tokenBudget - estimatedTokens < 0 && filteredTopics.length > 0)
246
- break;
247
- filteredTopics.push(t);
248
- tokenBudget -= estimatedTokens;
249
- }
250
- topics = filteredTopics;
251
- }
252
- if (topics.length === 0) {
253
- throw new Error(`No documentation found for file pattern: ${args.file_path}\n\nAvailable topics: ${Object.keys(XANOSCRIPT_DOCS_V2).join(", ")}`);
254
- }
318
+ const topics = selectTopicsForFilePath(docsPath, args, mode);
255
319
  return topics.map((t) => {
256
320
  const config = XANOSCRIPT_DOCS_V2[t];
257
321
  const content = cachedReadFile(join(docsPath, config.file));
@@ -120,7 +120,7 @@ $db.table.field // Database field reference (in queries)
120
120
  $this // Current item in loops/maps
121
121
  ```
122
122
 
123
- **Reserved Variables:** The following cannot be used as variable names: `$response`, `$output`, `$input`, `$auth`, `$env`, `$db`, `$this`, `$result`, `$index`. See `xano_xano_xanoscript_docs({ topic: "essentials" })` for detailed variable access rules.
123
+ **Reserved Variables:** The following cannot be used as variable names: `$response`, `$output`, `$input`, `$auth`, `$env`, `$db`, `$this`, `$result`, `$index`. See `xano_xanoscript_docs({ topic: "essentials" })` for detailed variable access rules.
124
124
 
125
125
  ### Type Names
126
126
 
@@ -203,10 +203,12 @@ Use `xano_xanoscript_docs({ topic: "<topic>" })` to retrieve documentation.
203
203
 
204
204
  ### Tiers (for context-limited models)
205
205
 
206
+ Approximate sizes below; the tool reports exact live sizes in the `mode: "index"` listing and derives the advertised token counts from the actual files at runtime.
207
+
206
208
  | Topic | Description | Size |
207
209
  | ---------- | ------------------------------------------------------------ | ---- |
208
- | `survival` | Minimal syntax survival kit for models with <16K context | ~3KB (~800 tokens) |
209
- | `working` | Complete working reference for models with 16-64K context | ~12KB (~3500 tokens) |
210
+ | `survival` | Minimal syntax survival kit for models with <16K context | ~5KB (~1.2K tokens) |
211
+ | `working` | Complete working reference for models with 16-64K context | ~17KB (~4.4K tokens) |
210
212
 
211
213
  Use `xano_xanoscript_docs({ tier: "survival" })` or `xano_xanoscript_docs({ tier: "working" })`.
212
214
 
@@ -236,6 +238,7 @@ Use `xano_xanoscript_docs({ tier: "survival" })` or `xano_xanoscript_docs({ tier
236
238
  | Topic | Description | Key Sections |
237
239
  | ---------- | --------------------------------------------------------------- | ------------ |
238
240
  | `apis` | HTTP endpoint definitions with authentication and CRUD patterns | Decision Tree, CRUD Examples |
241
+ | `file-uploads` | Uploading files to native Xano storage | `file?` input, create_attachment, signed URLs |
239
242
  | `tasks` | Scheduled and cron jobs | Cron Syntax, Input Handling |
240
243
  | `triggers` | Event-driven handlers (table, realtime, workspace, agent, MCP) | Predefined Inputs, Event Types |
241
244
  | `realtime` | Real-time channels and events for push updates | Channels, Events |