MCP Server PHP Springfield-App
How We Built the MCP Server for the PHP Springfield-App Project
Everyone knows the feeling: you just want AI to write a piece of code,
and you end up in a maze of new protocols, SDKs, and plugins promising “more integration than ever.”
That’s exactly how our adventure with the MCP Server looked—a Model Context Protocol server written in TypeScript,
meant to connect OpenAI GPT with a PHP project (Springfield-App).
🎯 Goal
Build a local MCP server that allows AI to:
- read and write PHP files,
- generate OOP classes (Controller, Model, Service),
- communicate with GPT via the OpenAI API.
In practice—we wanted AI to understand our project’s structure and modify it on the fly.
🧱 Project Structure
sprinfiled-app/
├── app/
├── public/
├── mcp-server/
│ ├── src/
│ │ ├── index.ts
│ │ └── openaiChat.ts
│ ├── tsconfig.json
│ ├── package.json
│ └── .env
⚙️ MCP Server Code Key file: src/index.ts
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
import * as fs from 'fs/promises';
import path from 'path';
import { askGPT } from './openaiChat.js';
const TOOLS = [
{ name: 'read_php_file', description: 'Read PHP file', inputSchema: { type: 'object', properties: { filepath: { type: 'string' } }, required: ['filepath'] } },
{ name: 'write_php_file', description: 'Write PHP file', inputSchema: { type: 'object', properties: { filepath: { type: 'string' }, content: { type: 'string' } }, required: ['filepath','content'] } },
{ name: 'generate_php_class', description: 'Generate PHP OOP class', inputSchema: { type: 'object', properties: { className: { type: 'string' }, type: { type: 'string' } }, required: ['className','type'] } },
{ name: 'ask_gpt', description: 'Ask OpenAI GPT', inputSchema: { type: 'object', properties: { prompt: { type: 'string' } }, required: ['prompt'] } }
];
class PHPProjectServer {
private server: Server;
constructor() {
this.server = new Server({ name: 'php-project-server', version: '1.0.0' }, { capabilities: { tools: {} } });
this.setupHandlers();
}
private setupHandlers() {
this.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: TOOLS }));
this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
const { name, arguments: args } = request.params;
if (name === 'ask_gpt') {
const result = await askGPT(args.prompt);
return { content: [{ type: 'text', text: result }] };
}
return { content: [{ type: 'text', text: `Tool ${name} executed.` }] };
});
}
async run() {
const transport = new StdioServerTransport();
await this.server.connect(transport);
console.error('[MCP] Tools registered:', TOOLS.map(t => t.name).join(', '));
}
}
new PHPProjectServer().run().catch(console.error);
💬 GPT Integration (openaiChat.ts)
import OpenAI from 'openai';
import dotenv from 'dotenv';
dotenv.config();
const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
export async function askGPT(prompt: string): Promise<string> {
const completion = await client.chat.completions.create({
model: 'gpt-4o-mini',
messages: [{ role: 'user', content: prompt }],
});
return completion.choices[0]?.message?.content ?? '';
}
🚀 Running
cd mcp-server
npx tsc
node build/index.js
Result:
[dotenv@17.2.3] injecting env (1) from .env
[MCP] Tools registered: read_php_file, write_php_file, list_php_files, generate_php_class, ask_gpt
🧠 What next?
Here’s where the philosophical part begins. It turned out that MCP works… but VS Code doesn’t yet have a GUI for its tools. As a result, the tools were only available via the terminal (CLI), which led to some interesting conclusions:
“I don’t need a prosthetic hand to write with a pencil.” — Scripterix
That’s why the idea of switching to pure CLI + Codex was born. AI can still create, but without unnecessary layers.
💡 Final conclusion
MCP Server is great technology “for tomorrow.” But today, if you want to build apps, not experiment with protocols, Codex and a simple CLI will give you 10× faster results.
End of MCP—the beginning of simplicity.
“I don’t need a prosthetic hand to write with a pencil.” Now it’s the motto of the Springfield-App project.
📦 ready to paste into the /docs/ folder