Skip to content

Commit 8a2c7d4

Browse files
committed
Drop reverse route tool because complex schema issues
1 parent adeeffb commit 8a2c7d4

3 files changed

Lines changed: 0 additions & 136 deletions

File tree

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@ Inspect and analyze your application routes:
225225
- `list_routes` - List all routes with filtering and sorting
226226
- `get_route` - Get detailed information about a specific route
227227
- `match_url` - Find which route matches a given URL
228-
- `reverse_route` - Generate URLs from route names or parameters
229228
- `detect_route_collisions` - Find potential route conflicts
230229
231230
### Documentation Search

src/Mcp/RouteTools.php

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Cake\Routing\Router;
99
use Exception;
1010
use Mcp\Capability\Attribute\McpTool;
11-
use Mcp\Capability\Attribute\Schema;
1211
use Mcp\Exception\ToolCallException;
1312

1413
/**
@@ -182,60 +181,6 @@ public function matchUrl(string $url, string $method = 'GET'): array
182181
}
183182
}
184183

185-
/**
186-
* Generate URL from route parameters (reverse routing).
187-
*
188-
* Creates a URL from either a named route or route parameters.
189-
* Supports generating full URLs with domain.
190-
*
191-
* @param string|null $name Named route (e.g., 'projects:view')
192-
* @param array<string, mixed> $params Route parameters
193-
* @param bool $full Generate full URL with domain
194-
* @return array<string, mixed> Generated URL or error
195-
*/
196-
#[McpTool(
197-
name: 'reverse_route',
198-
description: 'Generate URL from route name or parameters (reverse routing)',
199-
)]
200-
public function reverseRoute(
201-
?string $name = null,
202-
#[Schema(
203-
type: 'object',
204-
description: 'Route parameters like controller, action, plugin, prefix, and pass parameters. ' .
205-
'Examples: {"controller": "Articles", "action": "view", "id": "123"} or ' .
206-
'{"plugin": "MyPlugin", "controller": "Users", "action": "index"}',
207-
additionalProperties: true,
208-
)]
209-
array $params = [],
210-
bool $full = false,
211-
): array {
212-
try {
213-
$url = null;
214-
215-
if ($name !== null) {
216-
// Named route - merge params properly
217-
$urlArray = ['_name' => $name];
218-
foreach ($params as $key => $value) {
219-
$urlArray[$key] = $value;
220-
}
221-
222-
$url = Router::url($urlArray, $full);
223-
} elseif ($params !== []) {
224-
// Parameter-based routing
225-
$url = Router::url($params, $full);
226-
} else {
227-
throw new ToolCallException('Either name or params must be provided');
228-
}
229-
230-
return [
231-
'url' => $url,
232-
'full' => $full,
233-
];
234-
} catch (Exception $exception) {
235-
throw new ToolCallException('Error generating URL: ' . $exception->getMessage());
236-
}
237-
}
238-
239184
/**
240185
* Detect potential route collisions and conflicts.
241186
*

tests/TestCase/Mcp/RouteToolsTest.php

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -280,61 +280,6 @@ public function testMatchUrlNotFound(): void
280280
}
281281
}
282282

283-
/**
284-
* Test reverseRoute with named route
285-
*/
286-
public function testReverseRouteWithName(): void
287-
{
288-
$result = $this->RouteTools->reverseRoute(name: 'projects:view', params: ['id' => 123]);
289-
290-
$this->assertArrayHasKey('url', $result);
291-
$this->assertIsString($result['url']);
292-
$this->assertStringContainsString('projects', $result['url']);
293-
$this->assertArrayHasKey('full', $result);
294-
$this->assertFalse($result['full']);
295-
}
296-
297-
/**
298-
* Test reverseRoute with parameters
299-
*/
300-
public function testReverseRouteWithParams(): void
301-
{
302-
$result = $this->RouteTools->reverseRoute(
303-
params: ['controller' => 'Pages', 'action' => 'display', 'pass' => ['home']],
304-
);
305-
306-
$this->assertArrayHasKey('url', $result);
307-
$this->assertIsString($result['url']);
308-
}
309-
310-
/**
311-
* Test reverseRoute with full URL
312-
*/
313-
public function testReverseRouteWithFullUrl(): void
314-
{
315-
$result = $this->RouteTools->reverseRoute(
316-
name: 'home',
317-
params: [],
318-
full: true,
319-
);
320-
321-
$this->assertArrayHasKey('url', $result);
322-
$this->assertArrayHasKey('full', $result);
323-
$this->assertTrue($result['full']);
324-
$this->assertStringContainsString('http', $result['url']);
325-
}
326-
327-
/**
328-
* Test reverseRoute without name or params
329-
*/
330-
public function testReverseRouteWithoutNameOrParams(): void
331-
{
332-
$this->expectException(ToolCallException::class);
333-
$this->expectExceptionMessage('Either name or params must be provided');
334-
335-
$this->RouteTools->reverseRoute();
336-
}
337-
338283
/**
339284
* Test detectRouteCollisions
340285
*/
@@ -519,31 +464,6 @@ public function testMatchUrlWithMixedCaseMethod(): void
519464
$this->assertEquals('GET', $result['method']);
520465
}
521466

522-
/**
523-
* Test reverseRoute error handling with invalid name
524-
*/
525-
public function testReverseRouteWithInvalidName(): void
526-
{
527-
$this->expectException(ToolCallException::class);
528-
$this->expectExceptionMessage('Error generating URL');
529-
530-
$this->RouteTools->reverseRoute(name: 'totally:nonexistent:route:name:xyz');
531-
}
532-
533-
/**
534-
* Test reverseRoute with name and multiple parameters
535-
*/
536-
public function testReverseRouteWithNameAndMultipleParams(): void
537-
{
538-
$result = $this->RouteTools->reverseRoute(
539-
name: 'projects:edit',
540-
params: ['id' => 456, 'extra' => 'value'],
541-
);
542-
543-
$this->assertArrayHasKey('url', $result);
544-
$this->assertIsString($result['url']);
545-
}
546-
547467
/**
548468
* Test detectRouteCollisions with routes without methods
549469
*/

0 commit comments

Comments
 (0)