deepseek-1.x-dev/src/McpPluginManager.php

src/McpPluginManager.php
<?php

namespace Drupal\deepseek;

use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\deepseek\Attribute\McpTool;

/**
 * McpTool plugin manager.
 */
class McpPluginManager extends DefaultPluginManager {

  /**
   * Constructs the object.
   */
  public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
    parent::__construct('Plugin/McpTool', $namespaces, $module_handler, McpInterface::class, McpTool::class);
    $this->alterInfo('mcp_tool_info');
    $this->setCacheBackend($cache_backend, 'mcp_tool_plugins');
  }

  /**
   * Executes a tool by its ID.
   *
   * @param string $id
   *   The tool ID.
   * @param array $params
   *   The parameters for the tool.
   *
   * @return array
   *   The result of the tool execution.
   *
   * @throws \Exception
   */
  public function executeTool(string $id, array $params): array {
    $plugin = $this->createInstance($id);
    return $plugin->execute($params);
  }

  /**
   * Gets the list of all tools.
   *
   * @return array
   *   An array of tool configurations.
   */
  public function getToolsList(): array {
    $tools = [];
    foreach ($this->getDefinitions() as $id => $definition) {
      $tools[] = [
        'name' => $id,
        'description' => $definition['description'] instanceof TranslatableMarkup ?
        $definition['description']->render() :
        ($definition['description'] ?? ''),
        'parameters' => [
          'type' => 'object',
          'properties' => $definition['parameters'] ?? [],
          'required' => $definition['required'] ?? [],
        ],
      ];
    }
    return $tools;
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc