moonbit-agent-guide
Guide for writing, refactoring, and testing MoonBit projects. Use when working in MoonBit modules or packages, organizing MoonBit files, using moon tooling (build/check/test/doc/ide), or following MoonBit-specific layout, documentation, and testing conventions.
Install
mkdir -p .claude/skills/moonbit-agent-guide && curl -L -o skill.zip "https://mcp.directory/api/skills/download/3295" && unzip -o skill.zip -d .claude/skills/moonbit-agent-guide && rm skill.zipInstalls to .claude/skills/moonbit-agent-guide
About this skill
MoonBit Project Layouts
MoonBit use the .mbt extension and interface files .mbti. At
the top-level of a MoonBit project there is a moon.mod.json file specifying
the metadata of the project. The project may contain multiple packages, each
with its own moon.pkg.json file.
Example layout
my_module
├── moon.mod.json # Module metadata, source field(optional) specifies the source directory of the module
├── moon.pkg.json # Package metadata (each directory is a package like Golang)
├── README.mbt.md # Markdown with tested code blocks (`test "..." { ... }`)
├── README.md -> README.mbt.md
├── cmd # Command line directory
│ └── main
│ ├── main.mbt
│ └── moon.pkg.json # executable package with {"is_main": true}
├── liba/ # Library packages
│ └── moon.pkg.json # Referenced by other packages as `@username/my_module/liba`
│ └── libb/ # Library packages
│ └── moon.pkg.json # Referenced by other packages as `@username/my_module/liba/libb`
├── user_pkg.mbt # Root packages, referenced by other packages as `@username/my_module`
├── user_pkg_wbtest.mbt # White-box tests (only needed for testing internal private members, similar to Golang's package mypackage)
└── user_pkg_test.mbt # Black-box tests
└── ... # More package files, symbols visible to current package (like Golang)
-
Module:
moon.mod.jsonfile in the project directory. A MoonBit module is like a Go module,it is a collection of packages in subdirectories, usually corresponding to a repository or project. Module boundaries matter for dependency management and import paths. -
Package: a
moon.pkg.jsonfile per directory. All subcommands ofmoonwill still be executed in the directory of the module (wheremoon.mod.jsonis located), not the current package. A MoonBit package is the actual compilation unit (like a Go package). All source files in the same package are concatenated into one unit. Thepackagename in the source defines the package, not the file name. Imports refer to module + package paths, NEVER to file names. -
Files: A
.mbtfile is just a chunk of source inside a package. File names do NOT create modules or namespaces. You may freely split/merge/move declarations between files in the same package. Any declaration in a package can reference any other declaration in that package, regardless of file.
Coding/layout rules you MUST follow:
-
Prefer many small, cohesive files over one large file.
- Group related types and functions into focused files (e.g. http_client.mbt, router.mbt).
- If a file is getting large or unfocused, create a new file and move related declarations into it.
-
You MAY freely move declarations between files inside the same package.
- Each block is separated by
///|, moving a function/struct/trait between files does not change semantics, as long as its name and pub-ness stay the same, the order of each block is irrelevant too. - It is safe to refactor by splitting or merging files inside a package.
- Each block is separated by
-
File names are purely organizational.
- Do NOT assume file names define modules, and do NOT use file names in type paths.
- Choose file names to describe a feature or responsibility, not to mirror type names rigidly.
-
When adding new code:
- Prefer adding it to an existing file that matches the feature.
- If no good file exists, create a new file under the same package with a descriptive name.
- Avoid creating giant “misc” or “util” files.
-
Tests:
- Place tests in dedicated test files (e.g. *_test.mbt) within the appropriate package.
For a package, besides
*_test.mbtfiles,*.mbt.mdare also blackbox test files, the code blockmbt checkare treated as test cases, they serve both purposes: documentation and tests.
You may haveREADME.mbt.mdfiles withmbt checkcode examples, you can also symlinkREADME.mbt.mdtoREADME.mdto make it integrate better with GitHub. - It is fine—and encouraged—to have multiple small test files.
- Place tests in dedicated test files (e.g. *_test.mbt) within the appropriate package.
For a package, besides
-
Interface files(
pkg.generated.mbti)pkg.generated.mbtiis compiler-generated summaries of each package's public API surface. They provide a formal, concise overview of all exported types, functions, and traits without implementation details. They are generated usingmoon info, useful for code review, when you have a commit that does not change public APIs,pkg.generated.mbtifiles will remain unchanged, so it is recommended to putpkg.generated.mbtiin version control when you are done.You can also use
moon doc @moonbitlang/core/strconvto explore the public API of a package interactively andmoon ide peek-def 'Array::join'to read the definition.
Common Pitfalls to Avoid
- Don't use uppercase for variables/functions - compilation error
- Don't forget
mutfor mutable record fields - immutable by default - Don't ignore error handling - errors must be explicitly handled
- Don't use
returnunnecessarily - last expression is the return value - Don't create methods without Type:: prefix - methods need explicit type prefix
- Don't forget to handle array bounds - use
get()for safe access - Don't forget @package prefix when calling functions from other packages
- Don't use ++ or -- (not supported) - use
i = i + 1ori += 1 - Don't add explicit
tryfor error-raising functions - errors propagate automatically (unlike Swift) - Legacy syntax: Older code may use
function_name!(...)orfunction_name(...)?- these are deprecated; use normal calls andtry?for Result conversion
moon Essentials
Essential Commands
moon new my_project- Create new projectmoon run cmd/main- Run main packagemoon build- Build projectmoon check- Type check without building, use it REGULARLY, it is fastmoon info- Type check and generatembtifiles run it to see if any public interfaces changed.moon check --target all- Type check for all backendsmoon add package- Add dependencymoon remove package- Remove dependencymoon fmt- Format code
Test Commands
moon test- Run all testsmoon test --update- Update snapshotsmoon test -v- Verbose output with test namesmoon test [dirname|filename]- Test specific directory or filemoon coverage analyze- Analyze coveragemoon test --filter 'globl'- Run tests matching filtermoon test float/float_test.mbt --filter "Float::*"
README.mbt.md Generation Guide
- Output
README.mbt.mdin the package directory.*.mbt.mdfile and docstring contents treatsmbt checkspecially.mbt checkblock will be included directly as code and also run bymoon checkandmoon test. If you don't want the code snippets to be checked, explicitmbt nocheckis preferred. If you are only referencing types from the package, you should usembt nocheckwhich will only be syntax highlighted. SymlinkREADME.mbt.mdtoREADME.mdto adapt to systems that expectREADME.md.
Testing Guide
Use snapshot tests as it is easy to update when behavior changes.
-
Snapshot Tests:
inspect(value, content="..."). If unknown, writeinspect(value)and runmoon test --update(ormoon test -u).- Use regular
inspect()for simple values (usesShowtrait) - Use
@json.inspect()for complex nested structures (usesToJsontrait, produces more readable output) - It is encouraged to
inspector@json.inspectthe whole return value of a function if the whole return value is not huge, this makes test simple. You needimpl (Show|ToJson) for YourTypeorderive (Show, ToJson).
- Use regular
-
Update workflow: After changing code that affects output, run
moon test --updateto regenerate snapshots, then review the diffs in your test files (thecontent=parameter will be updated automatically). -
Black-box by default: Call only public APIs via
@package.fn. Use white-box tests only when private members matter. -
Grouping: Combine related checks in one
test "..." { ... }block for speed and clarity. -
Panics: Name test with prefix
test "panic ..." {...}; if the call returns a value, wrap it withignore(...)to silence warnings. -
Errors: Use
try? f()to getResult[...]andinspectit when a function may raise. -
Verify: Run
moon test(or-uto update snapshots) andmoon fmtafterwards.
Docstring tests
Public APIs are encouraged to have docstring tests.
///|
/// Get the largest element of a non-empty `Array`.
///
/// # Example
/// ```mbt check
/// test {
/// inspect(sum_array([1, 2, 3, 4, 5, 6]), content="21")
/// }
/// ```
///
/// # Panics
/// Panics if the `xs` is empty.
pub fn sum_array(xs : Array[Int]) -> Int {
xs.fold(init=0, (a, b) => a + b)
}
The MoonBit code in docstring will be type checked and tested automatically.
(using moon test --update). In docstrings, mbt check should only contain test or async test.
Spec-driven Development
- The spec can be written in a readonly
spec.mbtfile (name is conventional, not mandatory) with stub code marked as declarations:
///|
#declaration_only
pub type Yaml
///|
#declaration_only
pub fn Yaml::to_string(y : Yaml) -> String raise {
...
}
///|
#declaration_only
pub fn parse_yaml(s : String) -> Yaml raise {
...
}
-
Add
spec_easy_test.mbt,spec_difficult_test.mbtetc to test the spec functions; everything will be type-checked(moon check). -
The AI or students can implement the
declaration_onlyfunctions in different files thanks to our package organization. -
Run
moon testto check everything is correct. -
#declaration_onlyis supported for functions, methods, and types. -
The
pub type Yamlline is an intentionally opaque placeho
Content truncated.
You might also like
flutter-development
aj-geddes
Build beautiful cross-platform mobile apps with Flutter and Dart. Covers widgets, state management with Provider/BLoC, navigation, API integration, and material design.
drawio-diagrams-enhanced
jgtolentino
Create professional draw.io (diagrams.net) diagrams in XML format (.drawio files) with integrated PMP/PMBOK methodologies, extensive visual asset libraries, and industry-standard professional templates. Use this skill when users ask to create flowcharts, swimlane diagrams, cross-functional flowcharts, org charts, network diagrams, UML diagrams, BPMN, project management diagrams (WBS, Gantt, PERT, RACI), risk matrices, stakeholder maps, or any other visual diagram in draw.io format. This skill includes access to custom shape libraries for icons, clipart, and professional symbols.
ui-ux-pro-max
nextlevelbuilder
"UI/UX design intelligence. 50 styles, 21 palettes, 50 font pairings, 20 charts, 8 stacks (React, Next.js, Vue, Svelte, SwiftUI, React Native, Flutter, Tailwind). Actions: plan, build, create, design, implement, review, fix, improve, optimize, enhance, refactor, check UI/UX code. Projects: website, landing page, dashboard, admin panel, e-commerce, SaaS, portfolio, blog, mobile app, .html, .tsx, .vue, .svelte. Elements: button, modal, navbar, sidebar, card, table, form, chart. Styles: glassmorphism, claymorphism, minimalism, brutalism, neumorphism, bento grid, dark mode, responsive, skeuomorphism, flat design. Topics: color palette, accessibility, animation, layout, typography, font pairing, spacing, hover, shadow, gradient."
godot
bfollington
This skill should be used when working on Godot Engine projects. It provides specialized knowledge of Godot's file formats (.gd, .tscn, .tres), architecture patterns (component-based, signal-driven, resource-based), common pitfalls, validation tools, code templates, and CLI workflows. The `godot` command is available for running the game, validating scripts, importing resources, and exporting builds. Use this skill for tasks involving Godot game development, debugging scene/resource files, implementing game systems, or creating new Godot components.
nano-banana-pro
garg-aayush
Generate and edit images using Google's Nano Banana Pro (Gemini 3 Pro Image) API. Use when the user asks to generate, create, edit, modify, change, alter, or update images. Also use when user references an existing image file and asks to modify it in any way (e.g., "modify this image", "change the background", "replace X with Y"). Supports both text-to-image generation and image-to-image editing with configurable resolution (1K default, 2K, or 4K for high resolution). DO NOT read the image file first - use this skill directly with the --input-image parameter.
fastapi-templates
wshobson
Create production-ready FastAPI projects with async patterns, dependency injection, and comprehensive error handling. Use when building new FastAPI applications or setting up backend API projects.
Related MCP Servers
Browse all serversStructured Workflow guides disciplined software engineering via refactoring, feature creation, and test driven developme
Supercharge your NextJS projects with AI-powered tools for diagnostics, upgrades, and docs. Accelerate development and b
Enhance software testing with Playwright MCP: Fast, reliable browser automation, an innovative alternative to Selenium s
Uno Platform — Documentation and prompts for building cross-platform .NET apps with a single codebase. Get guides, sampl
Advanced MCP server enabling AI agents to autonomously run 150+ security and penetration testing tools. Covers reconnais
Supercharge browser tasks with Browser MCP—AI-driven, local browser automation for powerful, private testing. Inspired b
Stay ahead of the MCP ecosystem
Get weekly updates on new skills and servers.