Building an MCP server in PHP
How I structured a PHP Model Context Protocol server with schema-typed tools, resources, guided prompts, and safe agent workflows.
- MCP
- PHP
- LLM
- DeepSeek
I built a Model Context Protocol (MCP) server in PHP for Borderless Fetch. The goal was simple: give an agent — and an in-app DeepSeek chatbot — a typed, permission-aware way to work with orders, NGN wallets, Paystack top-ups, and fulfilment steps.
Why PHP
The surrounding product already lived in PHP. Putting the MCP surface next to that stack meant I could reuse existing domain knowledge instead of standing up a separate service language for the protocol layer.
JSON-RPC at /mcp
The server exposes a JSON-RPC endpoint at /mcp. Clients talk to that endpoint the same way they would with other MCP transports that speak JSON-RPC: list tools, call tools, read resources, and follow prompts.
Keeping the contract on one endpoint made it easier to reason about auth, rate limits, and logging in one place.
Schema-typed tools
The server ships with about 16 schema-typed tools. Each tool has an explicit input shape. That matters when a language model is choosing arguments: vague free-form payloads are harder to validate and easier to misuse.
Typed schemas also help humans. When I am debugging a failed tool call, I can compare the model output against the schema instead of guessing which field was optional.
Resources and guided prompts
Besides tools, the server exposes borderless:// resources and guided prompts. Resources give the agent structured context it can read without inventing side effects. Guided prompts steer common workflows — for example walking through an order or wallet flow — so the agent is not starting from a blank system message every time.
Permissions and confirmation
Role and permission scoping sit in front of the tools. Not every caller gets every operation.
For anything that changes state, the server expects explicit confirmation before the mutation runs. That pattern is boring on purpose. Agents are good at sounding confident; production systems still need a human- or policy-gated yes before money moves or fulfilment advances.
Rate limiting and the chatbot
Rate limiting protects the /mcp surface from noisy clients and runaway loops. The in-app DeepSeek chatbot calls these tools rather than inventing direct side effects. The model proposes; the MCP layer validates, scopes, and confirms.
What I would keep next time
- One JSON-RPC entry point with clear logging.
- Schema-first tools before clever agent behaviour.
- Resources and prompts as first-class companions to tools.
- Confirmation gates on mutations, not after the fact.
If you are implementing MCP in PHP, start with the tool schemas and permission model. The chatbot integration is the easy part once the server refuses to do unsafe work.