Download the PHP package errogaht/doctrine-mcp-bundle without Composer

On this page you can find all versions of the php package errogaht/doctrine-mcp-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package doctrine-mcp-bundle

Doctrine MCP Bundle

Doctrine MCP Bundle exposes an explicitly allow-listed Doctrine ORM model and application-defined capabilities through the Model Context Protocol. It is an independent Symfony bundle built on the official mcp/sdk Streamable HTTP transport and does not require symfony/mcp-bundle.

The bundle is intended for authenticated, multi-user Symfony applications. Symfony Security identifies the caller, mandatory query scopes constrain every Doctrine query, and PHP attributes define the public contract. Doctrine mapping by itself never exposes an entity or field.

Features

Requirements

Installation

If Symfony Flex does not register the bundle automatically, enable it manually:

Load the bundle route:

The default MCP endpoint is /_mcp. Protect it with the host application's firewall and access rules:

The bundle does not issue access tokens and does not implement OAuth. Session cookies, JWT, OAuth access tokens, service credentials, or another authentication mechanism may be used as long as the Symfony firewall resolves an authenticated UserInterface for the request.

Quick start

1. Configure the endpoint

Create the package configuration:

[!IMPORTANT] Configure every public hostname in allowed_hosts. Setting allowed_hosts: false disables DNS-rebinding protection and should only be used behind a trusted proxy that performs an equivalent check.

2. Expose a Doctrine entity

Apply McpEntity to the class and McpField only to properties that belong to the public MCP contract:

Read is the only operation enabled by default. Create, update, and delete must be enabled on the entity, and individual fields must separately opt in to creatable or updatable.

3. Add a mandatory row scope

Every exposed entity must have at least one scope. A scope adds actor-specific predicates to Doctrine queries and owns server-controlled creation data:

With standard Symfony service defaults, the scope is autowired, autoconfigured, and tagged automatically:

4. Validate the public contract

Run the validation command before exposing the endpoint:

Connect an MCP client to https://app.example.com/_mcp and provide the authentication headers or cookies required by the application's firewall. MCP session negotiation and the Mcp-Session-Id header are handled by compatible clients automatically.

How entity exposure works

The public contract is an allow-list assembled from both Doctrine metadata and MCP attributes:

  1. Doctrine must manage the class and property;
  2. the class must have #[McpEntity];
  3. every visible property must have #[McpField];
  4. the requested operation must be enabled on the entity;
  5. a field must be separately writable for create or update;
  6. every addressed row must pass all configured query scopes;
  7. configured Symfony voters and Validator constraints must pass.

Unannotated Doctrine entities and properties are invisible. The bundle never infers exposure from ORM mapping, serializer groups, forms, or API Platform metadata.

Entity configuration

McpEntity

McpEntity defines the public entity name and its operation-level policy:

Option Type Default Description
name ?string Doctrine class short name Stable public name used by all generic tools.
description ?string null Description shown to MCP clients and agents.
operations list<McpOperation> [Read] Allowed CRUD operations.
scopes list<class-string> [] Entity-specific EntityScopeInterface services. At least one entity or global scope is required.
permissions array<string, string> [] Symfony voter attributes keyed by read, create, update, or delete.
handler ?string null Service ID of a custom EntityMutationHandlerInterface.

Entity names must be unique across all Doctrine entity managers.

McpField

McpField defines a property's public representation and field-level policy:

Option Type Default Description
name ?string Property name Public field name.
description ?string null Human-readable meaning and usage constraints.
readable bool true Include the field in MCP output.
creatable bool false Accept the field during create.
updatable bool false Accept the field during update.
filterable bool true Allow filtering for scalar fields.
operators list<FilterOperator> [Eq] Explicitly allowed filter operators.
sortable bool false Allow ordering by the field.
sensitive bool false Replace serialized and audited values with [REDACTED].
serverControlled bool false Reject the field in create and update input even if a write flag was set accidentally.
format ?string null Format hint returned by doctrine_describe_entity.
reference ?string null Name of a ReferenceProviderInterface available through doctrine_reference_values.

[!NOTE] format is descriptive metadata for the agent. Use PHP types, Doctrine types, Symfony Validator constraints, or a custom mutation handler for server-side validation.

Supported values

The built-in codec safely converts common Doctrine and PHP values:

Value MCP representation
Strings, integers, floats, booleans, null Native JSON value
Doctrine integer types JSON integer
Doctrine float and decimal types JSON number
Doctrine boolean JSON boolean
Date and datetime types ISO-8601 string
Symfony Uuid RFC 4122 string
Backed enum Backing value
Unit enum Case name
Doctrine JSON JSON object or array
Association { "entity": "EntityName", "id": { ... } }

Unknown object graphs are rejected instead of being serialized recursively.

Built-in MCP tools

The bundle exposes a fixed tool surface. Adding more entities does not create one tool per entity:

Tool Purpose
doctrine_list_entities List entities and operations available to the current actor.
doctrine_describe_entity Describe identifiers, fields, formats, filters, write flags, and references.
doctrine_search Search scoped records with allow-listed filters, sorting, limits, and cursor pagination.
doctrine_get Read one scoped record by its complete identifier object.
doctrine_create Preview or create an entity.
doctrine_update Preview or update writable fields on a scoped entity.
doctrine_delete Preview or delete a scoped entity.
doctrine_reference_values Read actor-aware allowed-value suggestions from a reference provider.

All successful results contain ok, operation, and traceId.

Identifiers

Identifiers are always objects, including single-column identifiers:

Composite identifiers must contain every identifier field and no additional fields.

Search and filtering

Equality can use the short form:

Other operators use an explicit specification:

Supported operators are eq, in, contains, gt, gte, lt, and lte. An operator works only when it is listed in that field's McpField.operators. Associations cannot be filtered through the generic tool.

Search returns items and an opaque nextCursor. It deliberately does not execute a separate total-count query. Without an explicit sort, results are ordered by Doctrine identifier fields.

Mutation preview

Create, update, and delete default to dryRun: true:

A successful preview returns sanitized before and after values, but does not flush the standard Doctrine mutation. The caller must review the preview and explicitly send dryRun: false to apply it.

Symfony Validator constraints run for both previews and applied create/update operations. Mutation attempts also produce audit records.

Associations

Associations are represented as shallow references; the bundle never serializes an unbounded Doctrine object graph:

For a writable to-one association, send either an identifier object or a scalar for a single-column identifier:

The target entity must also be exposed with McpEntity. It is resolved using the target entity's read scopes and voter, so a caller cannot attach an inaccessible record.

Writable collections use explicit add/remove change sets:

The entity must provide conventional addTag() and removeTag() methods, or use a custom mutation handler. The number of association changes is bounded by query.max_association_items.

Row-level scopes

EntityScopeInterface is the primary data-isolation boundary:

Scopes are applied to search, get, update, delete, and writable association resolution. The bundle does not use EntityManager::find() for actor-addressable records.

Use bound parameters in every scope. Scope logic may add joins and predicates for ownership, organization membership, soft deletion, geographic access, or workflow state.

Global scopes apply to every exposed entity:

If an application intentionally exposes unscoped records, opt in explicitly:

[!WARNING] UnrestrictedScope is a security-review marker, not a convenience default. Never use it for tenant-owned or user-owned data.

If Symfony autoconfiguration is disabled, tag scope services manually with doctrine_mcp.scope.

Symfony voters

Scopes decide which rows are addressable. Voters decide whether the current actor may perform an operation:

Discovery and collection checks authorize against the entity class name. Record-specific get, update, and delete checks authorize against the resolved entity object. Create is authorized against the initialized entity object.

Scopes remain mandatory when voters are configured. A voter is not a replacement for a query predicate because filtering unauthorized rows after loading them can leak data and identifiers.

Actor providers

The default actor provider reads the authenticated user from Symfony Security and creates an ActorContext containing the user identifier, original UserInterface, and roles.

Implement ActorProviderInterface to add tenant identifiers or other scalar security attributes:

Configure its service ID:

Actor attributes must contain only scalar values or null. Scopes and custom handlers may inspect both ActorContext.attributes and the original ActorContext.user.

Reference values

Reference providers publish bounded, searchable, actor-aware value lists. They are useful for time zones, statuses, countries, warehouses, or project-specific dictionaries:

Attach the provider name to a field:

The agent calls doctrine_reference_values with reference, optional query, limit, and cursor. Providers are tagged automatically; without autoconfiguration, use doctrine_mcp.reference_provider.

[!NOTE] A reference provider documents and suggests values. Enforce membership with Symfony Validator constraints or domain logic when the field is written.

Custom mutation handlers

The default mutation pipeline uses a no-argument constructor, Symfony PropertyAccess setters, Doctrine persistence, and conventional collection methods. Use EntityMutationHandlerInterface for aggregate factories, value objects, workflow transitions, or domain services:

Reference the handler by service ID:

Custom handlers receive the dryRun flag and own their persistence and transaction behavior. They must not persist during a preview. Entity scopes, voters, and Symfony validation still run around handler results. Without autoconfiguration, tag handlers with doctrine_mcp.mutation_handler.

Custom MCP capabilities

The same endpoint can expose application-specific tools, resources, resource templates, and prompts. Put autowired services in src/Mcp and use attributes from the official PHP MCP SDK.

Custom tools

The SDK derives the tool input schema from PHP parameter types and documentation. Constructor dependencies are resolved by the Symfony container.

Resources and prompts

Change discovery directories when capabilities live elsewhere:

Paths are relative to kernel.project_dir. The classes must also be registered as Symfony services. With non-standard service loading, register the namespace explicitly:

[!IMPORTANT] Custom capabilities share the authenticated transport and actor-bound MCP session, but they do not automatically pass through Doctrine CRUD scopes, dryRun, field permissions, voters, or mutation auditing. Inject application services, Symfony Security, or ActorProviderInterface and enforce the capability's own authorization and domain rules.

Authentication and session security

The controller resolves the actor before MCP payload processing. Unauthenticated requests receive HTTP 401.

Streamable HTTP sessions are stored in the configured cache pool. Every session ID is bound to a SHA-256 fingerprint of the actor identifier; replaying another user's session ID returns HTTP 403. Session IDs are hashed in logs.

For multi-instance deployments, use a shared cache pool such as Redis:

The actor identifier returned by ActorProviderInterface must be stable and unique across all users or service identities that can access the endpoint.

Audit and observability

Every request has a traceId. The endpoint accepts X-Request-Id; otherwise it generates one and returns it in the response header.

The doctrine_mcp log channel emits structured events including:

Secret-like keys such as passwords, tokens, authorization headers, API keys, and cookies are redacted. Fields marked sensitive: true are redacted during entity serialization and mutation auditing.

The default audit sink writes sanitized mutation records to the logger. Implement AuditSinkInterface for an immutable database table or external audit service:

Configuration reference

Option Default Description
server.name Doctrine MCP MCP server display name.
server.version 0.1.1 Application-facing MCP server version.
server.description See example Server description returned during discovery.
server.instructions See example Instructions provided to MCP clients.
http.path /_mcp Streamable HTTP endpoint path.
http.allowed_hosts null SDK localhost defaults; use a hostname list in production or false to disable the middleware.
http.max_body_bytes 4194304 Maximum MCP request body size; minimum 1024 bytes.
http.session.cache_pool cache.app Symfony PSR-6 cache pool used for MCP state and actor binding.
http.session.prefix doctrine-mcp- Cache key prefix.
http.session.ttl 3600 Session lifetime in seconds; minimum 60.
discovery.scan_dirs ['src/Mcp'] Capability discovery paths relative to the project directory.
discovery.exclude_dirs [] Paths excluded from discovery.
query.default_limit 25 Default search page size.
query.max_limit 100 Maximum search and SDK pagination size.
query.max_association_items 100 Maximum add/remove items in one collection mutation.
actor_provider Symfony Security provider Service implementing ActorProviderInterface.
audit_sink Logger sink Service implementing AuditSinkInterface.
global_scopes [] Scope classes applied to every exposed entity.

Console commands

Validate all exposed entities, mapped fields, scope registrations, server-controlled write flags, and reference configuration:

Inspect the normalized public contract of one entity:

Run validation during deployment and after changing Doctrine metadata, MCP attributes, scope services, or reference providers. Clear the Symfony cache when a production deployment changes discovered attributes or container configuration.

Production checklist

Before connecting an agent:

  1. protect the MCP route with a Symfony firewall and access_control;
  2. configure all production allowed_hosts;
  3. use a shared session cache in a multi-instance deployment;
  4. expose only explicitly reviewed entities and fields;
  5. add an entity or global scope everywhere and review every use of UnrestrictedScope;
  6. keep write operations and field write flags disabled unless required;
  7. add Validator constraints and domain checks for writable values;
  8. verify custom mutation handlers honor dryRun;
  9. authorize and audit custom MCP capabilities explicitly;
  10. run doctrine-mcp:validate and inspect each entity with doctrine-mcp:debug;
  11. verify log redaction and configure durable audit storage where required;
  12. test with two users from different tenants before production rollout.

Troubleshooting

Authentication is always required

The default actor provider requires an authenticated Symfony UserInterface. Check the firewall pattern, authenticator, access token or cookie, and access_control rules for the MCP path.

The entity is unknown

Confirm that Doctrine manages the class, the class has McpEntity, its public name is unique, and the application cache was cleared after deployment.

The entity has no query scope

Add an EntityScopeInterface class to McpEntity.scopes, configure a global scope, or deliberately use UnrestrictedScope for reviewed public data.

A scope or provider is not registered

Ensure Symfony autoconfiguration covers the class. Otherwise add doctrine_mcp.scope, doctrine_mcp.reference_provider, or doctrine_mcp.mutation_handler manually.

A custom MCP tool is not discovered

Check that its file is inside discovery.scan_dirs, outside exclude_dirs, has an SDK MCP attribute, and is registered as an autoconfigured Symfony service. Clear the Symfony cache afterward.

A field cannot be written

The entity operation and field write flag must both be enabled. Identifiers, unannotated fields, read-only fields, and serverControlled fields are rejected by design.

An association cannot be resolved

Expose the target entity, provide its exact identifier shape, and ensure the current actor can read it through the target's scopes and voter.

Development

Install dependencies and run the complete package checks:

Doctrine integration tests require pdo_sqlite. The CI matrix covers PHP 8.1 with the lowest supported Symfony and Doctrine versions and stable dependencies on newer PHP versions.

Maintainer releases

Every successful CI run for a push to master publishes the tested commit automatically. The release workflow increments the patch version, creates an annotated Git tag and GitHub Release, and updates Packagist immediately. The Packagist webhook remains enabled as a second synchronization path.

Use the manual dispatcher only for an intentional minor or major release, or to retry automation:

To ask Packagist to recrawl the existing release without creating a version, run:

Release credentials are stored as GitHub Actions Secrets. Local recovery uses a machine-bound encrypted systemd-creds credential; secrets are never committed to the repository.

License

This project is proprietary. See LICENSE. Adapted MIT-licensed transport code is documented in THIRD_PARTY_NOTICES.md.


All versions of doctrine-mcp-bundle with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
doctrine/doctrine-bundle Version ^2.18 || ^3.2
doctrine/orm Version ^2.20 || ^3.3
mcp/sdk Version ^0.7
nyholm/psr7 Version ^1.8
psr/log Version ^1.1 || ^2.0 || ^3.0
psr/simple-cache Version ^1.0 || ^2.0 || ^3.0
symfony/cache Version ^6.4 || ^7.4 || ^8.0
symfony/config Version ^6.4 || ^7.4 || ^8.0
symfony/dependency-injection Version ^6.4 || ^7.4 || ^8.0
symfony/event-dispatcher Version ^6.4 || ^7.4 || ^8.0
symfony/framework-bundle Version ^6.4 || ^7.4 || ^8.0
symfony/http-foundation Version ^6.4 || ^7.4 || ^8.0
symfony/http-kernel Version ^6.4 || ^7.4 || ^8.0
symfony/property-access Version ^6.4 || ^7.4 || ^8.0
symfony/psr-http-message-bridge Version ^6.4 || ^7.4 || ^8.0
symfony/routing Version ^6.4 || ^7.4 || ^8.0
symfony/security-bundle Version ^6.4 || ^7.4 || ^8.0
symfony/serializer Version ^6.4 || ^7.4 || ^8.0
symfony/uid Version ^6.4 || ^7.4 || ^8.0
symfony/validator Version ^6.4 || ^7.4 || ^8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package errogaht/doctrine-mcp-bundle contains the following files

Loading the files please wait ...