Education › Evals & Harness › Stage 5: Building & improving harnesses

Extending harnesses: MCP, hooks and skills

Adding tools through MCP, lifecycle hooks, reusable skills and plugins without forking the harness.

Advanced ~40 min read Module 17 of 20

No harness ships with every tool and every rule a team needs. Modern harnesses are built to be extended in three main ways: the Model Context Protocol (MCP) connects external tools and data through a standard interface; hooks run your own code at fixed points in the agent's lifecycle to enforce rules or add context; and skills package instructions, scripts and reference material that the agent loads only when a task needs them. This lesson explains each mechanism, when to use which, how to build a small MCP server and a policy hook, and the security questions every extension raises.

After this module you can
  • Explain MCP's client-server model, its primitives and its transports
  • Build a small MCP server that exposes a tool
  • Use lifecycle hooks to enforce policy deterministically
  • Package knowledge as skills with progressive disclosure
  • Assess the security risks of third-party extensions

The Model Context Protocol

MCP is an open protocol for connecting agents to tools and data. The harness runs an MCP client; each integration is an MCP server that exposes capabilities in a standard form. Write the integration once as a server, and any MCP-capable harness can use it. Servers run locally as a subprocess speaking over stdio, or remotely over Streamable HTTP, where authorisation is typically handled with OAuth.

PrimitiveControlled byExample
ToolsThe model decides to call themorders_search, create_ticket
ResourcesThe application or user attaches themA file, a database schema, a document
PromptsThe user picks themA reusable "review this PR" template
orders_server.py: a minimal MCP server with the Python SDK
python
from mcp.server.fastmcp import FastMCP

mcp = FastMCP("orders")

ORDERS = {"A-1042": {"email": "sam@example.com", "status": "delivered", "total": 59.0}}


@mcp.tool()
def orders_search(customer_email: str) -> str:
    """Find a customer's orders. Use before any refund to get the order ID."""
    rows = [f"{oid} | {o['status']} | {o['total']:.2f}"
            for oid, o in ORDERS.items() if o["email"] == customer_email]
    return "\n".join(rows) or f"No orders for {customer_email}."


if __name__ == "__main__":
    mcp.run()          # stdio transport by default
tool callscontextcallseventsallow / blockinstructionsExternal systemsAPIs, dataModelMCP serversstdio or HTTPHarnessMCP clientHookspre/post tool, stopSkillson demand
Harnesses extend in three ways: MCP servers add tools and data, hooks run code at lifecycle events to allow or block, and skills load procedures only when a task needs them.

The function's name, type hints and docstring become the tool's name, schema and description, so everything from the tool design lesson applies: clear names, precise types, actionable results. Test servers with the MCP Inspector before connecting them to an agent.

Hooks: deterministic control

Instructions in a prompt are suggestions; the model usually follows them, but not always. Hooks are code the harness runs at lifecycle events (session start, before a tool runs, after a tool runs, when the agent tries to stop), and they always run. Use them for rules that must hold every time: block edits to protected files, run a formatter after every edit, add the current branch to context at session start, or require tests before stopping. The details differ by harness, but most pass the event as JSON and let the hook allow, block with a reason, or add context.

A pre-tool hook that blocks edits to protected paths
python
#!/usr/bin/env python3
"""Reads the pending tool call as JSON on stdin; exit code 2 blocks it, stderr is the reason."""
import fnmatch
import json
import sys

PROTECTED = ["*.env", "migrations/*", "tests/*", ".github/workflows/*"]

event = json.load(sys.stdin)
path = event.get("tool_input", {}).get("file_path", "")
if event.get("tool_name") in ("edit", "write") and any(fnmatch.fnmatch(path, p) for p in PROTECTED):
    print(f"{path} is protected; explain the needed change to the user instead.", file=sys.stderr)
    sys.exit(2)
sys.exit(0)
Tip

A good rule of thumb: if breaking a rule once would be unacceptable, put it in a hook or the permission policy, not only in the prompt.

Skills: knowledge on demand

Teams accumulate procedures: how to cut a release, how to write a migration, how to use the internal design system. Putting all of that in the system prompt wastes context on every call. A skill packages one procedure as a folder with a short description, detailed instructions and any helper scripts or reference files. The harness keeps only each skill's name and description in context; when a task matches, the agent loads the full instructions, and reads deeper files only if needed. This progressive disclosure keeps context small while making a large library of know-how available.

A skill folder
text
skills/release/
  SKILL.md          name, one-line description, then step-by-step instructions
  checklist.md      detailed pre-release checks, read only when needed
  scripts/
    bump_version.py helper the instructions tell the agent to run

Project instruction files (for example an AGENTS.md at the repository root) are the always-loaded counterpart: short, essential conventions such as build and test commands. Keep them brief and move long procedures into skills.

Choosing a mechanism

  • New capability or data source (query the ticket system): an MCP server, or a built-in tool.
  • Rule that must always hold (never edit migrations): a hook or permission rule.
  • Procedure or expertise used sometimes (how we release): a skill.
  • Conventions needed almost every time (test command, code style): project instructions.

Security of extensions

Every extension runs with real power. A local MCP server is a program on your machine; a remote one sees the data you send it; a hook executes arbitrary commands; a skill's scripts run in your environment. Treat them as dependencies: install from trusted sources, pin versions, review code and permissions, and give remote servers the narrowest OAuth scopes. Watch for tool poisoning, where a malicious server's tool descriptions contain hidden instructions, and remember that tool results from an MCP server are untrusted content for prompt-injection purposes.

Hands-on practice

Extend an agent three ways

  1. Build the orders MCP server above, run it, and inspect its tools with the MCP Inspector.
  2. Connect it to any MCP-capable harness and ask a question that requires orders_search.
  3. Write a pre-tool hook that blocks edits to tests/ and verify the block message reaches the agent.
  4. Write a skill for a team procedure (for example a release checklist) with a SKILL.md and one helper script.
  5. Check that only the skill's description is loaded until a matching task appears.
  6. Review one third-party MCP server's code and list what data and permissions it would get.
Cheat sheet

Extending harnesses: MCP, hooks and skills — at a glance

Main things to focus on

  • MCP: standard client-server protocol for tools, resources and prompts.
  • stdio for local servers, Streamable HTTP plus OAuth for remote ones.
  • Hooks always run: use them for rules that must hold.
  • Skills: name and description in context, full instructions on demand.
  • Project instructions: short, always-needed conventions.
  • Extensions are dependencies: trust, pin, review, scope.

MCP

FastMCP("name") + @mcp.tool()Python server
mcp.run()stdio by default
tools / resources / promptsPrimitives
Streamable HTTP + OAuthRemote servers
MCP InspectorTest before connecting

Hooks

session startAdd context
before toolBlock or modify
after toolFormat, lint, log
on stopRequire evidence

Skills

SKILL.md: name, description, stepsEntry point
reference filesRead only when needed
scripts/Deterministic helpers
progressive disclosureSmall context

Security

pin and review serversSupply chain
narrow OAuth scopesLeast privilege
tool poisoningMalicious descriptions
MCP results are untrustedInjection risk

Common pitfalls

  • Must-hold rules written only in the prompt.
  • Every procedure pasted into the system prompt.
  • Installing unreviewed MCP servers with broad credentials.
  • Treating MCP tool output as trusted.
  • Thin MCP wrappers around every API endpoint.
Quiz

Check your understanding

5 questions · 4 to pass · answers are explained as you go. Your best score is saved on this device only.

Progress and quiz scores are saved in this browser only. Back up or restore on the hub.

Was this lesson useful? Tell me what to improve →