-
-
Notifications
You must be signed in to change notification settings - Fork 160
[Mate][Symfony] Add optional profiler data access capabilities #1320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[Mate][Symfony] Add optional profiler data access capabilities #1320
Conversation
src/mate/src/Bridge/Profiler/Capability/ProfilerResourceTemplate.php
Outdated
Show resolved
Hide resolved
src/mate/src/Bridge/Profiler/Capability/ProfilerResourceTemplate.php
Outdated
Show resolved
Hide resolved
src/mate/src/Bridge/Profiler/Capability/ProfilerResourceTemplate.php
Outdated
Show resolved
Hide resolved
src/mate/src/Bridge/Profiler/Capability/ProfilerResourceTemplate.php
Outdated
Show resolved
Hide resolved
|
The README is too long, let's move it to the docs folder using rst |
5b8ec59 to
a5e4d3a
Compare
a5e4d3a to
7b7983e
Compare
7b7983e to
a11cfe7
Compare
|
@chr-hertel @OskarStark i reduced the formatters to request and exception - so that the review is easier - we can add the other important collectors later |
|
@chr-hertel @OskarStark @Nyholm its ready for review 🎉 |
|
this is an example run in claude. Claude Code SessionI dont like the empty returns for none registered formatters - but for the first implementation i think its ok - also this should to into an issue. |
|
This looks nice, but can we merge this with the SymfonyBridge? |
|
@Nyholm also considered this, but the profiler makes more sense as its own extension. This way, it can be enabled and configured independently, adding context to the prompt without coupling it to other extensions. |
src/mate/demo/src/Bridge/Profiler/Tests/Fixtures/profiler/23/c1/abc123
Outdated
Show resolved
Hide resolved
|
Open Points are:
|
8919f3c to
a43d3c1
Compare
src/mate/src/Bridge/Profiler/Service/CollectorFormatterInterface.php
Outdated
Show resolved
Hide resolved
|
@sonnymilton thanks for the feedback - i have done that now |
88239b5 to
9ee7401
Compare
779e119 to
9ab9462
Compare
This bridge provides MCP (Model Context Protocol) integration with the Symfony Profiler, allowing AI assistants to analyze profiler data for debugging and performance optimization. Key features: - Read and parse Symfony profiler files (gzipped, nested directory structure) - MCP tools for listing, searching, and retrieving profiler data - MCP resources for accessing specific profile sections (request, response, events, exceptions) - Collector formatters for structured data presentation (request, response, event, exception) - Type-safe models with PHPStan types (ProfileIndexData, CollectorDataArray) - Comprehensive test coverage (69 tests, 174 assertions) The bridge enables AI-powered analysis of web application performance, request handling, and error debugging through the Mate coding assistant.
…ofileData Major changes: - Simplify ProfileData to wrap Symfony Profile + context (for multi-directory support) - Update ProfilerDataProvider to use FileProfilerStorage instead of manual file operations - Update ProfilerResourceTemplate to access data through Profile methods - Add FileProfilerStorage and Profile imports to config.php - Update ProfileDataTest to test simplified model - Update ProfilerDataProviderTest for new ProfileData structure Benefits: - Use official Symfony API (FileProfilerStorage) instead of manual file operations - Future-proof against Symfony profiler format changes - Cleaner code with less maintenance burden - Preserve multi-context support through ProfileData wrapper Note: Some tests still need fixture updates to work with FileProfilerStorage format
- Update test expectations for newest-first sorting order - Create TestCollector fixture class with proper serialization support - Regenerate test fixtures using FileProfilerStorage API - Update ProfilerTool to work with new ProfileData structure - Remove unused ProfileIndexer dependency - Fix all PHPStan type errors - All 64 tests passing, 0 PHPStan errors Removes ProfileIndexer from service dependency chain as it's no longer needed with FileProfilerStorage handling all file operations.
Implements comprehensive data sanitization to prevent exposure of sensitive information through the profiler MCP tool: Security Measures: - Redact all cookie values (session tokens, CSRF tokens, etc.) - Redact sensitive HTTP headers (Authorization, Cookie, X-API-Key, etc.) - Redact environment variables containing sensitive patterns: SECRET, KEY, PASSWORD, TOKEN, BEARER, AUTH, CREDENTIAL, PRIVATE - Redact all session attributes - Preserve non-sensitive data for debugging purposes Pattern Matching: - Case-insensitive header matching - Case-insensitive environment variable pattern matching - Comprehensive test coverage (7 new tests, 42 assertions) Prevents exposure of: - Session cookies (admin_deauth_profile_token, etc.) - API keys (OPENAI_API_KEY, HUGGINGFACE_API_KEY, etc.) - Application secrets (APP_SECRET, JWT_TOKEN, etc.) - Database credentials (DATABASE_PASSWORD, etc.) - Authorization headers and tokens All 71 tests passing, 0 PHPStan errors
Profiler Bridge Dependencies: - Add symfony/http-kernel and symfony/var-dumper to mate require-dev (needed for testing embedded Profiler Bridge) - Add symfony/var-dumper to Profiler Bridge require-dev (for standalone installation) - Bridge dependencies are defined in Bridge composer.json but loaded via mate's vendor when embedded PHPStan Configuration: - Add excludePaths for src/Bridge/*/vendor to prevent scanning bridge vendor directories if accidentally created Code Quality: - Remove deprecated setAccessible() calls (not needed in PHP 8.1+) - Remove unused ProfileIndexer imports from test files - Remove unused FileProfilerStorage/Profile imports from config - Reorganize RequestCollectorFormatter methods for better readability All 71 tests passing, 0 PHPStan errors
9ab9462 to
f1b833b
Compare
|
@chr-hertel @Nyholm i merged the tools into the symfony bridge - you can review it BUT before merging i have to take a deeper test in the demo application - was not able todo this today |
The Profiler bridge has been merged into the Symfony bridge to consolidate all Symfony-related tooling in one package. This reduces maintenance overhead and simplifies the extension architecture. Key changes: - All profiler classes moved to Symfony\AI\Mate\Bridge\Symfony\Profiler namespace - Tool names updated with symfony- prefix (symfony-profiler-list, etc.) - Resource URIs updated to use symfony-profiler:// scheme - Profiler dependencies moved to require-dev (optional feature) - Conditional service registration using class_exists() check - Container introspection works independently of profiler - Test fixtures regenerated with correct namespace - All tests passing (65 tests, 171 assertions) - PHPStan analysis clean (0 errors)
f1b833b to
61dd8f2
Compare
|
@chr-hertel @Nyholm tested and OK for the first release :) see it here https://asciinema.org/a/paNQKKiSIQyOolsx |
src/mate/src/Bridge/Symfony/Profiler/Service/Formatter/ExceptionCollectorFormatter.php
Outdated
Show resolved
Hide resolved
0dde88c to
5bd21e9
Compare
Updated ExceptionCollectorFormatter and RequestCollectorFormatter to use specific collector types (ExceptionDataCollector and RequestDataCollector) instead of the generic DataCollectorInterface. Benefits: - Better static analysis with PHPStan understanding exact types - Removed defensive method_exists() checks (65 lines removed) - Type assertions provide runtime safety - Cleaner, more maintainable code - Direct access to collector-specific methods The generic template annotation tells PHPStan about the specific type, while runtime assertions ensure type safety.
5bd21e9 to
0e464f0
Compare
| "symfony/http-kernel": "^5.4|^6.4|^7.3|^8.0", | ||
| "symfony/var-dumper": "^5.4|^6.4|^7.3|^8.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why does mate itself now need those dependencies?
| ]); | ||
|
|
||
| // Profiler services (optional - only if profiler classes are available) | ||
| if (class_exists(Symfony\Component\HttpKernel\Profiler\Profile::class)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could be an import
| $configurator->parameters() | ||
| ->set('ai_mate_symfony.profiler_dir', '%mate.root_dir%/var/cache/dev/profiler'); | ||
|
|
||
| $services->set(Symfony\AI\Mate\Bridge\Symfony\Profiler\Service\CollectorRegistry::class) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add use statement please
| $services->set(Symfony\AI\Mate\Bridge\Symfony\Profiler\Service\CollectorRegistry::class) | ||
| ->args([tagged_iterator('ai_mate.profiler_collector_formatter')]); | ||
|
|
||
| $services->set(Symfony\AI\Mate\Bridge\Symfony\Profiler\Service\ProfilerDataProvider::class) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, and below

Summary
This PR adds optional profiler data access capabilities to the Symfony bridge, enabling AI assistants to analyze Symfony profiler data for debugging and performance optimization through the Mate coding assistant.
Features
The Symfony bridge now provides two feature sets:
Container Introspection (always available):
Profiler Data Access (optional, requires
symfony/http-kernelandsymfony/web-profiler-bundle):symfony-profiler-list,symfony-profiler-latest,symfony-profiler-search,symfony-profiler-get)symfony-profiler://profile/{token}URIsImplementation Details
Symfony\AI\Mate\Bridge\Symfony\Profiler\*require-dev, tools only register when availableclass_exists(\Symfony\Component\HttpKernel\Profiler\Profile::class)check