A minimal Next.js starter for TypeScript developers who want to run MTHDS methods from a web app, through the mthds SDK.
MTHDS is an open standard for AI methods, and a method runs on any MTHDS-compliant runtime. This repository is a Next.js app that runs methods from its Server Actions: each action reads a .mthds bundle from disk, sends it with your inputs to an MTHDS API through the mthds SDK, and turns the output into a typed value the page renders.
Its example methods are presented as tabs, and each is a pattern to copy:
- Text entities (
methods/hello) extracts the people, organizations and dates named in a text you paste. - PDF summary (
methods/summarize-pdf) reads a PDF you upload and returns its title, its document type and its key points. - Image generation (
methods/generate-image) turns a text prompt into an image.
- Node.js 22 or later.
- An MTHDS API for the app to call. The
mthdsSDK speaks the MTHDS protocol, so any MTHDS-compliant API works. Pipelex, the reference runtime, is one of them: you can run itspipelex-apiserver yourself, which is where the shipped.env.examplepoints, or call Pipelex's hosted API.
From the root of a clone of this repository:
cp .env.example .env.local make install make dev
.env.local points the app at an MTHDS API on http://127.0.0.1:8081. If yours runs elsewhere or asks for a key, set the two variables under Configuration first. Then open http://localhost:3000 and run a method from any tab.
The app reads two variables from .env.local, which git ignores:
| Variable | Purpose | Value in .env.example |
|---|---|---|
MTHDS_BASE_URL |
Base URL of your MTHDS API, host only, with no path | http://127.0.0.1:8081 |
MTHDS_API_KEY |
API key the SDK sends to that API as a bearer token | test-api-key |
Always set MTHDS_BASE_URL: when it is unset, the SDK falls back to its own default API rather than yours.
- The browser calls a Server Action, one per method:
runHelloPipeline,runSummarizePdfPipelineorrunGenerateImagePipeline. - The action reads the method's
.mthdsbundle from disk and callsMthdsApiClient.execute()with the method, the pipe to run and the inputs. The method travels as its tree, thefilesmap from each file's path in the method to its content, here the one filemain.mthds. The action names the pipe by its qualified reference, the bundle's domain then the pipe's code (hello.extract_entities), so the reference stays exact whatever else is loaded. - The MTHDS API runs the pipe and returns its output, loosely typed.
- A
parseXxx()narrower insrc/types/checks that output and returns a typed value. - The page renders the value, or
<ErrorDisplay>renders thePipelineErrorthe action returned instead of throwing.
Every error the mthds SDK raises carries the MTHDS protocol's problem document, and the app shows each failure from that problem, never from an error's class or message. <ErrorDisplay> shows the problem's title and detail, its next step, and who must act, which sets its tone: amber when the fix is on the app's side (the request, the method or the account), red when it is the API's (its set-up or a failure of the runtime). Under "Technical details" it shows the problem's code and the request id to hand to whoever runs the API. For some next steps the app adds its own help: a missing or refused key shows the MTHDS_API_KEY line for .env.local, a configuration problem points at .env.local or at the API's own set-up, a method that does not validate points at its bundle, and an API that cannot be reached says to start it. A failure the app catches itself, such as an output its narrower cannot read, is shown with the same layout and no code.
A file input, such as the PDF, is read into a data URL in the browser and wrapped in an MTHDS Document input on the server, and a generated image comes back as a URL. File and image inputs explains both.
methods/ # the .mthds bundles, one directory per method
public/sample-invoice.pdf # sample PDF, so the PDF example works out of the box
src/
app/ # Next.js App Router (layout, page, globals.css)
actions/ # 'use server' Server Actions, one per method
lib/
mthdsClient.ts # MthdsApiClient singleton
loadBundle.ts # reads each .mthds bundle into the method's files map
errors.ts # classifyPipelineError: a problem → PipelineError
fileEncoding.ts # data-URL validation + Document input envelope
clientFile.ts # browser File → base64 data URL
components/ # ExampleTabs + per-example form and result components
types/ # concept types + parseXxx() narrowers
e2e/ # optional Playwright specs
docs/ # file and image inputs, development
- Add
methods/<name>/main.mthds. Write it by hand from the MTHDS guide Write your first method, or have Claude Code or Codex build it with the Pipelex plugin. - Add a loader in
src/lib/loadBundle.ts, a type and itsparseXxx()narrower insrc/types/, and a Server Action insrc/actions/that names the pipe as<domain>.<pipe_code>. - Call the action from a component. The example methods are the patterns to copy.
To make this project your own, run /bootstrap in Claude Code: it replaces the template's name, description and license holder everywhere, and resets the version and the changelog.
- File and image inputs: how a file reaches a method, and how a generated image comes back.
- Development: every make target, the optional end-to-end tests, and working against a local checkout of the
mthdsSDK. - mthds.ai: the MTHDS standard, its language and its protocol.
Run make all after every change: it runs ESLint, the Prettier check, the TypeScript check, the unit tests and a production build, the same gates as CI. If the Prettier check fails, run make format. Development has the rest.
This project is licensed under the MIT license. Runtime dependencies are distributed under their own licenses via npm.