taphra / mcp-server
Taphra MCP server starter: tools, a resource and a prompt over stdio (desktop apps, IDEs and other MCP clients) and Streamable HTTP with a bearer token.
Requires
- php: ^8.2
- taphra/taphra: ^1.0
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Taphra's guides are at https://taphra.dev/docs/. Coding agents: read this app's AGENTS.md, and all the guides in one file at https://taphra.dev/llms-full.txt.
A Model Context Protocol server built on Taphra. It exposes a posts table to desktop AI apps, IDEs and other MCP clients: three tools, a resource and a prompt, declared with PHP attributes. Two transports:
- stdio (
php taphra mcp:serve), for clients that start the server as a process on your machine. No token is needed: only that process talks to it. - Streamable HTTP (
POST /mcp), for remote clients. Every request is refused until you set a token.
Requirements
- PHP 8.2 or later, with the
pdo_sqliteextension (php -mlists your extensions) - Composer
Quick start
composer create-project taphra/mcp-server my-app cd my-app php taphra migrate # creates the posts table in app/Database/app.sqlite php taphra mcp:serve --list # what the server offers
--list prints the controllers folder it scanned, then:
Tools: 3
list_posts
get_post
create_post
Resources: 1
Recent posts posts://recent
Prompts: 1
summarise_post
Connect a desktop client (stdio)
Most desktop MCP clients read a JSON configuration file with an mcpServers
section (see your client's documentation for where it lives). Copy
mcp_config_example.json into it, with the absolute path of your project,
then restart the client:
{
"mcpServers": {
"my-app": {
"command": "php",
"args": ["/absolute/path/to/my-app/taphra", "mcp:serve"]
}
}
}
The command works from any working directory. mcp:serve finds every MCP
controller in app/Controllers/ by itself.
You can also talk to it by hand, one JSON-RPC message per line:
printf '%s\n' \ '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"shell","version":"1"}}}' \ '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"create_post","arguments":{"title":"Hello MCP","body":"First post","user_id":1}}}' \ | php taphra mcp:serve
The HTTP endpoint
composer create-project writes a random TAPHRA_MCP_TOKEN to .env
(which app/bootstrap.php reads). Start the server:
php taphra serve
Clients send Authorization: Bearer <token> on every request, with the
token from .env. A token shorter than 32 bytes refuses every request (the
error log says why); to make a new one:
php -r 'echo bin2hex(random_bytes(32)), PHP_EOL;'
| Method and path | What it does |
|---|---|
POST /mcp |
one JSON-RPC message; initialize answers with an Mcp-Session-Id header that later requests send back |
GET /mcp |
405: this server opens no server-initiated stream |
DELETE /mcp |
ends the session named in Mcp-Session-Id |
GET /health (and /) |
{"status":"ok"}, for load balancers |
Without the token (or with a wrong one) /mcp answers 401. A request with an
Origin header gets a 403 unless the origin is a localhost address or is
listed under mcp.allowed_origins in app/Config/ai.yml. Only
application/json bodies are accepted. To use your own authentication instead
of the token, override authorizeMcp() in AppMcpController.
Docker
docker compose up --build
The app reads TAPHRA_MCP_TOKEN from .env; a value set in your shell
wins.
A development container: it runs the migrations and php taphra serve, and
publishes the app on 127.0.0.1:8080 only.
Adding a tool
Add a method with an attribute to PostsMcpController, or create another
class next to it that extends Taphra\Controller (not AppMcpController:
each of those is an MCP endpoint of its own, with a handle() action):
#[McpTool(
name: 'count_posts',
description: 'How many posts an author wrote.',
inputSchema: [
'type' => 'object',
'properties' => ['user_id' => ['type' => 'integer', 'description' => 'Author user ID']],
'required' => ['user_id'],
]
)]
public function countPosts(array $params): array
{
return ['count' => (new PostDataStore())->findCount(['user_id' => (int) $params['user_id']])];
}
mcp:serve picks up new methods and controllers by itself. The HTTP endpoint
serves the controllers McpController::__construct() registers; add a new
controller there:
$this->discovery->discover(new SearchMcpController());
A tool that throws Taphra\Ai\Mcp\McpToolException sends its message back
to the model as a tool error (isError: true), so the model can correct
itself; any other exception is logged on the server and the model gets a
generic message, so database errors and paths stay on the server. An associative array
result is also sent as structuredContent. Methods with an MCP attribute are
never reachable as URL actions.
Layout
app/
Config/ app.yml, routes.yml, databases.yml
Controllers/ McpController (the one HTTP endpoint), PostsMcpController (capabilities), AppMcpController (its base)
Database/ the SQLite file
Lib/ McpToken (writes TAPHRA_MCP_TOKEN at create-project)
DataStores/ PostDataStore
Migrations/ the posts table
Static/ document root (index.php)
bootstrap.php runs on every request and command: .env, mode
composer.json
mcp_config_example.json
taphra the command line
An unset APP_ENV means production (no debug pages); php taphra serve sets
APP_ENV=dev for its server. To use MySQL or PostgreSQL, edit
app/Config/databases.yml.
Licence
This starter, like Taphra, is open-source software under the MIT licence (Copyright 2019-2026 Prodacity LLC); see LICENSE.