# Connect an agent

Hatch ships an MCP server, so any agent that speaks MCP can search, read and write your notes. It runs on your computer, reads the vault folder directly and needs no account. The app doesn't have to be open.

## Set it up

The server is the npm package `@hatchmd/mcp`. Give it the path to your vault.

````tabs
tab: Claude Code
```sh
claude mcp add hatch -- npx -y @hatchmd/mcp /path/to/your/vault
```
tab: Codex
```sh
codex mcp add hatch -- npx -y @hatchmd/mcp /path/to/your/vault
```
tab: Cursor
In `.cursor/mcp.json` (one project) or `~/.cursor/mcp.json` (every project):

```json
{
  "mcpServers": {
    "hatch": { "command": "npx", "args": ["-y", "@hatchmd/mcp", "/path/to/your/vault"] }
  }
}
```
tab: Claude Desktop
In Settings, Developer, Edit Config:

```json
{
  "mcpServers": {
    "hatch": { "command": "npx", "args": ["-y", "@hatchmd/mcp", "/path/to/your/vault"] }
  }
}
```
````

Add `--read-only` after the path to leave out every tool that writes. Without a path, the server uses `HATCH_VAULT`.

To try it, ask your agent "what's in my vault?" or "file this as a note". It reads the vault's guide first, searches before it creates anything, and links notes with `[[Note]]`.

## Tell agents where things go

Write your filing rules in `AGENTS.md` at the vault root, or in `.hatch/AGENTS.md`: which folder meetings go in, what to tag, what never to touch. The `vault_guide` tool hands agents those rules along with what it learns from the vault itself: its folders, common tags and properties, templates and daily notes.

## Tools

| Kind | Tools |
|---|---|
| Reading | `vault_guide`, `search_notes`, `query_notes` (by property), `read_note`, `list_notes`, `list_tags` |
| Writing | `create_note` (from a template, with properties and tags), `append_to_note`, `add_to_section`, `replace_in_note`, `move_note` (updates links to it), `add_to_daily_note` |
| Components and sites | `components`, `make_component`, `check_component`, `check_component_file`, `save_component`, `slides`, `site_look`, `check_site_style` |

Writes touch only what the tool names: `append_to_note` adds to the end, `replace_in_note` changes only the text it matches, and each write reads the note fresh first. If the note is open in Hatch at the time, the app merges the change into what's on screen. Plugins in the vault can add tools of their own (see [Writing a Hatch plugin](https://hatch-docs.pages.dev/building-on-hatch/writing-a-hatch-plugin/)).

## From your own code

To give an agent you're building the same tools, use `@hatchmd/ai-sdk` with Vercel's AI SDK (see [Agent memory with the AI SDK](https://hatch-docs.pages.dev/agents/agent-memory-with-the-ai-sdk/)), or start the server yourself with `createHatchMcpServer` from `@hatchmd/mcp`.
