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
31 changes: 16 additions & 15 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ function () {
// probing routes.
$context->registerCapability(UrnCapability::class);

// pluggable-integration-registry task 4.5 (tasks.md#task-22):
// Pluggable-integration-registry task 4.5 (tasks.md#task-22):
// advertise the integration registry through the OCS
// capabilities endpoint.
$context->registerCapability(\OCA\OpenRegister\Capabilities\IntegrationsCapability::class);
Expand Down Expand Up @@ -889,7 +889,7 @@ function (ContainerInterface $container) {
}
);

$this->registerBuiltinIntegrationProviders($context);
$this->registerBuiltinIntegrationProviders(context: $context);

// IntegrationsController — read-only API over the registry.
$context->registerService(
Expand Down Expand Up @@ -926,7 +926,6 @@ function (ContainerInterface $container) {
// remaining constructor deps (IAppManager / IURLGenerator /
// IL10N) are framework services NC autowires. No explicit
// registerService needed, mirroring OpenRegisterAdmin.

// IntegrationsCapability — surfaces the registry through the
// Nextcloud OCS capabilities endpoint, role-redacted per AD-17.
$context->registerService(
Expand Down Expand Up @@ -1354,12 +1353,12 @@ function (ContainerInterface $container) {

// Per-app tool providers: try two discovery paths for each
// installed app:
// 1) the alias key `OCA\OpenRegister\Mcp\IMcpToolProvider::<appId>`
// (works only if the app registered the alias on this same
// container instance — NC scopes alias registration per app);
// 2) the canonical FQCN `OCA\<AppId>\Mcp\<AppId>ToolProvider`
// (resolved via NC's autoloader + DI autowiring, which works
// cross-app since the autoloader is process-global).
// 1) the alias key `OCA\OpenRegister\Mcp\IMcpToolProvider::<appId>`
// (works only if the app registered the alias on this same
// container instance — NC scopes alias registration per app);
// 2) the canonical FQCN `OCA\<AppId>\Mcp\<AppId>ToolProvider`
// (resolved via NC's autoloader + DI autowiring, which works
// cross-app since the autoloader is process-global).
try {
$appManager = $container->get('OCP\App\IAppManager');
foreach ($appManager->getInstalledApps() as $appId) {
Expand Down Expand Up @@ -1395,6 +1394,7 @@ function (ContainerInterface $container) {
// Path-resolution failures are benign; the other two
// candidates already cover the common case.
}

foreach ($candidates as $key) {
try {
if (str_contains($key, '\\') === true && str_contains($key, '::') === false) {
Expand All @@ -1420,9 +1420,10 @@ function (ContainerInterface $container) {
);
break;
} else {
$resolvedClass = is_object($appProvider) === true ? get_class($appProvider) : gettype($appProvider);
$logger->warning(
'[McpToolsService] Resolved but not IMcpToolProvider',
['appId' => $appId, 'via' => $key, 'class' => is_object($appProvider) ? get_class($appProvider) : gettype($appProvider)]
['appId' => $appId, 'via' => $key, 'class' => $resolvedClass]
);
}
} catch (\Throwable $e) {
Expand All @@ -1431,14 +1432,14 @@ function (ContainerInterface $container) {
['appId' => $appId, 'key' => $key, 'error' => $e->getMessage()]
);
continue;
}
}
}
}//end try
}//end foreach
}//end foreach
} catch (\Throwable $e) {
$logger->warning(
'[McpToolsService] Per-app provider enumeration failed: '.$e->getMessage()
);
}
}//end try

return new McpToolsService(
providers: $providers,
Expand Down Expand Up @@ -1475,7 +1476,7 @@ public function boot(IBootContext $context): void
// registry contract. Each provider is constructed lazily — the
// registry never touches a provider's wrapped service unless a
// caller actually invokes that provider's CRUD path.
$this->bootBuiltinIntegrationProviders($server);
$this->bootBuiltinIntegrationProviders(server: $server);
}//end boot()

/**
Expand Down
10 changes: 5 additions & 5 deletions lib/Capabilities/IntegrationsCapability.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
*/
class IntegrationsCapability implements ICapability
{

/**
* Constructor.
*
Expand All @@ -59,6 +58,8 @@ public function __construct(
}//end __construct()

/**
* Expose the registered integration providers as a capability.
*
* @inheritDoc
*
* @return array<string,mixed>
Expand All @@ -69,14 +70,14 @@ public function getCapabilities(): array
$rows = [];

foreach ($this->registry->list() as $provider) {
$rows[] = $this->describe($provider, $isAdmin);
$rows[] = $this->describe(provider: $provider, isAdmin: $isAdmin);
}

return [
'openregister' => [
'integrations' => [
'version' => 1,
'providers' => $rows,
'version' => 1,
'providers' => $rows,
],
],
];
Expand Down Expand Up @@ -135,5 +136,4 @@ private function currentUserIsAdmin(): bool

return $this->groupManager->isAdmin($user->getUID());
}//end currentUserIsAdmin()

}//end class
8 changes: 3 additions & 5 deletions lib/Controller/IntegrationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
*/
class IntegrationsController extends Controller
{

/**
* Constructor.
*
Expand All @@ -75,7 +74,7 @@ public function __construct(
private IGroupManager $groupManager,
private LoggerInterface $logger,
) {
parent::__construct($appName, $request);
parent::__construct(appName: $appName, request: $request);
}//end __construct()

/**
Expand Down Expand Up @@ -107,7 +106,7 @@ public function index(): JSONResponse
continue;
}

$rows[] = $this->describe($provider, $isAdmin);
$rows[] = $this->describe(provider: $provider, isAdmin: $isAdmin);
}

return new JSONResponse(['integrations' => $rows], Http::STATUS_OK);
Expand Down Expand Up @@ -139,7 +138,7 @@ public function show(string $id): JSONResponse
}

return new JSONResponse(
$this->describe($provider, $this->currentUserIsAdmin()),
$this->describe(provider: $provider, isAdmin: $this->currentUserIsAdmin()),
Http::STATUS_OK
);
}//end show()
Expand Down Expand Up @@ -210,5 +209,4 @@ private function currentUserIsAdmin(): bool

return $this->groupManager->isAdmin($user->getUID());
}//end currentUserIsAdmin()

}//end class
45 changes: 22 additions & 23 deletions lib/Controller/ObjectIntegrationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
*/
class ObjectIntegrationsController extends Controller
{

/**
* Constructor.
*
Expand All @@ -77,7 +76,7 @@
private IntegrationRegistry $registry,
private LoggerInterface $logger,
) {
parent::__construct($appName, $request);
parent::__construct(appName: $appName, request: $request);
}//end __construct()

/**
Expand All @@ -97,8 +96,8 @@
public function index(string $register, string $schema, string $id, string $integrationId): JSONResponse
{
return $this->dispatch(
$integrationId,
fn ($provider) => ['items' => $provider->list($register, $schema, $id, $this->collectFilters())]
integrationId: $integrationId,
callback: fn ($provider) => ['items' => $provider->list($register, $schema, $id, $this->collectFilters())]
);
}//end index()

Expand All @@ -119,8 +118,8 @@
public function show(string $register, string $schema, string $id, string $integrationId, string $entityId): JSONResponse
{
return $this->dispatch(
$integrationId,
fn ($provider) => $provider->get($register, $schema, $id, $entityId)
integrationId: $integrationId,
callback: fn ($provider) => $provider->get($register, $schema, $id, $entityId)
);
}//end show()

Expand All @@ -141,9 +140,9 @@
{
$payload = $this->collectPayload();
return $this->dispatch(
$integrationId,
fn ($provider) => $provider->create($register, $schema, $id, $payload),
Http::STATUS_CREATED
integrationId: $integrationId,
callback: fn ($provider) => $provider->create($register, $schema, $id, $payload),
okStatus: Http::STATUS_CREATED
);
}//end create()

Expand All @@ -165,8 +164,8 @@
{
$payload = $this->collectPayload();
return $this->dispatch(
$integrationId,
fn ($provider) => $provider->update($register, $schema, $id, $entityId, $payload)
integrationId: $integrationId,
callback: fn ($provider) => $provider->update($register, $schema, $id, $entityId, $payload)
);
}//end update()

Expand All @@ -187,15 +186,15 @@
public function destroy(string $register, string $schema, string $id, string $integrationId, string $entityId): JSONResponse
{
try {
$provider = $this->resolveProvider($integrationId);
$provider = $this->resolveProvider(integrationId: $integrationId);
$provider->delete($register, $schema, $id, $entityId);
return new JSONResponse(null, Http::STATUS_NO_CONTENT);
} catch (NotImplementedException $e) {
return $this->respondNotImplemented($e, $integrationId);
return $this->respondNotImplemented(exception: $e, integrationId: $integrationId);
} catch (ProviderUnavailableException $e) {
return $this->respondUnavailable($e);
return $this->respondUnavailable(exception: $e);
} catch (\Throwable $e) {
return $this->respondInternalError($e, $integrationId);
return $this->respondInternalError(exception: $e, integrationId: $integrationId);
}
}//end destroy()

Expand All @@ -209,20 +208,20 @@
*
* @return JSONResponse
*/
private function dispatch(string $integrationId, callable $callback, int $okStatus = Http::STATUS_OK): JSONResponse
private function dispatch(string $integrationId, callable $callback, int $okStatus=Http::STATUS_OK): JSONResponse
{
try {
$provider = $this->resolveProvider($integrationId);
$provider = $this->resolveProvider(integrationId: $integrationId);
$body = $callback($provider);
return new JSONResponse($body, $okStatus);

Check failure on line 216 in lib/Controller/ObjectIntegrationsController.php

View workflow job for this annotation

GitHub Actions / quality / PHP Quality (phpstan)

Parameter #2 $statusCode of class OCP\AppFramework\Http\JSONResponse constructor expects S of 100|101|102|200|201|202|203|204|205|206|207|208|226|300|301|302|303|304|305|306|307|400|401|402|403|404|405|406|407|408|409|410|411|412|413|414|415|416|417|418|422|423|424|426|428|429|431|500|501|502|503|504|505|506|507|508|509|510|511, int given.
} catch (NotImplementedException $e) {
return $this->respondNotImplemented($e, $integrationId);
return $this->respondNotImplemented(exception: $e, integrationId: $integrationId);
} catch (ProviderUnavailableException $e) {
return $this->respondUnavailable($e);
return $this->respondUnavailable(exception: $e);
} catch (\InvalidArgumentException $e) {
return new JSONResponse(['message' => $e->getMessage()], Http::STATUS_BAD_REQUEST);
} catch (\Throwable $e) {
return $this->respondInternalError($e, $integrationId);
return $this->respondInternalError(exception: $e, integrationId: $integrationId);
}
}//end dispatch()

Expand All @@ -246,7 +245,7 @@
sort($registered);
$hint = ($registered === []) ? '(no providers registered)' : implode(', ', $registered);
throw new NotImplementedException(
sprintf("Integration '%s' is not registered. Registered: %s", $integrationId, $hint)
message: sprintf("Integration '%s' is not registered. Registered: %s", $integrationId, $hint)
);
}

Expand All @@ -257,7 +256,7 @@
* Translate `NotImplementedException` to the 501 envelope shape
* documented in QueryTimeContract::buildHttpBody().
*
* @param NotImplementedException $exception Exception.
* @param NotImplementedException $exception Exception.
* @param string $integrationId Integration id.
*
* @return JSONResponse
Expand Down Expand Up @@ -337,6 +336,7 @@
if (in_array($key, ['register', 'schema', 'id', 'integrationId', 'entityId'], true) === true) {
continue;
}

$filters[$key] = $value;
}

Expand All @@ -354,5 +354,4 @@
unset($raw['register'], $raw['schema'], $raw['id'], $raw['integrationId'], $raw['entityId']);
return $raw;
}//end collectPayload()

}//end class
8 changes: 4 additions & 4 deletions lib/Db/EmailLinkMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ public function tableExists(): bool

if ($this->tableExistsCache === false) {
try {
$qb = $this->db->getQueryBuilder();
$qb = $this->db->getQueryBuilder();
$qb->select($qb->func()->count('*'))
->from('information_schema.tables')
->where($qb->expr()->eq('table_name', $qb->createNamedParameter('oc_'.$this->getTableName())));
$result = $qb->executeQuery();
$row = $result->fetch();
$this->tableExistsCache = $row !== false && (int) reset($row) > 0;
$result = $qb->executeQuery();
$row = $result->fetch();
$this->tableExistsCache = $row !== false && (int) reset($row) > 0;
} catch (\Throwable $e) {
$this->tableExistsCache = false;
}
Expand Down
7 changes: 3 additions & 4 deletions lib/Exception/ProviderUnavailableException.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ProviderUnavailableException extends \RuntimeException
public const CAUSE_OPENCONNECTOR_DOWN = 'openconnector-down';
public const CAUSE_OPENCONNECTOR_SOURCE_MISSING = 'openconnector-source-missing';
public const CAUSE_UPSTREAM_SERVICE_DOWN = 'upstream-service-down';
public const CAUSE_PROVIDER_AUTH = 'provider-auth';
public const CAUSE_PROVIDER_AUTH = 'provider-auth';

/**
* The cause classification.
Expand All @@ -59,9 +59,9 @@ class ProviderUnavailableException extends \RuntimeException
*
* @return void
*/
public function __construct(string $message, string $cause, ?\Throwable $previous = null)
public function __construct(string $message, string $cause, ?\Throwable $previous=null)
{
parent::__construct($message, 0, $previous);
parent::__construct(message: $message, code: 0, previous: $previous);
$this->cause = $cause;
}//end __construct()

Expand All @@ -86,5 +86,4 @@ public function getDetails(): array
{
return ['cause' => $this->cause];
}//end getDetails()

}//end class
9 changes: 6 additions & 3 deletions lib/Listener/ToolRegistrationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@
* @param ObjectsTool $objectsTool Objects tool.
* @param ApplicationTool $applicationTool Application tool.
* @param AgentTool $agentTool Agent tool.
* @param McpToolsService $mcpToolsService MCP tools service used to register MCP-sourced tools.
* @param LoggerInterface $logger PSR logger.
*
* @spec openspec/changes/retrofit-2026-04-28-b2b-crossrefs/tasks.md#task-20
*/
Expand Down Expand Up @@ -199,9 +201,10 @@
if (in_array($appId, ['registers', 'schemas', 'objects', 'openregister'], true) === true) {
continue;
}

try {
foreach ($provider->getTools() as $descriptor) {
$mcpId = (string) ($descriptor['id'] ?? '');

Check failure on line 207 in lib/Listener/ToolRegistrationListener.php

View workflow job for this annotation

GitHub Actions / quality / PHP Quality (phpstan)

Offset 'id' on array{id: string, name: string, description: string, inputSchema: array} on left side of ?? always exists and is not nullable.
if ($mcpId === '' || preg_match('/^[a-z0-9_]+\.[a-zA-Z0-9_]+$/', $mcpId) === 0) {
// Tool id is non-conforming (camelCase or missing
// dot). Skip — the LLM-visible id MUST match the
Expand All @@ -223,13 +226,13 @@
'app' => $appId,
]
);
}
}//end foreach
} catch (\Throwable $e) {
$this->logger->warning(
'[ToolRegistrationListener] Failed to bridge MCP provider',
['appId' => $appId, 'error' => $e->getMessage()]
);
}
}
}//end try
}//end foreach
}//end handle()
}//end class
Loading
Loading