From 15a9cef2059a2d0b9c240ad79f40a26052641d5d Mon Sep 17 00:00:00 2001 From: Osama Bashir Date: Fri, 9 Oct 2026 09:57:12 +0300 Subject: [PATCH] Hide inactive tools and block calls to them --- .../Mcp/Tools/Mcp/Tool/ToolProvider.php | 18 +++++++++++++++++- .../ToolsCall/ToolsCallGeneralProcessor.php | 9 +++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/files/custom/Espo/Modules/Mcp/Tools/Mcp/Tool/ToolProvider.php b/src/files/custom/Espo/Modules/Mcp/Tools/Mcp/Tool/ToolProvider.php index ccd4b43..01ff340 100644 --- a/src/files/custom/Espo/Modules/Mcp/Tools/Mcp/Tool/ToolProvider.php +++ b/src/files/custom/Espo/Modules/Mcp/Tools/Mcp/Tool/ToolProvider.php @@ -62,6 +62,10 @@ public function __construct( $tools = []; foreach ($this->endpoint->getFeatures() as $feature) { + if (!$feature->isActive()) { + continue; + } + $tool = $this->getForFeature($feature); if (!$tool) { @@ -117,7 +121,19 @@ public function getAll(): array */ private function getEnvelopeAll(): array { - return $this->dataCacheAccess->get(); + $activeFeatureIds = []; + + foreach ($this->endpoint->getFeatures() as $feature) { + if ($feature->isActive()) { + $activeFeatureIds[$feature->getId()] = true; + } + } + + // Cached definitions must not restore a feature that was revoked or unlinked. + return array_values(array_filter( + $this->dataCacheAccess->get(), + fn (ToolEnvelope $item) => isset($activeFeatureIds[$item->featureId]), + )); } /** diff --git a/src/files/custom/Espo/Modules/Mcp/Tools/Mcp/ToolsCall/ToolsCallGeneralProcessor.php b/src/files/custom/Espo/Modules/Mcp/Tools/Mcp/ToolsCall/ToolsCallGeneralProcessor.php index bc8dd29..8906cc9 100644 --- a/src/files/custom/Espo/Modules/Mcp/Tools/Mcp/ToolsCall/ToolsCallGeneralProcessor.php +++ b/src/files/custom/Espo/Modules/Mcp/Tools/Mcp/ToolsCall/ToolsCallGeneralProcessor.php @@ -59,10 +59,10 @@ public function process(CallToolRequestParams $params): CallToolResult { $toolEnvelope = $this->toolProvider->get($params->name); - $this->jsonSchemaValidator->assert($toolEnvelope->tool->inputSchema, $params->arguments); - $feature = $this->getFeature($toolEnvelope->featureId, $params->name); + $this->jsonSchemaValidator->assert($toolEnvelope->tool->inputSchema, $params->arguments); + $processor = $this->processorFactory->create($params->name); try { @@ -76,6 +76,7 @@ public function process(CallToolRequestParams $params): CallToolResult /** * @throws InternalError + * @throws InvalidParamsError */ private function getFeature(string $id, string $name): Feature { @@ -85,6 +86,10 @@ private function getFeature(string $id, string $name): Feature throw new InternalError("Feature `$id` for tool `$name` not found."); } + if (!$feature->isActive()) { + throw new InvalidParamsError("Tool `$name` not found."); + } + return $feature; } }