Documentation menu

Overview

Taphra

Full-stack PHP for the agent era. AI and MCP included.

Taphra is a full-stack framework for PHP 8.2 and later: routing, controllers and views, a database layer, authentication, queues, email, localisation and billing, plus AI providers, a tool-use agent loop and an MCP server, installed as one Composer package. It runs on ordinary PHP hosting with safe defaults, and its code is explicit enough for you and your coding agents to follow a request from end to end.

Website | Documentation | Getting started | Changelog | Security

Why Taphra

#
  • One install. taphra/taphra includes seven libraries (database, validator, container, crypt, localisation, AI, billing). Each of them also installs on its own, without the framework.
  • AI in the same stack. Anthropic, OpenAI (and OpenAI-compatible servers) and Ollama sit behind one interface with token streaming, structured output, conversations and an agent loop that calls your tools. The same app can expose tools, resources and prompts to MCP clients such as desktop AI apps, IDEs and coding agents.
  • Safe defaults. An unset or unknown APP_ENV runs the app in production mode, and the debug error page only exists in development. In the HTML starters, every request that is not GET, HEAD or OPTIONS must carry a CSRF token (the API starter uses bearer tokens instead, which need none). Values in conditions, Criteria and the query builder are bound as parameters; SQL you write as a string or through the *Raw() methods is yours to keep safe. e() and the form helpers escape what they print; helpers documented as taking HTML, such as p(), and SafeString print it as given. Session cookies are HttpOnly and SameSite=Lax. The MCP HTTP endpoint refuses every request until you give it a token or your own check.
  • You can trace it. A request goes from app/Static/index.php to the front controller, which asks the router for a controller and action, runs the PSR-15 middleware the route declares, and calls the method you wrote. That method returns a string or renders a plain PHP template. Configuration is YAML, one file per concern, with a section per environment. The framework is ordinary PHP classes that you can open and step through.

Where Taphra comes from

#

Taphra is new to the public, but it is not new. Its grandfather is WebAlgo, a minimal PHP framework that the people behind Prodacity wrote and used from 2010 to 2020 to build several projects for their clients, which are still running today. It drew on that senior team's years of building tools on CakePHP, Django, Zend Framework, Symfony and other PHP and Python frameworks, and kept only what had held up on real projects. In all, they have used WebAlgo and Taphra on hundreds of projects.

Much of Taphra started there: DataStores and their Criteria conditions, views, layouts and elements as plain PHP files, cache rules that clear entries when an event fires, widgets, queues and locks. DataStore::find() still takes the arguments it took in WebAlgo. Taphra 1.0 rebuilds that design for PHP 8.2, with PSR standards, Composer packages, a test suite that runs in CI and safe defaults, and adds AI providers, an agent loop and an MCP server. The agent era is its newest chapter, not its first.

Built to be relied on

#
  • Tested on every change. About 2,000 tests on each of PHP 8.2, 8.3 and 8.4, a PostgreSQL suite against a real server, static analysis with PHPStan, end-to-end checks of the four starters (including CSRF, sign-in, token and rate-limit checks) and the five tutorials followed step by step. Bugs fixed before 1.0 have their own regression tests. See CI.
  • Built on proven packages. Symfony Console, YAML and Process, Doctrine Inflector, Whoops, Predis, Nyholm PSR-7 and PHPMailer, installed about 5.7 billion times between them on Packagist (the list).
  • Semantic versioning. No breaking changes within 1.x, fixes in patch releases, and security reports handled as described in SECURITY.md.

Requirements

#
  • PHP 8.2, 8.3 or 8.4 (CI tests all three)
  • Extensions: curl, json, mbstring, pdo, sodium
  • Composer
  • Optional: the PDO driver for your database (pdo_mysql, pdo_pgsql, pdo_sqlite), intl (CLDR plural rules and number formats), pcntl (several queue workers per process), dom (the HTML sanitiser), a Redis server for the Redis cache, session and queue drivers

Install

#
Shell
composer create-project taphra/skeleton my-app
cd my-app
php taphra serve

Open http://127.0.0.1:8000 for the welcome page and http://127.0.0.1:8000/health for a JSON endpoint. php taphra serve starts PHP's development server with APP_ENV=dev. Everywhere else the app runs in production mode until you set APP_ENV=dev (or stg).

Three other starters use the same layout:

Starter What it adds
taphra/api-starter A JSON API with JWT login, a posts resource with ownership checks, CORS, rate limiting and RFC 7807 errors
taphra/ai-chat A streaming chat page (Server-Sent Events), conversation history, a prompt template and an example tool
taphra/mcp-server An MCP server over stdio and Streamable HTTP with example tools, a resource and a prompt
Shell
composer create-project taphra/mcp-server my-mcp-app

The framework itself is the taphra/taphra package (composer require taphra/taphra); the starters are the app structure around it.

A short tour

#

Routes map URLs to controller/action. Without a route, /post/index reaches PostController::index() by convention.

app/Config/routes.yml
# app/Config/routes.yml
GET:
  /posts:          post/index
  /posts/{id:\d+}: post/show

A controller is a class in app/Controllers. Only the public methods you declare can be reached from a URL; the helpers the base class gives you (redirect(), csrf(), sse() and the others) cannot.

app/Controllers/PostController.php
<?php
// app/Controllers/PostController.php
namespace App\Controllers;

use App\DataStores\PostDataStore;

class PostController extends AppController
{
    // GET /posts: renders app/Views/post/index.tpl.php inside the default layout
    public function index(): void
    {
        $this->viewTitle  = 'Posts';
        $this->posts      = PostDataStore::where('status', 'published')
            ->orderBy('id', 'desc')
            ->limit(20)
            ->get();
        $this->autoRender = true;
    }

    // GET /posts/42: the {id} segment arrives as $id; an unknown id answers 404
    public function show(int $id): void
    {
        $this->post       = (new PostDataStore())->findOrFail(['id' => $id])->first();
        $this->viewTitle  = $this->post['title'];
        $this->autoRender = true;
    }
}

Views are PHP templates. The properties you set on the controller become variables, and e() escapes a value for HTML.

app/Views/post/index.tpl.php
<!-- app/Views/post/index.tpl.php -->
<h1>Posts</h1>
<ul>
<?php foreach ($posts as $post): ?>
    <li><a href="/posts/<?= (int) $post['id'] ?>"><?= e($post['title']) ?></a></li>
<?php endforeach; ?>
</ul>
app/Views/post/show.tpl.php
<!-- app/Views/post/show.tpl.php -->
<h1><?= e($post['title']) ?></h1>
<p><?= e($post['body']) ?></p>

A DataStore is a class for one table. Static calls start a query; values in conditions and the query builder are sent to the database as bound parameters (SQL you write yourself goes through the *Raw() methods).

app/DataStores/PostDataStore.php
<?php
// app/DataStores/PostDataStore.php
namespace App\DataStores;

class PostDataStore extends AppDataStore
{
    public $objectName  = 'posts';                       // the table
    protected $fillable = ['title', 'body', 'status'];   // columns accepted from input
}

The AI layer reads app/Config/ai.yml. ${NAME} is replaced with the environment variable of that name.

app/Config/ai.yml
# app/Config/ai.yml
default_provider: anthropic
providers:
  anthropic:
    api_key: "${ANTHROPIC_API_KEY}"
    model: claude-opus-5-5
PHP
use Taphra\Ai\AI;

$reply = AI::complete([
    ['role' => 'user', 'content' => 'Suggest a title for a post about PHP 8.4 property hooks.'],
]);

echo $reply['content'];

AI::stream() yields the answer as it is generated, and AI::agent() runs a loop that lets the model call your tools. A controller can also serve MCP clients: the server lists each method marked #[McpTool] with its input schema and calls it with the client's arguments. It does not check the arguments against the schema, so treat them like form input.

app/Controllers/PostsMcpController.php
<?php
// app/Controllers/PostsMcpController.php
namespace App\Controllers;

use App\DataStores\PostDataStore;
use Taphra\Ai\Mcp\McpController;
use Taphra\Ai\Mcp\McpTool;

class PostsMcpController extends McpController
{
    #[McpTool(
        name: 'find_posts',
        description: 'Titles of published posts that contain a word',
        inputSchema: [
            'type'       => 'object',
            'properties' => ['word' => ['type' => 'string']],
            'required'   => ['word'],
        ],
    )]
    public function findPosts(array $params): array
    {
        return PostDataStore::where('status', 'published')
            ->whereContains(['title'], (string) $params['word'])
            ->pluck('title');
    }
}

php taphra mcp:serve --list prints what was found, and php taphra mcp:serve runs the server over stdio. In an MCP client's configuration:

JSON
{
  "mcpServers": {
    "my-app": { "command": "php", "args": ["/path/to/my-app/taphra", "mcp:serve"] }
  }
}

The guides cover each of these in depth, from routing and DataStores to AI and MCP.

Packages

#

taphra/taphra includes these libraries. Each one is also published on its own and works without the framework.

Package What it does Standalone docs
taphra/db DataStores, a query builder and a schema builder over PDO (SQLite, PostgreSQL, MySQL and MariaDB; SQL Server through generated SQL), plus a Redis connection and an experimental MongoDB connection packages/db
taphra/validator Input validation with built-in and custom rules packages/validator
taphra/container A PSR-11 service container and service providers packages/container
taphra/crypt Authenticated encryption with libsodium packages/crypt
taphra/l10n Translations named by key or by source text, ICU MessageFormat (plural, select, number) packages/l10n
taphra/ai AI providers, streaming, structured output, the agent loop, the MCP server packages/ai
taphra/billing One billing interface with a Stripe provider and a null provider for tests: customers, subscriptions, webhooks packages/billing
Shell
composer require taphra/db

Documentation

#

Start with Getting started, then follow the guide index: configuration, routing and controllers, views, requests and validation, the database, authentication and security, AI, MCP, queues, cache, events, the scheduler, email, localisation, billing, testing, the command line, deployment and upgrading. How Taphra compares with Laravel, Symfony and others is there too, with the cases where they are the better choice.

Security

#

Please report security problems privately, as described in SECURITY.md. Do not open a public issue.

Contributing

#

Bug reports, fixes, docs and new features are welcome. CONTRIBUTING.md explains how to set up the repository and run the tests, and everyone taking part follows the code of conduct.

Licence

#

Taphra is released under the MIT License. Copyright 2019-2026 Prodacity LLC.