@xano/developer-mcp 1.0.33 → 1.0.35

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.
@@ -108,7 +108,20 @@ $db.table.field // Database field reference (in queries)
108
108
  $this // Current item in loops/maps
109
109
  ```
110
110
 
111
- **Note:** `$response` is a reserved word and cannot be used as a variable name.
111
+ **Reserved Variables:** The following cannot be used as variable names: `$response`, `$output`, `$input`, `$auth`, `$env`, `$db`, `$this`, `$result`.
112
+
113
+ ### Type Names
114
+
115
+ XanoScript uses specific type names:
116
+
117
+ | Type | Description | Example |
118
+ |------|-------------|---------|
119
+ | `text` | String (not "string") | `text name` |
120
+ | `int` | Integer (not "integer") | `int count` |
121
+ | `bool` | Boolean (not "boolean") | `bool active` |
122
+ | `decimal` | Float/number | `decimal price` |
123
+ | `type[]` | Array (not "array" or "list") | `text[] tags` |
124
+ | `json` | Arbitrary JSON data | `json metadata` |
112
125
 
113
126
  ### Comments
114
127
 
@@ -142,18 +155,35 @@ applyTo: "function/**/*.xs"
142
155
 
143
156
  This helps AI tools apply the correct documentation based on the file being edited.
144
157
 
158
+ ## Getting Started
159
+
160
+ For common patterns and quick examples, use:
161
+ ```
162
+ xanoscript_docs({ topic: "quickstart" })
163
+ ```
164
+
165
+ This includes:
166
+ - Variable declaration patterns
167
+ - Conditional logic (if/elseif/else)
168
+ - API requests with error handling
169
+ - Database CRUD operations
170
+ - Common mistakes to avoid
171
+
172
+ ---
173
+
145
174
  ## Documentation Index
146
175
 
147
176
  Use `xanoscript_docs({ topic: "<topic>" })` to retrieve documentation.
148
177
 
149
178
  ### Core Language
150
179
 
151
- | Topic | Description |
152
- | ----------- | ------------------------------------------------- |
153
- | `syntax` | Expressions, operators, filters, system variables |
154
- | `types` | Data types, validation, input blocks |
155
- | `functions` | Reusable function stacks, async, loops |
156
- | `schema` | Runtime schema parsing and validation |
180
+ | Topic | Description |
181
+ | ------------ | ---------------------------------------------------- |
182
+ | `quickstart` | Common patterns, quick examples, mistakes to avoid |
183
+ | `syntax` | Expressions, operators, filters, system variables |
184
+ | `types` | Data types, validation, input blocks |
185
+ | `functions` | Reusable function stacks, async, loops |
186
+ | `schema` | Runtime schema parsing and validation |
157
187
 
158
188
  ### Data
159
189
 
@@ -210,3 +240,47 @@ Use `xanoscript_docs({ topic: "<topic>" })` to retrieve documentation.
210
240
  | ------------- | ------------------------------------------------------------ |
211
241
  | `performance` | Performance optimization best practices |
212
242
  | `security` | Security best practices for authentication and authorization |
243
+
244
+ ---
245
+
246
+ ## Example Implementations
247
+
248
+ Common integration patterns you can reference:
249
+
250
+ ### External API Integrations
251
+ - **OpenAI/ChatGPT**: Use `api.request` with POST to `/v1/chat/completions`
252
+ - **Stripe**: Use `api.request` with form-encoded params for payments
253
+ - **SendGrid/Resend**: Use `api.request` or `util.send_email` for emails
254
+ - **Slack/Discord**: Use `api.request` with webhook URLs
255
+ - **Twilio**: Use `api.request` with Basic auth for SMS
256
+
257
+ ### Common Pattern: API Integration Function
258
+
259
+ ```xs
260
+ function "call_external_api" {
261
+ input {
262
+ text endpoint
263
+ object payload
264
+ }
265
+ stack {
266
+ api.request {
267
+ url = $env.API_BASE_URL ~ $input.endpoint
268
+ method = "POST"
269
+ params = $input.payload
270
+ headers = [
271
+ "Content-Type: application/json",
272
+ "Authorization: Bearer " ~ $env.API_KEY
273
+ ]
274
+ timeout = 30
275
+ } as $api_result
276
+
277
+ precondition ($api_result.response.status >= 200 && $api_result.response.status < 300) {
278
+ error_type = "standard"
279
+ error = "API error: " ~ ($api_result.response.status|to_text)
280
+ }
281
+ }
282
+ response = $api_result.response.result
283
+ }
284
+ ```
285
+
286
+ For more patterns, see `xanoscript_docs({ topic: "quickstart" })` or `xanoscript_docs({ topic: "integrations" })`.
@@ -612,3 +612,17 @@ try_catch {
612
612
  5. **Use null-safe operators** - `==?` for optional filters
613
613
  6. **Use bulk operations for batch processing** - More efficient than loops
614
614
  7. **Handle deadlocks gracefully** - Implement retry logic for concurrent writes
615
+
616
+ ---
617
+
618
+ ## Related Topics
619
+
620
+ Explore more with `xanoscript_docs({ topic: "<topic>" })`:
621
+
622
+ | Topic | Description |
623
+ |-------|-------------|
624
+ | `tables` | Database schema definitions with indexes and relationships |
625
+ | `syntax` | Query filters, operators, and expressions |
626
+ | `quickstart` | Common CRUD patterns and examples |
627
+ | `addons` | Reusable subqueries for fetching related data |
628
+ | `performance` | Query optimization best practices |
@@ -465,3 +465,17 @@ foreach ($items) {
465
465
  5. **Keep stacks shallow** - Avoid deeply nested conditionals
466
466
  6. **Use group for organization** - Visually group related statements for readability
467
467
  7. **Use remove sparingly** - Consider filtering arrays instead
468
+
469
+ ---
470
+
471
+ ## Related Topics
472
+
473
+ Explore more with `xanoscript_docs({ topic: "<topic>" })`:
474
+
475
+ | Topic | Description |
476
+ |-------|-------------|
477
+ | `types` | Input types, filters, and validation |
478
+ | `syntax` | Expressions, operators, and control flow |
479
+ | `quickstart` | Common patterns and examples |
480
+ | `database` | Database operations in function stacks |
481
+ | `testing` | Unit testing functions |
@@ -575,22 +575,92 @@ util.send_email {
575
575
 
576
576
  ---
577
577
 
578
- ## External APIs
578
+ ## External APIs (api.request)
579
579
 
580
580
  Make HTTP requests to external APIs.
581
581
 
582
+ ### Quick Reference
583
+
582
584
  ```xs
583
585
  api.request {
584
- url = "https://api.example.com/data"
585
- method = "POST"
586
- params = { key: "value" }
586
+ url = "https://api.example.com/endpoint"
587
+ method = "POST" // GET, POST, PUT, PATCH, DELETE
588
+ params = $payload // Request body for POST/PUT/PATCH
587
589
  headers = ["Content-Type: application/json", "Authorization: Bearer " ~ $env.API_KEY]
588
- timeout = 30
590
+ timeout = 30 // Timeout in seconds
589
591
  } as $api_result
592
+
593
+ // Access response
594
+ $api_result.response.status // HTTP status code (200, 404, etc.)
595
+ $api_result.response.result // Response body (auto-parsed JSON)
596
+ $api_result.response.headers // Response headers array
590
597
  ```
591
598
 
599
+ > **Important:** The `params` parameter is used for the **request body** (POST/PUT/PATCH), not query parameters. This naming is counterintuitive but consistent across XanoScript.
600
+
592
601
  > **Note:** The `headers` parameter expects an array of text strings, where each string contains the header name and value separated by a colon (e.g., `["Content-Type: application/json", "X-Custom-Header: value"]`).
593
602
 
603
+ ### GET Request
604
+
605
+ ```xs
606
+ api.request {
607
+ url = "https://api.example.com/users?page=1&limit=10"
608
+ method = "GET"
609
+ headers = ["Authorization: Bearer " ~ $env.API_KEY]
610
+ } as $api_result
611
+
612
+ var $users { value = $api_result.response.result }
613
+ ```
614
+
615
+ ### POST Request with JSON Body
616
+
617
+ ```xs
618
+ var $payload {
619
+ value = {
620
+ name: $input.name,
621
+ email: $input.email
622
+ }
623
+ }
624
+
625
+ api.request {
626
+ url = "https://api.example.com/users"
627
+ method = "POST"
628
+ params = $payload
629
+ headers = ["Content-Type: application/json", "Authorization: Bearer " ~ $env.API_KEY]
630
+ } as $api_result
631
+
632
+ // Check for success
633
+ precondition ($api_result.response.status == 201) {
634
+ error_type = "standard"
635
+ error = "Failed to create user: " ~ ($api_result.response.result|json_encode)
636
+ }
637
+ ```
638
+
639
+ ### Error Handling Pattern
640
+
641
+ ```xs
642
+ api.request {
643
+ url = "https://api.example.com/data"
644
+ method = "GET"
645
+ timeout = 30
646
+ } as $api_result
647
+
648
+ conditional {
649
+ if ($api_result.response.status >= 200 && $api_result.response.status < 300) {
650
+ var $data { value = $api_result.response.result }
651
+ }
652
+ elseif ($api_result.response.status == 404) {
653
+ throw { name = "NotFound", value = "Resource not found" }
654
+ }
655
+ else {
656
+ throw {
657
+ name = "APIError",
658
+ value = "API returned status " ~ ($api_result.response.status|to_text)
659
+ }
660
+ }
661
+ }
662
+ ```
663
+
594
664
  ### Response Structure
595
665
 
596
666
  The `api.request` statement returns an object with both request and response details: