Skip to content

Commit c6e7585

Browse files
Sync MagentoMcpAi module: CLI agent, tools, MultiLLM, docs
- Add genaker:agento:llm CLI (chat + analyzer modes) - Add tool registry: execute_sql_query, describe_table, grep_files, read_file, get_magento_info, run_magento_cli, ask_user - Add CliChatWithToolsService, MgentoAIService, MultiLLMService - Add TOOLS_AND_LLM.md, DATABASE_TOOLS_DOCUMENTATION.md, MAGENTO_AI_QUERY_ANALYZER.md - Update README with tools overview and documentation links - Add integration and unit tests - Various controller/model updates Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 3d4313f commit c6e7585

71 files changed

Lines changed: 18123 additions & 2558 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Api/DatabaseToolInterface.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Genaker\MagentoMcpAi\Api;
5+
6+
/**
7+
* Database Tool Interface
8+
*
9+
* Implement this interface to create custom database tools that can be used
10+
* by the LlmAnalyzer CLI command (`genaker:agento:llm`) via tool calling.
11+
*
12+
* @api
13+
*/
14+
interface DatabaseToolInterface
15+
{
16+
/**
17+
* Get tool name (must be unique)
18+
*
19+
* @return string
20+
*/
21+
public function getName(): string;
22+
23+
/**
24+
* Get tool description for AI
25+
*
26+
* @return string
27+
*/
28+
public function getDescription(): string;
29+
30+
/**
31+
* Get tool parameters schema (OpenAPI-style JSON schema)
32+
*
33+
* @return array
34+
*/
35+
public function getParametersSchema(): array;
36+
37+
/**
38+
* Execute the tool
39+
*
40+
* @param array $arguments Tool arguments
41+
* @param bool $allowDangerous Whether dangerous operations are allowed
42+
* @return array Result array with 'success', 'data', 'preview', etc.
43+
* @throws \Exception
44+
*/
45+
public function execute(array $arguments, bool $allowDangerous = false): array;
46+
}

Api/Service/AIServiceInterface.php

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Genaker\MagentoMcpAi\Api\Service;
5+
6+
/**
7+
* AI Service Interface
8+
*
9+
* Generic interface for AI services supporting multiple providers
10+
* Abstracts the underlying implementation (OpenAI, Claude, Gemini, etc)
11+
*
12+
* @api
13+
*/
14+
interface AIServiceInterface
15+
{
16+
/**
17+
* Send a chat request
18+
*
19+
* @param string $message User message
20+
* @param array $messages Previous messages (conversation history)
21+
* @param int $maxTokens Maximum tokens in response
22+
* @param float $temperature Temperature for randomness
23+
* @param array $tools Function definitions
24+
* @return array Response with 'success', 'message', 'tokens', 'cost', 'model', 'provider'
25+
* @throws \Magento\Framework\Exception\LocalizedException
26+
*/
27+
public function sendChatRequest(
28+
string $message,
29+
array $messages = [],
30+
int $maxTokens = 2000,
31+
float $temperature = 0.7,
32+
array $tools = []
33+
): array;
34+
35+
/**
36+
* Get chat completion (simple wrapper)
37+
*
38+
* @param string $prompt User prompt
39+
* @param array $messages Conversation history
40+
* @param int $maxTokens Max tokens
41+
* @param float $temperature Temperature
42+
* @return string Response text
43+
* @throws \Magento\Framework\Exception\LocalizedException
44+
*/
45+
public function getChatCompletion(
46+
string $prompt,
47+
array $messages = [],
48+
int $maxTokens = 2000,
49+
float $temperature = 0.7
50+
): string;
51+
52+
/**
53+
* Get completion with structured response
54+
*
55+
* @param string $prompt Prompt text
56+
* @param int $maxTokens Max tokens
57+
* @return array Response with 'success', 'completion', 'tokens', 'cost'
58+
* @throws \Magento\Framework\Exception\LocalizedException
59+
*/
60+
public function getCompletion(string $prompt, int $maxTokens = 2000): array;
61+
62+
/**
63+
* Get API key
64+
*
65+
* @return string API key
66+
* @throws \Magento\Framework\Exception\LocalizedException
67+
*/
68+
public function getApiKey(): string;
69+
70+
/**
71+
* Generate embeddings
72+
*
73+
* @param string $text Text to embed
74+
* @return array Embedding vector
75+
* @throws \Magento\Framework\Exception\LocalizedException
76+
*/
77+
public function generateEmbeddings(string $text): array;
78+
79+
/**
80+
* Generate image
81+
*
82+
* @param string $prompt Image description
83+
* @param int $size Image size
84+
* @return array Generated image info
85+
* @throws \Magento\Framework\Exception\LocalizedException
86+
*/
87+
public function generateImage(string $prompt, int $size = 512): array;
88+
89+
/**
90+
* Send function calling request
91+
*
92+
* @param string $message User message
93+
* @param array $functions Function definitions
94+
* @param int $maxTokens Max tokens
95+
* @return array Response with function calls
96+
* @throws \Magento\Framework\Exception\LocalizedException
97+
*/
98+
public function sendFunctionCallingRequest(
99+
string $message,
100+
array $functions,
101+
int $maxTokens = 4096
102+
): array;
103+
104+
/**
105+
* Transcribe audio
106+
*
107+
* @param string $filePath Audio file path
108+
* @param string $model Model to use
109+
* @return array Transcription result
110+
* @throws \Magento\Framework\Exception\LocalizedException
111+
*/
112+
public function transcribeAudio(string $filePath, string $model = 'whisper-1'): array;
113+
114+
/**
115+
* Generate speech
116+
*
117+
* @param string $text Text to speak
118+
* @param string $voice Voice type
119+
* @return array Speech generation result
120+
* @throws \Magento\Framework\Exception\LocalizedException
121+
*/
122+
public function generateSpeech(string $text, string $voice = 'alloy'): array;
123+
124+
/**
125+
* Get available providers
126+
*
127+
* @return array List of available providers
128+
*/
129+
public function getAvailableProviders(): array;
130+
131+
/**
132+
* Get pricing information
133+
*
134+
* @param string $provider Provider name
135+
* @return array Pricing info
136+
*/
137+
public function getPricing(string $provider): array;
138+
}

0 commit comments

Comments
 (0)