We use cookies to enhance your experience on the site
CodeWorlds

MCP & Hooks: Trading Ports and the Bosun's Whistle

The final treasure, @name! Two of the newest, most powerful features deserve a closer look: MCP for connecting to the wider world, and hooks for automating your crew.

MCP: Your Ship's Trade Routes

MCP (Model Context Protocol) connects Claude Code to external tools and data sources - GitHub, databases, Slack, a browser, and many more. Each connection is a trade route to another port.

Add a server from the command line:

1# Add the GitHub MCP server
2claude mcp add github npx -y @modelcontextprotocol/server-github

Or declare servers in a project file so the whole crew shares them:

1.mcp.json

Inspect and manage your connections in the REPL:

1/mcp

You can also load a specific MCP configuration when launching:

1claude \
2  --mcp-config ./mcp.json

Once connected, ask Claude to read a GitHub issue, query a database, or post a message to Slack - all from the terminal.

Hooks: The Bosun's Whistle

Hooks are shell commands that run automatically on events, configured in

.claude/settings.json
. When the whistle blows, the crew acts - no reminders needed.

The key events:

  • SessionStart
    - when a session begins
  • PreToolUse
    - before a tool runs (can block dangerous actions)
  • PostToolUse
    - after a tool runs (e.g. format code)
  • Stop
    - when Claude finishes responding

A hook that formats code after every edit:

1// .claude/settings.json
2{
3  "hooks": {
4    "PostToolUse": [
5      {
6        "matcher": "Edit",
7        "hooks": [
8          { "type": "command", "command": "npx prettier --write ." }
9        ]
10      }
11    ]
12  }
13}

A

PreToolUse
hook can refuse edits to protected paths, guarding your treasure like a cannon on the gunwale.

MCP + Hooks = A Self-Sailing Ship

Combine them and your ship nearly sails itself: MCP opens trade routes to GitHub and your database, while hooks keep the deck spotless - formatting after edits, running tests on stop, and blocking anything dangerous. Add subagents and skills from the previous lessons, and you command a full, disciplined pirate crew. 🏴‍☠️

See you on deck! 🚀

Go to CodeWorlds