A Hono MCP server exposing create, list, update, and delete tools backed by a Postgres database.
About this template
This template is a Model Context Protocol server that runs as a Neon Function. It uses Hono and the MCP TypeScript SDK to serve streamable HTTP at /mcp. It stores a todo list in Lakebase Postgres through a pg pool that it registers with attachDatabasePool from @neon/functions.
The server exposes four tools:
Tool
Description
create_todo
Insert a todo. title is required; notes is optional.
list_todos
List todos, optionally filtered by completion or by a search of the title or notes. limit defaults to 20, with a maximum of 50.
update_todo
Update the fields you pass for a todo id, including completed. You can't clear the title or notes.
delete_todo
Delete a todo by id and return the deleted row.
Every request to /mcp must send Authorization: Bearer <MCP_API_KEY>.
Scaffold it
Install the latest Neon CLI, then create the function from the registry:
Random token (for example, from openssl rand -hex 32) that MCP clients send as Authorization: Bearer <token>; required because the function URL is public.
Yes
neon dev loads .env.local, but neon deploy needs --env .env.local to resolve the value when it evaluates neon.ts. A missing key and a wrong key both return 401. If every request fails, check that MCP_API_KEY was set in the environment you deployed with.
Run locally
neon dev
neon dev serves every function declared in neon.ts and prints its URL (the default is http://localhost:8787). The MCP endpoint is /mcp:
curl http://localhost:8787/# MCP server. Connect an MCP client to /mcp with an Authorization: Bearer token.curl -i http://localhost:8787/mcp# HTTP/1.1 401 Unauthorized
Connect an MCP client
Any client that speaks the streamable HTTP transport can connect to /mcp and send the bearer token. For example, with mcporter:
npm install -g mcportermcporter list http://localhost:8787/mcp --schema --allow-http \ --header "Authorization=Bearer $MCP_API_KEY"mcporter call "http://localhost:8787/mcp.create_todo" --allow-http \ --header "Authorization=Bearer $MCP_API_KEY" \ title="Write the rollback notes" notes="Include the migration step"
You only need --allow-http for local plain-HTTP URLs. To write the config for Cursor, Claude Code, or another supported client instead, use add-mcp:
A Neon Function URL is public, so this template protects /mcp with a static bearer token.
Data model
The first tool call creates the table, so there is no migration step. A single cached promise runs the CREATE TABLE IF NOT EXISTS once per function instance:
CREATE TABLE IF NOT EXISTS mcp_todos ( id serial PRIMARY KEY, title text NOT NULL, notes text, completed boolean NOT NULL DEFAULT false, created_at timestamptz NOT NULL DEFAULT now(), updated_at timestamptz NOT NULL DEFAULT now());