Skip to content

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 ​

1. Scaffold the directory ​

bash
mkdir -p /tmp/m31a-team-ext/{commands,skills/echo-guide,hooks,policies,scripts}
cd /tmp/m31a-team-ext

Create m31a-extension.json:

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:

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:

markdown
---
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:

json
{
  "hooks": {
    "SessionStart": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "node ${extensionPath}${/}scripts/on-start.cjs"
          }
        ]
      }
    ]
  }
}

And scripts/on-start.cjs:

javascript
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:

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 ​

bash
m31a extensions validate /tmp/m31a-team-ext

Validation 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.

bash
m31a extensions link /tmp/m31a-team-ext
m31a extensions list

Linking keeps the source directory in place, so edits are picked up without reinstalling. For one-off runs you can also select extensions explicitly:

bash
m31a -e m31a-team-ext --list-extensions

Start the TUI and check each asset:

text
/extensions list
/skills list
/mcp list
/mcp schema
/policies list
/hooks panel
/summary "this repository"

Expected observations:

  • the extension is enabled and listed;
  • echo-guide appears in the skill list;
  • echo-demo appears with its echo tool schema;
  • the extension policy appears in /policies list;
  • SessionStart appears in /hooks panel;
  • /summary runs the bundled command.

Check the hook log after startup:

bash
cat /tmp/m31a-extension-hooks.log

9. Enablement and distribution ​

Enablement is tracked per extension in extension-enablement.json, with path overrides and user/workspace scopes:

bash
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 ​

SymptomResolution
validate fails on versionUse semver such as 1.0.0.
MCP server not listedCheck the hydrated ${extensionPath} path and mcp.excluded.
Skill not visibleConfirm skills/<name>/SKILL.md and skills.disabled.
Hook not firingCheck hooksConfig.enabled and the hooks/hooks.json nesting.
Policy rule ignoredALLOW rules from extensions are intentionally discarded.

Next steps ​

Built with VitePress. Powered by NVIDIA NIM.