Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions lib/Mcp/BuiltIn/DerivedToolDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
use OCA\OpenRegister\Db\Schema;

/**
* One schema-derived tool being described: the schema, its slug, the verb,
* that verb's dialect config and the namespaced tool id.
* One schema-derived tool being described: the schema, its slug, the verb
* and that verb's dialect config. The namespaced tool id is derived from the
* slug and verb by the provider that owns the app id.
*/
final readonly class DerivedToolDefinition {

Expand All @@ -37,14 +38,12 @@
* @param string $slug The schema's slug (id-tail).
* @param string $verb One of {@see McpAnnotationValidator::VERBS}.
* @param array<string, mixed> $verbConfig That verb's dialect config (description/scope/filters/hints).
* @param string $id The fully-namespaced tool id.
*/
public function __construct(
public Schema $schema,
public string $slug,
public string $verb,
public array $verbConfig,
public string $id,
) {
}//end __construct()
}//end class
20 changes: 15 additions & 5 deletions lib/Mcp/BuiltIn/SchemaDerivedToolProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,7 @@ private function descriptorsForSchema(Schema $schema, array &$emittedIds): array
schema: $schema,
slug: $slug,
verb: $verb,
verbConfig: $this->verbConfig(toolsConfig: $toolsConfig, verb: $verb),
id: $this->appId . '.' . $slug . '.' . $verb
verbConfig: $this->verbConfig(toolsConfig: $toolsConfig, verb: $verb)
);
if ($this->claimToolId(tool: $tool, emittedIds: $emittedIds) === false) {
continue;
Expand Down Expand Up @@ -292,6 +291,17 @@ private function verbConfig(mixed $toolsConfig, string $verb): array {
return [];
}//end verbConfig()

/**
* The fully-namespaced id of a derived tool: `{appId}.{slug}.{verb}`.
*
* @param DerivedToolDefinition $tool The tool being described.
*
* @return string The tool id.
*/
private function toolId(DerivedToolDefinition $tool): string {
return $this->appId . '.' . $tool->slug . '.' . $tool->verb;
}//end toolId()

/**
* Claim a tool id for a schema, refusing suppressed and already-emitted ids.
*
Expand All @@ -301,7 +311,7 @@ private function verbConfig(mixed $toolsConfig, string $verb): array {
* @return bool Whether the id may be emitted for this schema.
*/
private function claimToolId(DerivedToolDefinition $tool, array &$emittedIds): bool {
$id = $tool->id;
$id = $this->toolId(tool: $tool);
$schema = $tool->schema;

// Self-suppression (REQ-DERIVED-003): a hand-written per-app
Expand Down Expand Up @@ -656,7 +666,7 @@ private function anchorObjectService(Schema $schema, ?Register $register): void
/**
* Build one tool descriptor for a schema+verb pair.
*
* @param DerivedToolDefinition $tool The schema, slug, verb, verb config and tool id.
* @param DerivedToolDefinition $tool The schema, slug, verb and verb config.
*
* @return array{id: string, name: string, description: string, inputSchema: array,
* app: string, subject: string, action: string,
Expand All @@ -668,7 +678,7 @@ private function buildDescriptor(DerivedToolDefinition $tool): array {
$verb = $tool->verb;
$verbConfig = $tool->verbConfig;
$descriptor = [
'id' => $tool->id,
'id' => $this->toolId(tool: $tool),
'name' => $slug . '_' . $verb,
'description' => $this->description(tool: $tool, override: $verbConfig['description'] ?? null),
'inputSchema' => $this->buildInputSchema(tool: $tool),
Expand Down
13 changes: 5 additions & 8 deletions lib/Service/Integration/LeafRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ class LeafRegistry implements LeafRegistryInterface {
* @param IntegrationRegistry $integrationRegistry Shared provider registry (data leaves land here).
* @param IAppManager $appManager App manager (usability check).
* @param LoggerInterface $logger Logger for collision, validation, collection warnings.
* @param LeafBundle|null $leafBundleService Answers whether an app's leaf can render. Nullable and last so
* no construction site shifts; absent, one is built from the app
* manager this class already holds.
*
* @return void
*/
Expand All @@ -93,12 +90,12 @@ public function __construct(
private IntegrationRegistry $integrationRegistry,
private IAppManager $appManager,
private LoggerInterface $logger,
// LAST AND NULLABLE so every existing construction keeps working; the
// container always supplies it. Built from the app manager this class
// already holds when it is absent, so the answer is never a second one.
private ?LeafBundle $leafBundleService = null,
) {
$this->leafBundle = ($leafBundleService ?? new LeafBundle($appManager));
// LeafBundle is stateless and only reads the app manager, so the one
// built here from the app manager this class already holds is the one
// answer to whether a leaf can render; no construction site passed
// another.
$this->leafBundle = new LeafBundle($appManager);
}//end __construct()

/**
Expand Down
Loading