Discover MCPs & agents
Loading MCPs and agents…
Loading MCPs and agents…
Translates multi-file PHP projects to Python using LLM agents — trusts the difference, not the model.
Jump to setup instructionsFetched from the repository for this visit.
Millions of production systems still run on legacy PHP: banks, insurers, government services, e-commerce platforms built 15+ years ago. That code works, but it's stranded: modern data science, machine learning, and AI tooling lives overwhelmingly in the Python ecosystem. Rewriting by hand is slow, expensive, and risky. Every subtle behavioral difference is a potential production incident.
php2python explores an automated path: translate a multi-file PHP project into Python using LLM agents, then prove the translation behaves identically by running both programs and comparing their output, not by trusting the model.
The core problem it tackles is cross-file consistency. Translating one file is easy; translating five files that call each other is where LLMs fall apart: renamed methods, dropped arguments, invented code. This pipeline treats the model as an unreliable worker inside a system of deterministic checks, rather than as a trusted translator.
For each PHP file, main.py orchestrates a chain of gpt-4o-mini agents:
Translated class files become live Python modules (generated/*.py,
registered in sys.modules so imports between them resolve). The entry
point runs with its output captured, then the original PHP runs via the
php CLI and the two outputs are compared after normalization
(timestamps masked, numeric formats normalized: PHP's 100 equals
Python's 100.0).
The finish line is literal: Outputs are equal!
Prompt rules alone don't make a small LLM reliable. This repo's answer is
a set of deterministic mechanisms in main.py that catch and correct the
model's recurring failure modes in code, where compliance isn't optional:
build_class_ownership,
remove_duplicate_classes) : the model loves inlining stub copies of
other files' classes (a cut-down Order inside Customer.py), which
breaks isinstance checks and drops methods. Ownership is derived from
the PHP sources themselves; any class defined outside its owning module
is deleted and replaced with a real import.strip_fabricated_attr_resets) : the
entry-point PHP only ever calls methods, so any generated
object.attribute = ... statement in Main is a hallucination that
clobbers constructor state. Matching lines are removed mechanically.strip_bad_import) : imports of nonexistent
modules (from Logger import Logger) are detected from Python's own
ModuleNotFoundError and deleted, no LLM call needed.culprit_generated_files, module_file_for_missing_attr,
reload_all_modules).normalize) : masks wall-clock timestamps and
normalizes values on both sides so the comparison tests
behavior, not incidental formatting, while preserving line structure,
so real differences still fail.Every generated file is written to generated/ before execution and
compiled with its real path, so crash tracebacks point at actual files
and lines instead of <string>.
openai package (pip install openai)php -v to check): used to produce the reference outputOPENAI_API_KEY set in the environmentexport OPENAI_API_KEY="your-key"
python3 main.py
GitHub checked 15h ago - refresh overdue. Recently viewed repositories target hourly refresh.
Find a documented setup for your client. No sign-in, installation, or tool execution.
If this MCP is also published on mcpchannel.ai, you can subscribe from Browse and use the gateway config there instead.