Repository navigation
feat: new MCP tools — run_command, LogTools, CacheTools, ModelTools #7
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1a18edb
feat: add SubprocessRunner utility, run_command MCP tool, refactor Ti…
josbeir 26f798e
feat: add LogTools MCP tools (log_list, log_read)
josbeir e58c2d1
fix: capture exit code from proc_get_status to fix PHP 8.2 CI failures
josbeir b165ef5
fix: loosen testRunCommandIntegration exit code assertion
josbeir 986c7e5
fix: check combined stdout+stderr in integration test
josbeir 530b245
fix: remove non-blocking fread loop in SubprocessRunner for Windows c…
josbeir 555cd4b
feat: add CacheTools MCP tools (cache_configs, cache_read, cache_writ…
josbeir a93b113
feat: add ModelTools MCP tools (orm_describe, orm_find)
josbeir 3bae20f
fix: address Copilot review comments — shell injection escape, Subpro…
josbeir cdf0cea
test: add coverage for shell escaping, runner caching, and log tail e…
josbeir df1c465
ci: always generate JUnit XML so codecov test-results upload succeeds…
josbeir 572680e
docs: update README with run_command, LogTools, CacheTools, ModelTools
josbeir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,167 @@ | ||
| <?php | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Synapse\Tools; | ||
|
|
||
| use Cake\Cache\Cache; | ||
| use Mcp\Capability\Attribute\McpTool; | ||
| use Mcp\Exception\ToolCallException; | ||
|
|
||
| /** | ||
| * Cache Tools | ||
| * | ||
| * MCP tools for inspecting and managing CakePHP cache configurations and entries. | ||
| */ | ||
| class CacheTools | ||
| { | ||
| /** | ||
| * List all configured cache configurations. | ||
| * | ||
| * Returns information about each configured cache engine including | ||
| * the engine class name and any configured prefix. | ||
| * | ||
| * @return array<int, array<string, mixed>> List of cache configurations | ||
| */ | ||
| #[McpTool( | ||
| name: 'cache_configs', | ||
| description: 'List all configured CakePHP cache configurations with engine information', | ||
| )] | ||
| public function listConfigs(): array | ||
| { | ||
| $configs = Cache::configured(); | ||
| $result = []; | ||
|
|
||
| foreach ($configs as $name) { | ||
| $config = Cache::getConfig($name) ?? []; | ||
|
|
||
| $result[] = [ | ||
| 'name' => $name, | ||
| 'className' => $config['className'] ?? $config['engine'] ?? 'Unknown', | ||
| 'prefix' => $config['prefix'] ?? null, | ||
| 'path' => $config['path'] ?? null, | ||
| 'duration' => $config['duration'] ?? null, | ||
| ]; | ||
| } | ||
|
|
||
| return $result; | ||
| } | ||
|
|
||
| /** | ||
| * Read a value from the cache. | ||
| * | ||
| * Returns the stored value for the given key, or indicates the key was not found. | ||
| * | ||
| * @param string $config Cache configuration name (e.g. 'default') | ||
| * @param string $key Cache key to read | ||
| * @return array{key: string, value: mixed, found: bool} Cache read result | ||
| */ | ||
| #[McpTool( | ||
| name: 'cache_read', | ||
| description: 'Read a value from a CakePHP cache configuration by key', | ||
| )] | ||
| public function cacheRead(string $config, string $key): array | ||
| { | ||
| $this->assertConfigured($config); | ||
|
|
||
| $value = Cache::read($key, $config); | ||
| $found = $value !== null; | ||
|
|
||
| return [ | ||
| 'key' => $key, | ||
| 'value' => $found ? $value : null, | ||
| 'found' => $found, | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * Write a value to the cache. | ||
| * | ||
| * Stores the given string value under the specified key in the cache configuration. | ||
| * | ||
| * @param string $config Cache configuration name (e.g. 'default') | ||
| * @param string $key Cache key to write | ||
| * @param string $value Value to store | ||
| * @return array{key: string, stored: bool} Cache write result | ||
| */ | ||
| #[McpTool( | ||
| name: 'cache_write', | ||
| description: 'Write a string value to a CakePHP cache configuration', | ||
| )] | ||
| public function cacheWrite(string $config, string $key, string $value): array | ||
| { | ||
| $this->assertConfigured($config); | ||
|
|
||
| $stored = Cache::write($key, $value, $config); | ||
|
|
||
| return [ | ||
| 'key' => $key, | ||
| 'stored' => $stored, | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * Delete a key from the cache. | ||
| * | ||
| * Removes the specified key from the given cache configuration. | ||
| * | ||
| * @param string $config Cache configuration name (e.g. 'default') | ||
| * @param string $key Cache key to delete | ||
| * @return array{key: string, deleted: bool} Cache delete result | ||
| */ | ||
| #[McpTool( | ||
| name: 'cache_delete', | ||
| description: 'Delete a key from a CakePHP cache configuration', | ||
| )] | ||
| public function cacheDelete(string $config, string $key): array | ||
| { | ||
| $this->assertConfigured($config); | ||
|
|
||
| $deleted = Cache::delete($key, $config); | ||
|
|
||
| return [ | ||
| 'key' => $key, | ||
| 'deleted' => $deleted, | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * Clear all entries from a cache configuration. | ||
| * | ||
| * Removes all cached entries from the specified cache configuration. | ||
| * | ||
| * @param string $config Cache configuration name (e.g. 'default') | ||
| * @return array{config: string, cleared: bool} Cache clear result | ||
| */ | ||
| #[McpTool( | ||
| name: 'cache_clear', | ||
| description: 'Clear all entries from a CakePHP cache configuration', | ||
| )] | ||
| public function cacheClear(string $config): array | ||
| { | ||
| $this->assertConfigured($config); | ||
|
|
||
| $cleared = Cache::clear($config); | ||
|
|
||
| return [ | ||
| 'config' => $config, | ||
| 'cleared' => $cleared, | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * Assert that a cache configuration exists. | ||
| * | ||
| * @param string $config Cache configuration name to validate | ||
| * @throws \Mcp\Exception\ToolCallException If the configuration is not registered | ||
| */ | ||
| private function assertConfigured(string $config): void | ||
| { | ||
| if (!in_array($config, Cache::configured(), true)) { | ||
| throw new ToolCallException(sprintf( | ||
| 'Cache config "%s" is not configured. Available: %s', | ||
| $config, | ||
| implode(', ', Cache::configured()), | ||
| )); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.