Build & Deploy AI Agents

Exercise 5

Build: MCP

Expose review-pr and review-diff as MCP tools at /mcp.

Build Module 5 on top of your Module 4 work (or checkpoint-4-hitl-schedule).

The goal

Offer the reviewer you built as MCP tools so any client can call it:

  • ReviewMCP extends McpAgent,
  • review-pr and review-diff registered in init(),
  • served at /mcp over Streamable HTTP.

Build the server

Have your agent scaffold ReviewMCP with an McpServer. Register review-pr (fetch a public PR, run the reviewer) and review-diff (review a raw diff), reusing runReview and the generalist prompt from Module 2.

Wire it up

Mount with ReviewMCP.serve("/mcp", { binding: "ReviewMCP" }) and route /mcp in the Worker’s fetch handler. In wrangler.jsonc, add a second Durable Object binding and a new_sqlite_classes migration for ReviewMCP, and re-export the class from the entrypoint.

Critical gotcha

Forget the re-export or the migration and the binding silently no-ops at runtime. Cloudflare will not error.

Stuck?

git checkout checkpoint-5-mcp -- src/

Done when

  • An MCP client (or curl) to /mcp lists review-pr and review-diff.
  • Calling review-pr on a public PR returns structured findings.
  • You can explain why the re-export and migration are required.