An extension is a directory with m31a-extension.json plus optional assets. This tutorial assembles the pieces from the previous tutorials into one installable unit.
Prerequisites
- Work through Custom skill, Custom hook, and Custom MCP server, or copy the example assets from
bundle/examples/. - Read Extensions and Extension model.
1. Scaffold the directory
mkdir -p /tmp/m31a-team-ext/{commands,skills/echo-guide,hooks,policies,scripts}
cd /tmp/m31a-team-extCreate m31a-extension.json:
{
"name": "m31a-team-ext",
"version": "1.0.0",
"mcpServers": {
"echo-demo": {
"command": "node",
"args": ["${extensionPath}${/}scripts/echo-server.js"],
"cwd": "${extensionPath}",
"timeout": 30000
}
},
"excludeTools": []
}${extensionPath}, ${workspacePath}, and ${/} are hydrated at load time. mcp add in an extension is not needed; the server definition is part of the manifest.
2. Add a slash command
Create commands/team/summary.toml:
prompt = """
Summarize the current repository for `{{args}}`.
List the main packages, build commands, and test commands.
"""The command name is derived from the path relative to commands/, so this is /summary under the team group. Command files are loaded from user, project, and extension directories in that order; conflicting extension commands are renamed rather than silently replacing user commands.
3. Add a skill
Create skills/echo-guide/SKILL.md:
---
name: echo-guide
description: Explain how to call the echo-demo MCP server and interpret its response.
---
# Echo guide
1. Confirm the server is listed with `/mcp list`.
2. Inspect its schema with `/mcp schema`.
3. Call the `echo` tool with a short `message` argument.
4. Report the exact text returned; do not paraphrase it.The skill will be discovered at extension scope, before user and workspace skills. See Custom skill for front matter constraints.
4. Add an MCP server
Copy the minimal server from Custom MCP server into scripts/echo-server.js. Keep it stdout-clean: protocol traffic must be the only stdout output.
5. Add a hook
Create hooks/hooks.json:
{
"hooks": {
"SessionStart": [
{
"hooks": [
{
"type": "command",
"command": "node ${extensionPath}${/}scripts/on-start.cjs"
}
]
}
]
}
}And scripts/on-start.cjs:
const fs = require('node:fs');
const os = require('node:os');
const path = require('node:path');
fs.appendFileSync(
path.join(os.tmpdir(), 'm31a-extension-hooks.log'),
`${new Date().toISOString()} session started\n`,
);
process.stdout.write('{}');This mirrors the bundled hooks example. Hooks are read only when hooksConfig.enabled is true, and extension hooks are hydrated with any configured extension settings.
WARNING
Hook commands run with your privileges. Review extension hooks exactly as you would review executable code, and keep the log target disposable.
6. Add a policy (optional)
Create policies/policies.toml:
[[rule]]
toolName = "grep_search"
argsPattern = "(\\.env|id_rsa)"
decision = "deny"
priority = 200
denyMessage = "Sensitive file search is blocked by m31a-team-ext."Extension policies live at tier 2. ALLOW decisions and YOLO-mode rules are stripped when loaded, so an extension can only tighten permissions. See Policy evaluation.
7. Validate
m31a extensions validate /tmp/m31a-team-extValidation checks the manifest, version, context file paths, and MCP server transport definitions. It does not execute your hooks or MCP server; smoke-test those separately with node scripts/echo-server.js and node scripts/on-start.cjs.
8. Link and verify
m31a extensions link /tmp/m31a-team-ext
m31a extensions listLinking keeps the source directory in place, so edits are picked up without reinstalling. For one-off runs you can also select extensions explicitly:
m31a -e m31a-team-ext --list-extensionsStart the TUI and check each asset:
/extensions list
/skills list
/mcp list
/mcp schema
/policies list
/hooks panel
/summary "this repository"Expected observations:
- the extension is enabled and listed;
echo-guideappears in the skill list;echo-demoappears with itsechotool schema;- the extension policy appears in
/policies list; SessionStartappears in/hooks panel;/summaryruns the bundled command.
Check the hook log after startup:
cat /tmp/m31a-extension-hooks.log9. Enablement and distribution
Enablement is tracked per extension in extension-enablement.json, with path overrides and user/workspace scopes:
m31a extensions disable m31a-team-ext
m31a extensions enable m31a-team-ext-e none disables all extensions for one invocation. extensions.disabled, security.blockGitExtensions, and security.allowedExtensions provide persistent controls. experimental.extensionReloading is required for hot enable, disable, and reload inside the TUI.
To distribute the extension, commit the directory to a Git repository and use m31a extensions install <source>. Keep credentials out of the manifest; use settings definitions and environment variables instead.
Troubleshooting
| Symptom | Resolution |
|---|---|
validate fails on version | Use semver such as 1.0.0. |
| MCP server not listed | Check the hydrated ${extensionPath} path and mcp.excluded. |
| Skill not visible | Confirm skills/<name>/SKILL.md and skills.disabled. |
| Hook not firing | Check hooksConfig.enabled and the hooks/hooks.json nesting. |
| Policy rule ignored | ALLOW rules from extensions are intentionally discarded. |
Next steps
- Read Extensions for installation sources.
- Read Sandbox hardening before installing a third-party extension.
- Read Session storage for what an extension-driven run records.