Server code
Put a .js file in server/ and it answers an address: server/time.js is /api/time. It runs in Node.js, so it can use any npm package and the database.
server/time.js
Network error: RequestInit: Expected signal ("AbortSignal {}") to be an instance of AbortSignal.
server/notes/stats.js
Network error: RequestInit: Expected signal ("AbortSignal {}") to be an instance of AbortSignal.
server/hash.js
Empty the field and press the button: the page stops you first. The server would answer 422 with the same message.
How a file looks
// server/hash.js → POST /api/hash
const crypto = require('crypto') // Node's own packages, or any from npm
exports.post = (ctx) => {
const { text, algorithm } = ctx.validate(ctx.body, {
text: 'required|max:500',
algorithm: 'required|in:sha256,sha1,md5',
})
return { algorithm, hash: crypto.createHash(algorithm).update(text).digest('hex') }
}
Export get, post, put, patch or del. server/users/[id].js answers /api/users/5 with ctx.params.id. What you return is sent as JSON.
npm packages and CSS libraries in .kreft files
import dayjs from 'dayjs' // kreft add dayjs
import { nanoid } from 'nanoid'
import 'bootstrap/dist/css/bootstrap.min.css' // a CSS file becomes a <link>
Install packages safely with kreft add (blocks untrusted lifecycle scripts and checks for typosquatting), then import them. kreft dev prepares them for the browser (with kreft add -D esbuild), and kreft build puts them in dist/deps. A library from a CDN is one line in index.html, or start with kreft new my-app --ui bootstrap (also tailwind, bulma, pico).
AI Agent Integration (Model Context Protocol — /mcp)
Kreft includes a built-in JSON-RPC 2.0 MCP server at /mcp so AI assistants (Cursor, Claude Desktop, Windsurf) can inspect routes, database schemas, and components or scaffold files directly.
// Connect any MCP client to http://localhost:8000/mcp // Resources: kreft://routes · kreft://schema · kreft://components · kreft://docs // Tools: list_routes · query_database (read-only) · make_resource · read_component