HookfishServer, calls
it with Hookfish, and reads Gmail through https://gmail.run.tools.
Prerequisites
- Node.js 20 or later
- pnpm
- A Google account with Gmail enabled
1
Scaffold and start Hookfish
src/index.ts is a Hono application with HookfishServer
mounted at /api. The scaffold also registers the trusted mcp and
secret providers and creates gitignored OAUTH_ENCRYPTION_KEY and
HOOKFISH_API_KEY values. Leave this terminal running.2
Add the Gmail route
Open another terminal, enter the generated project, and install the SDK:Update the generated Hono app to match the version below. The new
/inbox
route is highlighted in green.src/index.ts
Hookfish calls the mounted /api routes through the application’s URL.
hookfish.mcp() creates and connects an MCP client with Hookfish-managed
authentication. await using closes the client when the route handler
exits. The scaffold’s watch process reloads the application after you save
the file.3
Authorize Gmail and read the inbox
Request the inbox:The first request returns
401 authorization_required with a fresh
authorize_url. Open that URL and approve access, then run the curl
command again to receive the inbox result.HookfishError preserves the failed Hookfish response through Hono. You do
not need an onError handler to retain the status, error code, or
authorization URL. If the MCP server later rejects the credential,
Hookfish starts a fresh authorization flow and the new response bubbles
through Hono in the same way.user/personal/gmail/mcp has four parts:
- Namespace:
user/personal - Resource identity:
gmail - Provider implementation:
mcp - Authentication: OAuth
gmail identity
distinguishes this generic MCP connection from other resources under the same
namespace. Hookfish stores the URL on first access and rejects a later access
that supplies a different URL for the same path. A concrete Gmail provider at
user/personal/gmail is a different connection because its final segment is
gmail.
Next, read How Hookfish works and
Application authentication.