xanoscript-docs-expert
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseXanoScript Docs Expert
XanoScript Docs 专家技能
Overview
概述
This skill provides expert-level knowledge for working with the system inside the project. The project is a dual-purpose npm package: an MCP Server that serves XanoScript documentation to AI assistants, and a standalone library. The documentation lives as markdown files in and is the primary content delivered by the MCP tool.
xanoscript_docs@xano/developer-mcpsrc/xanoscript_docs/xanoscript_docs本技能提供了在项目中使用系统的专家级知识。该项目是一个兼具双重用途的npm包:既是为AI助手提供XanoScript文档的MCP Server,也是一个独立库。文档以Markdown文件形式存储在目录下,是 MCP工具提供的核心内容。
@xano/developer-mcpxanoscript_docssrc/xanoscript_docs/xanoscript_docsArchitecture at a Glance
架构概览
src/
├── index.ts # MCP server entry (stdio transport)
├── lib.ts # Library entry (standalone usage)
├── xanoscript.ts # Core doc logic: topic registry, file matching, content extraction
├── tools/
│ ├── index.ts # Tool registry + dispatch (6 tools total)
│ ├── xanoscript_docs.ts # xanoscript_docs tool: path resolution, MCP definition
│ ├── validate_xanoscript.ts # Code validation via language server parser
│ ├── meta_api_docs.ts # Meta API docs tool
│ ├── run_api_docs.ts # Run API docs tool
│ ├── cli_docs.ts # CLI docs tool
│ ├── mcp_version.ts # Version tool
│ └── types.ts # Shared ToolResult type
├── xanoscript_docs/ # 34 documentation topics (THE CONTENT)
│ ├── README.md # Overview (returned when no args)
│ ├── version.json # { "version": "2.0.0", "updated": "2025-02-06" }
│ ├── docs_index.json # Machine-readable index with aliases, filters, constructs
│ ├── cheatsheet.md, syntax.md, quickstart.md, types.md # Core language docs
│ ├── functions.md, database.md, tables.md, apis.md # Construct-specific docs
│ ├── agents.md, tools.md, mcp-servers.md, triggers.md # AI & event docs
│ ├── [16 more topic files...]
│ └── integrations/ # Sub-topic directory
│ ├── cloud-storage.md, search.md, redis.md
│ ├── external-apis.md, utilities.md
│ ...
├── meta_api_docs/ # Separate doc module for Meta API
├── run_api_docs/ # Separate doc module for Run API
└── cli_docs/ # Separate doc module for CLIsrc/
├── index.ts # MCP服务器入口(stdio传输)
├── lib.ts # 库入口(独立使用)
├── xanoscript.ts # 核心文档逻辑:主题注册表、文件匹配、内容提取
├── tools/
│ ├── index.ts # 工具注册表 + 调度(共6个工具)
│ ├── xanoscript_docs.ts # xanoscript_docs工具:路径解析、MCP定义
│ ├── validate_xanoscript.ts # 通过语言服务器解析器进行代码验证
│ ├── meta_api_docs.ts # Meta API文档工具
│ ├── run_api_docs.ts # Run API文档工具
│ ├── cli_docs.ts # CLI文档工具
│ ├── mcp_version.ts # 版本工具
│ └── types.ts # 共享ToolResult类型
├── xanoscript_docs/ # 34个文档主题(核心内容)
│ ├── README.md # 概述(无参数时返回)
│ ├── version.json # { "version": "2.0.0", "updated": "2025-02-06" }
│ ├── docs_index.json # 包含别名、过滤器、结构的机器可读索引
│ ├── cheatsheet.md, syntax.md, quickstart.md, types.md # 核心语言文档
│ ├── functions.md, database.md, tables.md, apis.md # 特定结构文档
│ ├── agents.md, tools.md, mcp-servers.md, triggers.md # AI与事件文档
│ ├── [16个更多主题文件...]
│ └── integrations/ # 子主题目录
│ ├── cloud-storage.md, search.md, redis.md
│ ├── external-apis.md, utilities.md
│ ...
├── meta_api_docs/ # Meta API的独立文档模块
├── run_api_docs/ # Run API的独立文档模块
└── cli_docs/ # CLI的独立文档模块How the xanoscript_docs Tool Works
xanoscript_docs工具的工作原理
Request Flow
请求流程
Caller provides { topic?, file_path?, mode? }
│
├── No args → Return README.md
├── topic="syntax" → Return syntax.md content
├── file_path="api/users/create.xs" → minimatch applyTo patterns → return all matching docs
└── mode="quick_reference" → Extract only "## Quick Reference" sections
│
└── All responses append: "---\nDocumentation version: X.X.X"调用者提供 { topic?, file_path?, mode? }
│
├── 无参数 → 返回README.md
├── topic="syntax" → 返回syntax.md内容
├── file_path="api/users/create.xs" → 应用minimatch的applyTo模式 → 返回所有匹配文档
└── mode="quick_reference" → 仅提取"## Quick Reference"章节
│
└── 所有响应追加:"---\nDocumentation version: X.X.X"Key Source Files
关键源文件
src/xanoscript.ts- : Record<string, DocConfig> mapping 34 topic keys to
XANOSCRIPT_DOCS_V2{ file, applyTo, description } - : Uses
getDocsForFilePath(filePath)to match file paths againstminimatchglob patterns. Always includes "syntax" as a foundation topic.applyTo - : Finds "## Quick Reference" heading and extracts content until the next
extractQuickReference(content, topic)heading. Falls back to first 50 lines.## - : Main read function — decides what to return based on args.
readXanoscriptDocsV2(docsPath, args)
src/tools/xanoscript_docs.ts- : Resolves docs directory — tries
getXanoscriptDocsPath()first, falls back todist/xanoscript_docs/.src/xanoscript_docs/ - : Standalone function returning
xanoscriptDocs(args).{ documentation: string } - : Returns
xanoscriptDocsTool(args)(ToolResult).{ success, data?, error? } - : MCP tool schema with name, description, inputSchema.
xanoscriptDocsToolDefinition
src/tools/index.ts- array registers all 6 tools
toolDefinitions - dispatches by tool name
handleTool(name, args) - converts ToolResult to MCP format:
toMcpResponse(){ content: [{ type: "text", text }], isError? }
src/xanoscript.ts- : Record<string, DocConfig>,将34个主题键映射到
XANOSCRIPT_DOCS_V2{ file, applyTo, description } - : 使用
getDocsForFilePath(filePath)将文件路径与minimatch通配符模式匹配,始终包含"syntax"作为基础主题applyTo - : 查找"## Quick Reference"标题并提取内容直到下一个
extractQuickReference(content, topic)标题,若未找到则返回前50行## - : 主读取函数 — 根据参数决定返回内容
readXanoscriptDocsV2(docsPath, args)
src/tools/xanoscript_docs.ts- : 解析文档目录 — 优先尝试
getXanoscriptDocsPath(), fallback到dist/xanoscript_docs/src/xanoscript_docs/ - : 返回
xanoscriptDocs(args)的独立函数{ documentation: string } - : 返回
xanoscriptDocsTool(args)(ToolResult){ success, data?, error? } - : 包含名称、描述、inputSchema的MCP工具 schema
xanoscriptDocsToolDefinition
src/tools/index.ts- 数组注册所有6个工具
toolDefinitions - 根据工具名称调度
handleTool(name, args) - 将ToolResult转换为MCP格式:
toMcpResponse(){ content: [{ type: "text", text }], isError? }
Build Process
构建流程
bash
tsc && cp -r src/xanoscript_docs dist/TypeScript compiles to , then markdown files are copied verbatim. The docs are NOT transformed — they ship as-is.
dist/bash
tsc && cp -r src/xanoscript_docs dist/TypeScript编译到目录,然后Markdown文件被原样复制。文档不会被转换 — 按原始形式发布。
dist/Adding a New Documentation Topic
添加新文档主题
This is the most common modification. Follow these steps exactly:
这是最常见的修改操作,请严格遵循以下步骤:
Step 1: Create the Markdown File
步骤1:创建Markdown文件
Create a new file in . For sub-topics, use the subdirectory pattern.
.mdsrc/xanoscript_docs/integrations/Every doc file MUST start with frontmatter:
markdown
---
applyTo: "function/*.xs, api/**/*.xs"
---The value specifies which file patterns this doc applies to when using context-aware delivery. Use empty string or omit patterns for docs only accessible via explicit parameter.
applyTotopic在目录下创建新的文件。子主题请使用子目录模式。
src/xanoscript_docs/.mdintegrations/每个文档文件必须以frontmatter开头:
markdown
---
applyTo: "function/*.xs, api/**/*.xs"
---applyTotopicStep 2: Register the Topic in src/xanoscript.ts
src/xanoscript.ts步骤2:在src/xanoscript.ts
中注册主题
src/xanoscript.tsAdd an entry to the object:
XANOSCRIPT_DOCS_V2typescript
"my-new-topic": {
file: "my-new-topic.md", // Path relative to xanoscript_docs/
applyTo: ["function/**/*.xs"], // Glob patterns for context-aware matching
description: "One-line description of what this doc covers",
},For sub-topics in a directory:
typescript
"integrations/my-service": {
file: "integrations/my-service.md",
applyTo: [], // Sub-topics typically have empty applyTo
description: "Description here",
},在对象中添加条目:
XANOSCRIPT_DOCS_V2typescript
"my-new-topic": {
file: "my-new-topic.md", // 相对于xanoscript_docs/的路径
applyTo: ["function/**/*.xs"], // 上下文感知匹配的通配符模式
description: "该文档涵盖内容的单行描述",
},对于目录中的子主题:
typescript
"integrations/my-service": {
file: "integrations/my-service.md",
applyTo: [], // 子主题通常为空applyTo
description: "描述内容",
},Step 3: Update docs_index.json
(Optional but Recommended)
docs_index.json步骤3:更新docs_index.json
(可选但推荐)
docs_index.jsonAdd the topic to in the appropriate section:
src/xanoscript_docs/docs_index.jsonjson
"my-new-topic": {
"file": "my-new-topic.md",
"purpose": "Brief purpose description",
"aliases": ["alias1", "alias2"]
}Also update , , or sections if the new topic documents any of those.
constructsoperationstasks在的对应章节中添加主题:
src/xanoscript_docs/docs_index.jsonjson
"my-new-topic": {
"file": "my-new-topic.md",
"purpose": "简要用途描述",
"aliases": ["alias1", "alias2"]
}如果新主题涉及任何结构、操作或任务,也请更新、或章节。
constructsoperationstasksStep 4: Bump Version
步骤4:更新版本
Update :
src/xanoscript_docs/version.jsonjson
{
"version": "2.1.0",
"updated": "2025-03-15"
}更新:
src/xanoscript_docs/version.jsonjson
{
"version": "2.1.0",
"updated": "2025-03-15"
}Step 5: Build and Test
步骤5:构建并测试
bash
npm run build # tsc && cp -r src/xanoscript_docs dist/
npm test # vitest runbash
npm run build # tsc && cp -r src/xanoscript_docs dist/
npm test # vitest runDocumentation Authoring Conventions
文档创作规范
Read for the complete style guide. Here's the essential pattern:
references/doc-conventions.md完整的风格指南请查看。以下是核心模式:
references/doc-conventions.mdRequired Structure
必需结构
Every documentation file follows this skeleton:
markdown
---
applyTo: "pattern/**/*.xs"
---每个文档文件遵循以下框架:
markdown
---
applyTo: "pattern/**/*.xs"
---Topic Title
主题标题
TL;DR: One or two sentences summarizing the key concepts.
TL;DR: 一两句话总结核心概念。
Quick Reference
Quick Reference
| Feature | Example | Notes |
|---|---|---|
| ... | ... | ... |
| 特性 | 示例 | 说明 |
|---|---|---|
| ... | ... | ... |
[Detailed Sections]
[详细章节]
Basic Structure
基础结构
[Minimal working example]
[最小可运行示例]
Common Patterns
常见模式
[Real-world usage examples]
[实际使用示例]
Common Mistakes
常见错误
❌ Wrong:
xs
// incorrect code✅ Correct:
xs
// correct code❌ 错误写法:
xs
// 错误代码✅ 正确写法:
xs
// 正确代码Related Topics
相关主题
| Topic | Use For |
|---|---|
| [syntax](xanoscript_docs({ topic: "syntax" })) | Filters and operators |
undefined| 主题 | 适用场景 |
|---|---|
| [syntax](xanoscript_docs({ topic: "syntax" })) | 过滤器与运算符 |
undefinedCode Examples
代码示例
- Use language identifier for XanoScript code blocks
xs - Use for frontend code,
javascriptfor datajson - Comments use only (no
//or#in XanoScript)/* */ - Show both wrong and correct patterns with ❌/✅ markers
- Progress from simple to complex examples
- XanoScript代码块使用语言标识符
xs - 前端代码使用,数据使用
javascriptjson - 注释仅使用(XanoScript中不使用
//或#)/* */ - 使用❌/✅标记展示错误和正确模式
- 示例从简单到复杂递进
Cross-Referencing
交叉引用
Reference other topics using this pattern:
For details, see xanoscript_docs({ topic: "syntax" })
For sub-topics: xanoscript_docs({ topic: "integrations/redis" })使用以下模式引用其他主题:
详情请见xanoscript_docs({ topic: "syntax" })
子主题引用:xanoscript_docs({ topic: "integrations/redis" })File Naming
文件命名
- Lowercase with hyphens: ,
unit-testing.mdcloud-storage.md - Integration sub-topics go in subdirectory
integrations/
- 小写字母加连字符:,
unit-testing.mdcloud-storage.md - 集成子主题放在子目录中
integrations/
XanoScript Language Reference
XanoScript语言参考
For quick reference when writing docs, see . Key things to remember:
references/xanoscript-language.md编写文档时的快速参考请查看。需要记住的关键点:
references/xanoscript-language.mdType Names (Common Mistake Area)
类型名称(常见错误点)
| Correct | WRONG |
|---|---|
| |
| |
| |
| |
| 正确写法 | 错误写法 |
|---|---|
| |
| |
| |
| |
Filter Type Safety (Most Common Doc Error)
过滤器类型安全(最常见文档错误)
String filters and array filters are NOT interchangeable. This is the #1 source of mistakes in the docs:
| Task | String Filter | Array Filter |
|---|---|---|
| Get length | | |
| Get part | | |
| Reverse | | |
字符串过滤器和数组过滤器不可互换,这是文档中最常见的错误来源:
| 任务 | 字符串过滤器 | 数组过滤器 |
|---|---|---|
| 获取长度 | | |
| 获取部分内容 | | |
| 反转 | | |
Control Flow Keyword
控制流关键字
Always (one word), never .
elseifelse if始终使用(一个单词),切勿使用。
elseifelse ifString Concatenation
字符串拼接
Use (tilde), not . Parentheses required around filtered values in concatenation:
~+xs
($count|to_text) ~ " items"使用(波浪号),而非。拼接中经过过滤的值必须加括号:
~+xs
($count|to_text) ~ " items"Modifying the MCP Tool Itself
修改MCP工具本身
For changes to how documentation is served (not the content):
若要更改文档的提供方式(而非内容):
Changing Tool Parameters
修改工具参数
Edit in . The follows JSON Schema format.
xanoscriptDocsToolDefinitionsrc/tools/xanoscript_docs.tsinputSchema编辑中的。遵循JSON Schema格式。
src/tools/xanoscript_docs.tsxanoscriptDocsToolDefinitioninputSchemaChanging Doc Resolution Logic
修改文档解析逻辑
Edit functions in :
src/xanoscript.ts- — context-aware matching logic
getDocsForFilePath() - — quick reference extraction
extractQuickReference() - — main read dispatch
readXanoscriptDocsV2()
编辑中的函数:
src/xanoscript.ts- — 上下文感知匹配逻辑
getDocsForFilePath() - — 快速参考提取逻辑
extractQuickReference() - — 主读取调度逻辑
readXanoscriptDocsV2()
Changing Path Resolution
修改路径解析
Edit in . The fallback chain: → → default.
getXanoscriptDocsPath()src/tools/xanoscript_docs.tsdist/xanoscript_docs/src/xanoscript_docs/编辑中的。 fallback链: → → 默认路径。
src/tools/xanoscript_docs.tsgetXanoscriptDocsPath()dist/xanoscript_docs/src/xanoscript_docs/Adding a New MCP Tool
添加新MCP工具
- Create with tool definition and handler
src/tools/my_tool.ts - Register in : add to
src/tools/index.tsarray andtoolDefinitionsswitchhandleTool - Export from if needed for standalone usage
src/lib.ts
- 创建,包含工具定义和处理函数
src/tools/my_tool.ts - 在中注册:添加到
src/tools/index.ts数组和toolDefinitions分支handleTool - 若需独立使用,从导出
src/lib.ts
Testing
测试
bash
npm test # Run all tests
npm run test:watch # Watch mode
npm run test:coverage # With V8 coverageTest files live alongside source: . Tests use Vitest with // patterns.
src/xanoscript.test.tsdescribeitexpectKey things to test when modifying docs:
- New topics resolve correctly via
readXanoscriptDocsV2({ topic: "new-topic" }) - patterns match expected file paths via
applyTogetDocsForFilePath() - Quick reference extraction works if your doc has a section
## Quick Reference
bash
npm test # 运行所有测试
npm run test:watch # 监听模式
npm run test:coverage # 生成V8覆盖率报告测试文件与源文件放在一起:。测试使用Vitest的//模式。
src/xanoscript.test.tsdescribeitexpect修改文档时需要测试的关键点:
- 新主题可通过正确解析
readXanoscriptDocsV2({ topic: "new-topic" }) - 模式可通过
applyTo匹配预期文件路径getDocsForFilePath() - 若文档包含章节,快速参考提取功能正常工作
## Quick Reference
Common Tasks Checklist
常见任务清单
| Task | Files to Modify |
|---|---|
| Add new doc topic | New |
| Edit existing doc content | Just the |
| Change which files a doc applies to | |
| Add integration sub-topic | New file in |
| Change tool description/schema | |
| Change doc resolution logic | |
| Update version | |
| Add new MCP tool (non-docs) | New file in |
| 任务 | 需要修改的文件 |
|---|---|
| 添加新文档主题 | 新的 |
| 编辑现有文档内容 | 仅修改 |
| 修改文档适用的文件范围 | |
| 添加集成子主题 | 在 |
| 修改工具描述/schema | |
| 修改文档解析逻辑 | |
| 更新版本 | |
| 添加新MCP工具(非文档类) | 在 |