Skip to content

MCP Server (Self-Serve)

AgentsMesh ships a built-in MCP server that lets AI agents read and write the canonical .agentsmesh/ directory directly. Agents can list rules, create commands, update permissions, and trigger generate — without leaving the conversation.

Quick start

agentsmesh init seeds .agentsmesh/mcp.json with the server entry automatically. The seeded entry looks like:

{
"mcpServers": {
"agentsmesh": {
"type": "stdio",
"command": "npx",
"args": ["-y", "agentsmesh", "mcp"]
}
}
}

After init, run agentsmesh generate to project the entry into each target’s native MCP config file (e.g. .claude/settings.json, .cursor/mcp.json, .gemini/settings.json).

Configuration

Three deployment forms are supported:

FormWhen to use
npx -y agentsmesh mcpZero-install default. Seeded on init. Works on any machine with Node.js.
command: "agentsmesh"Recommended after npm install -D agentsmesh. Faster startup; no network round-trip.
Global installAir-gapped or shared machines. npm install -g agentsmesh then use command: "agentsmesh".

Recommended form (after adding agentsmesh as a dev dependency):

{
"mcpServers": {
"agentsmesh": {
"type": "stdio",
"command": "agentsmesh",
"args": ["mcp"]
}
}
}

The server reads projectRoot from the process working directory at startup. No configuration flags are accepted; the MCP host controls the working directory via the cwd field in the MCP server entry when needed.

Tools reference

Canonical reads (8)

ToolDescription
list_rulesList rules with summary metadata
get_ruleGet a single rule by name
list_commandsList commands with summary metadata
get_commandGet a single command by name
list_agentsList agents with summary metadata
get_agentGet a single agent by name
list_skillsList skills
get_skillGet one skill (frontmatter + body + supporting filenames)

Skill file read (1)

ToolDescription
get_skill_fileRead a skill supporting file by skill name and relative path

Settings reads (5)

ToolDescription
get_configRead agentsmesh.yaml
list_mcp_serversList MCP servers in canonical mcp.json
get_permissionsRead permissions.yaml
get_hooksRead hooks.yaml
get_ignoreRead ignore patterns

Capabilities (2)

ToolDescription
list_target_capabilitiesList the support matrix for all targets
get_target_capabilitiesGet capabilities for a specific target ID

Canonical mutations (12)

ToolDescription
create_ruleCreate a new rule
update_ruleUpdate a rule (replace or merge)
delete_ruleDelete a rule
create_commandCreate a new command
update_commandUpdate a command
delete_commandDelete a command
create_agentCreate a new agent
update_agentUpdate an agent
delete_agentDelete an agent
create_skillCreate a skill with optional supporting files
update_skillUpdate a skill (supportingFiles: string = write, null = delete)
delete_skillDelete a skill

Settings mutations (7)

ToolDescription
update_configUpdate agentsmesh.yaml (replace or merge)
add_mcp_serverAdd an MCP server entry to .agentsmesh/mcp.json
update_mcp_serverUpdate an MCP server entry (replace or merge)
remove_mcp_serverRemove an MCP server entry
update_permissionsUpdate permissions.yaml (replace or append)
update_hooksReplace hooks.yaml content
update_ignoreUpdate ignore patterns (replace or append)

Orchestration (6)

ToolDescription
generateGenerate target-native config from canonical
lintLint canonical files
checkDetect drift between canonical and lockfile
diffPreview generation changes
importImport another tool’s config into canonical
convertConvert directly from one tool to another

All mutation tools and orchestration tools accept an optional dry_run: true parameter that returns the planned changes without writing to disk.

Resources reference

The server exposes 16 readable resources, derived from the tools that have a resourceUri:

URIMapped tool
agentsmesh://canonical/ruleslist_rules
agentsmesh://canonical/rules/{name}get_rule
agentsmesh://canonical/commandslist_commands
agentsmesh://canonical/commands/{name}get_command
agentsmesh://canonical/agentslist_agents
agentsmesh://canonical/agents/{name}get_agent
agentsmesh://canonical/skillslist_skills
agentsmesh://canonical/skills/{name}get_skill
agentsmesh://canonical/skills/{name}/files/{path}get_skill_file
agentsmesh://configget_config
agentsmesh://canonical/mcplist_mcp_servers
agentsmesh://canonical/permissionsget_permissions
agentsmesh://canonical/hooksget_hooks
agentsmesh://canonical/ignoreget_ignore
agentsmesh://capabilitieslist_target_capabilities
agentsmesh://capabilities/{targetId}get_target_capabilities

Error codes

All tool errors return a structured envelope { code, message, details? }.

CodeMeaning
NOT_FOUNDThe requested item does not exist
ALREADY_EXISTSA create was attempted for a name that already exists
VALIDATION_FAILEDInput did not pass schema validation
INVALID_NAMEName contains disallowed characters or is reserved
PATH_TRAVERSALA path argument attempted to escape the canonical directory
PROTECTED_FILEThe target file (_root.md) cannot be deleted
LOCK_HELDThe generate lock is held by another process
NO_PROJECTNo agentsmesh.yaml was found in the working directory
IO_ERRORA filesystem read or write failed
LIMIT_EXCEEDEDA content or file-count limit was reached

Security

The MCP server relies on the host trust boundary — no authentication is built in. The host process (Claude Code, Cursor, etc.) controls which servers agents may invoke.

Guards in place:

  • Path-traversal protection — all paths are resolved relative to .agentsmesh/ and rejected if they escape it.
  • _root.md protection — the root rule cannot be deleted.
  • Resource limits — individual file writes are capped at 1 MiB; canonical name length, hooks-per-event, args, and env values all have explicit caps.
  • Flat canonical namescreate_rule / create_command / create_agent reject names containing /, .., or characters outside [A-Za-z0-9_-]. Names that are Windows reserved devices (CON, AUX, NUL, COM1-9, LPT1-9) or contain <>:|?* are rejected so generation stays portable.
  • Strict write-tool input validation — every mutation tool is gated by a Zod schema that rejects shell-meta payloads before they reach disk:
    • add_mcp_server / update_mcp_server reject command strings containing any of the shell metacharacters ; & | $ \ < > ! \or newlines, env keys outside[A-Za-z_][A-Za-z0-9_]*, URLs whose protocol is not http(s)://`, args arrays longer than 100, and unknown server fields.
    • update_hooks requires a matcher free of CR/LF, requires every entry to have command or prompt, and caps each event at 100 entries (50 nested).
    • update_permissions validates each entry against Tool / Tool(matcher) and rejects newlines that could escape YAML quoting.
  • Redacted error messagesMcpError refuses to construct messages containing absolute paths, and the server fallback path runs raw Error.message strings through a redactor before returning them to the client. IO_ERROR envelopes include the underlying errno code in details so failures stay diagnosable without leaking layout.

Troubleshooting

Server does not appear in the tool list

The MCP entry was seeded into .agentsmesh/mcp.json but you must run agentsmesh generate to project it into each target’s native settings file. Run generate, then restart your AI tool.

NO_PROJECT error when calling any tool

The server process started in a directory without agentsmesh.yaml. Set the cwd field in the MCP server entry to your project root, or start your AI tool from the project root.

LOCK_HELD on generate

Another process (e.g. agentsmesh watch or a parallel generate) holds the generate lock. Wait for it to finish or check for stale lock files in .agentsmesh/.

npx form is slow to start

npx -y agentsmesh mcp downloads the package on first use and caches it. For faster startup, install agentsmesh as a dev dependency and switch the entry to command: "agentsmesh", args: ["mcp"].

PATH_TRAVERSAL error

A skill or file path argument contained .. or an absolute path. Use only relative paths within the skill directory.

Migrating existing projects

If your project already has .agentsmesh/mcp.json and you want to add the self-serve server entry manually:

{
"mcpServers": {
"agentsmesh": {
"type": "stdio",
"command": "npx",
"args": ["-y", "agentsmesh", "mcp"]
}
}
}

Then run agentsmesh generate to project the entry.

Alternatively, re-running agentsmesh init on an existing project will inject the entry if it is absent, without overwriting other canonical files.