Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/aimogen-pro/res/aiomatic-mcp-menu.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
function aiomatic_mcp_panel()
3
+
{
4
+
$settings = get_option('aiomatic_mcp_settings', []);
5
+
$bearer_token = isset($settings['bearer_token']) ? $settings['bearer_token'] : '';
6
+
$aiomatic_Main_Settings = get_option('aiomatic_Main_Settings', false);
7
+
$sse_url = esc_url_raw( rest_url('aiomatic-mcp/v1/sse') );
8
+
$messages_url = esc_url_raw( rest_url('aiomatic-mcp/v1/messages') );
9
+
$tools_url = esc_url_raw( rest_url('aiomatic-mcp/v1/aiomatic-tools') );
10
+
?>
11
+
<div class="wp-header-end"></div>
12
+
<div class="wrap gs_popuptype_holder seo_pops">
13
+
<h2 class="cr_center"><?php echo esc_html__('Aimogen MCP (Model Context Protocol)', 'aiomatic-automatic-ai-content-writer'); ?></h2>
14
+
</div>
15
+
<div class="wrap gs_popuptype_holder">
16
+
<h1><?php echo esc_html__('MCP', 'aiomatic-automatic-ai-content-writer'); ?></h1>
17
+
18
+
<nav class="nav-tab-wrapper">
19
+
<a href="#tab-0" class="nav-tab nav-tab-active"><?php echo esc_html__('Tutorial', 'aiomatic-automatic-ai-content-writer'); ?></a>
20
+
<a href="#tab-1" class="nav-tab"><?php echo esc_html__('Create Your MCP Server', 'aiomatic-automatic-ai-content-writer'); ?></a>
21
+
<a href="#tab-2" class="nav-tab"><?php echo esc_html__('Connect To A MCP Server', 'aiomatic-automatic-ai-content-writer'); ?></a>
22
+
</nav>
23
+
24
+
<div id="tab-0" class="tab-content" style="display:block">
25
+
<br/><h3><?php echo esc_html__('MCP Server Tutorial', 'aiomatic-automatic-ai-content-writer'); ?></h3>
26
+
<div>
27
+
<p>
28
+
<?php echo esc_html__('The Model Context Protocol (MCP) support built into Aimogen allows your WordPress site to become more than just a publishing platform.
29
+
Once enabled, your site acts as an MCP server using Server Sent Events (SSE).
30
+
This means tools like Claude Desktop can connect through a local relay script, and services like OpenAI Deep Research can discover and call the functions you expose here.', 'aiomatic-automatic-ai-content-writer'); ?>
31
+
</p>
32
+
<p>
33
+
<?php echo esc_html__('Enabling the MCP extension plugin unlocks a control panel where you can decide which tool packs are exposed.
34
+
The Core WordPress pack is recommended because it registers useful functions that let AI models interact with posts, pages, media, taxonomies, and other essentials.
35
+
You can also turn on plugin oriented helpers, theme oriented helpers, or even WooCommerce helpers if you run a shop.
36
+
There is an option to generate a dynamic REST layer that creates CRUD style endpoints for content, giving models a way to create or update posts directly.', 'aiomatic-automatic-ai-content-writer'); ?>
37
+
</p>
38
+
<p>
39
+
<?php echo esc_html__('Once you check the setting to enable the SSE server, an endpoint will be available and protected by the Bearer Token you configure.
40
+
Any client connecting to this endpoint must provide the correct token.
41
+
There is also a Debug Mode which is only intended for local testing, it lets you see raw function registrations and requests.', 'aiomatic-automatic-ai-content-writer'); ?>
42
+
</p>
43
+
<p>
44
+
<?php echo esc_html__('When the extension is active and SSE is enabled you will see your live endpoints listed below.
45
+
These are the exact URLs that an MCP client or relay script will consume.
46
+
For example, Claude Desktop requires a relay script pointing to the SSE endpoint, while Deep Research clients may call the Messages endpoint to exchange structured data.', 'aiomatic-automatic-ai-content-writer'); ?>
47
+
</p>
48
+
<p>
49
+
<?php echo esc_html__('If you scroll further down in the MCP panel you will also see the Messages endpoint and the list of registered tools.
50
+
The refresh button will query your server and print the current function set in JSON format, which makes it easy to verify what is exposed.', 'aiomatic-automatic-ai-content-writer'); ?>
51
+
</p>
52
+
<p>
53
+
<?php echo esc_html__('For users running multiple MCP servers, the Connect tab lets you register and manage external servers.
54
+
Each server entry has a name, description, URL, authentication token, and a flag for global enablement.
55
+
Aimogen will then merge those into the active context for supported AI models, allowing you to extend functionality across different environments.', 'aiomatic-automatic-ai-content-writer'); ?>
56
+
</p>
57
+
<p>
58
+
<?php echo esc_html__('In short, Aimogen\'s MCP support turns your WordPress site into a living API hub that AI tools can call.
59
+
By enabling SSE, protecting it with a token, and choosing the right tool packs, you gain fine control over how AI assistants interact with your content, plugins, themes, and store.
60
+
The extension plugin is required for this functionality and once active, everything can be configured directly here in the WordPress admin panel.', 'aiomatic-automatic-ai-content-writer'); ?>
61
+
</p>
62
+
<p><?php echo wp_kses(
63
+
sprintf(
64
+
__(
65
+
'Check %s for more details on usage of the MCP server feature of Aimogen.',
66
+
'aiomatic-automatic-ai-content-writer'
67
+
),
68
+
'<a href="https://coderevolution.ro/knowledge-base/faq/how-to-connect-claude-to-wordpress-with-aiomatic-mcp/" target="_blank">this tutorial</a>'
69
+
),
70
+
array(
71
+
'a' => array(
72
+
'href' => array(),
73
+
'target' => array(),
74
+
),
75
+
)
76
+
);?></p>
77
+
</div>
78
+
79
+
<?php if (!isset($aiomatic_Main_Settings['hide_videos']) || trim($aiomatic_Main_Settings['hide_videos']) != 'on') { ?>
80
+
<h3><?php echo esc_html__('Tutorial Video', 'aiomatic-automatic-ai-content-writer'); ?></h3>
81
+
<p class="cr_center">
82
+
<div class="embedtool">
83
+
<iframe src="https://www.youtube.com/embed/niILXouTah4" frameborder="0" allowfullscreen></iframe>
84
+
</div>
85
+
</p>
86
+
<?php } ?>
87
+
</div>
88
+
89
+
<div id="tab-1" class="tab-content" style="display:none">
90
+
<br/>
91
+
<h3><?php echo esc_html__('Create Your Own MCP Server', 'aiomatic-automatic-ai-content-writer'); ?></h3>
92
+
<p><?php echo esc_html__('Create a MCP server on your website and allow AI models to directly connect to it and use tools published by it. Like this, external AI models can control your site, query information from it and insert or update data on it.', 'aiomatic-automatic-ai-content-writer'); ?></p>
93
+
<p><?php echo esc_html__('If your server is behind Cloudflare, go to Cloudflare settings for your site -> Security -> Security Rules -> click Create Rule -> Custom Rules -> add a name of your choice -> in Field select URI -> in Value add: ', 'aiomatic-automatic-ai-content-writer')
94
+
. '<strong>/wp-json/aiomatic-mcp/v1/*</strong>' . esc_html__(' -> in Choose action select Skip -> select all checkboxes in WAF components to skip -> click More components to skip and also select all new checkboxes which appeared -> click Deploy', 'aiomatic-automatic-ai-content-writer'); ?></p>
95
+
<hr/>
96
+
<?php
97
+
if ( ! function_exists( 'is_plugin_active' ) ) {
98
+
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
99
+
}
100
+
101
+
if ( is_plugin_active( 'aiomatic-extension-mcp-server/aiomatic-extension-mcp-server.php' ) )
102
+
{
103
+
?>
104
+
<form method="post" action="options.php">
105
+
<?php settings_fields('aiomatic_mcp'); ?>
106
+
<?php $opt = wp_parse_args($settings, [
107
+
'enable_sse' => '', 'bearer_token' => '', 'enable_debug' => '',
108
+
'tuned_core' => 'on', 'tuned_plugins' => '', 'tuned_themes' => '',
109
+
'dynamic_rest' => '', 'tuned_woocommerce' => '', 'session_memory' => '', 'embeddings_sse' => '', 'advanced_sse' => ''
110
+
]); ?>
111
+
112
+
<table class="form-table">
113
+
<tr>
114
+
<th scope="row"><?php echo esc_html__('Enable SSE server', 'aiomatic-automatic-ai-content-writer'); ?></th>
115
+
<td><input type="hidden" name="aiomatic_mcp_settings[enable_sse]" value="" /><label><input type="checkbox" name="aiomatic_mcp_settings[enable_sse]" <?php checked($opt['enable_sse'], 'on'); ?> /> <?php echo esc_html__('Enables the MCP SSE endpoint', 'aiomatic-automatic-ai-content-writer'); ?></label></td>
116
+
</tr>
117
+
<tr class="mcp_sse">
118
+
<th scope="row"><?php echo esc_html__('Bearer Token', 'aiomatic-automatic-ai-content-writer'); ?></th>
119
+
<td><input type="text" name="aiomatic_mcp_settings[bearer_token]" value="<?php echo esc_attr($opt['bearer_token']); ?>" class="regular-text" /><p class="description"><?php echo esc_html__('MCP will be usable by using this Bearer Token. If you intend to use this in Claude Desktop, don\'t use any upper case letters in the token.', 'aiomatic-automatic-ai-content-writer'); ?></p></td>
120
+
</tr>
121
+
<tr class="mcp_sse">
122
+
<th scope="row"><?php echo esc_html__('Enable Debug Mode', 'aiomatic-automatic-ai-content-writer'); ?></th>
123
+
<td><input type="hidden" name="aiomatic_mcp_settings[enable_debug]" value="" /><label><input type="checkbox" name="aiomatic_mcp_settings[enable_debug]" <?php checked($opt['enable_debug'], 'on'); ?> /> <?php echo esc_html__('Enables debug mode - only use for local testing', 'aiomatic-automatic-ai-content-writer'); ?></label></td>
124
+
</tr>
125
+
<tr class="mcp_sse"><th colspan="2"><h3><?php echo esc_html__('Enabled Tool Packs', 'aiomatic-automatic-ai-content-writer'); ?></h3></th></tr>
126
+
<tr class="mcp_sse"><th scope="row"><?php echo esc_html__('Core WordPress Functionality', 'aiomatic-automatic-ai-content-writer'); ?></th><td><input type="hidden" name="aiomatic_mcp_settings[tuned_core]" value="" /><label><input type="checkbox" name="aiomatic_mcp_settings[tuned_core]" <?php checked($opt['tuned_core'], 'on'); ?> /> <?php echo esc_html__('Registers core WordPress tools (recommended)', 'aiomatic-automatic-ai-content-writer'); ?></label></td></tr>
127
+
<tr class="mcp_sse"><th scope="row"><?php echo esc_html__('Plugins Related Functionality', 'aiomatic-automatic-ai-content-writer'); ?></th><td><input type="hidden" name="aiomatic_mcp_settings[tuned_plugins]" value="" /><label><input type="checkbox" name="aiomatic_mcp_settings[tuned_plugins]" <?php checked($opt['tuned_plugins'], 'on'); ?> /> <?php echo esc_html__('Plugin oriented helpers (optional)', 'aiomatic-automatic-ai-content-writer'); ?></label></td></tr>
128
+
<tr class="mcp_sse"><th scope="row"><?php echo esc_html__('Themes Related Functionality', 'aiomatic-automatic-ai-content-writer'); ?></th><td><input type="hidden" name="aiomatic_mcp_settings[tuned_themes]" value="" /><label><input type="checkbox" name="aiomatic_mcp_settings[tuned_themes]" <?php checked($opt['tuned_themes'], 'on'); ?> /> <?php echo esc_html__('Theme oriented helpers (optional)', 'aiomatic-automatic-ai-content-writer'); ?></label></td></tr>
129
+
<tr class="mcp_sse"><th scope="row"><?php echo esc_html__('Dynamic REST API', 'aiomatic-automatic-ai-content-writer'); ?></th><td><input type="hidden" name="aiomatic_mcp_settings[dynamic_rest]" value="" /><label><input type="checkbox" name="aiomatic_mcp_settings[dynamic_rest]" <?php checked($opt['dynamic_rest'], 'on'); ?> /> <?php echo esc_html__('Generate CRUD tools for posts, pages, media (optional)', 'aiomatic-automatic-ai-content-writer'); ?></label></td></tr>
130
+
<tr class="mcp_sse">
131
+
<th scope="row">
132
+
<?php echo esc_html__( 'Agent Session Memory', 'aiomatic-automatic-ai-content-writer' ); ?>
133
+
</th>
134
+
<td>
135
+
<input type="hidden" name="aiomatic_mcp_settings[session_memory]" value="" />
136
+
<label>
137
+
<input type="checkbox"
138
+
name="aiomatic_mcp_settings[session_memory]"
139
+
<?php checked( $opt['session_memory'], 'on' ); ?>
140
+
<?php disabled( ! function_exists( 'aiomatic_mcp_session_tools' ) ); ?> />
141
+
<?php echo esc_html__( 'Allows the AI to memorize information for its processing (optional)', 'aiomatic-automatic-ai-content-writer' ); ?>
142
+
</label>
143
+
<?php if ( ! function_exists( 'aiomatic_mcp_session_tools' ) ) : ?>
144
+
<p class="description">
145
+
<?php echo esc_html__( 'Requires latest update of the "Aimogen Extension - MCP Server Creator" plugin.', 'aiomatic-automatic-ai-content-writer' ); ?>
146
+
</p>
147
+
<?php endif; ?>
148
+
</td>
149
+
</tr>
150
+
<tr class="mcp_sse">
151
+
<th scope="row">
152
+
<?php echo esc_html__( 'Embeddings', 'aiomatic-automatic-ai-content-writer' ); ?>
153
+
</th>
154
+
<td>
155
+
<input type="hidden" name="aiomatic_mcp_settings[embeddings_sse]" value="" />
156
+
<label>
157
+
<input type="checkbox"
158
+
name="aiomatic_mcp_settings[embeddings_sse]"
159
+
<?php checked( $opt['embeddings_sse'], 'on' ); ?>
160
+
<?php disabled( ! function_exists( 'aiomatic_mcp_embeddings_tools' ) ); ?> />
161
+
<?php echo esc_html__( 'Allows access to the AI to internal embeddings (optional)', 'aiomatic-automatic-ai-content-writer' ); ?>
162
+
</label>
163
+
<?php if ( ! function_exists( 'aiomatic_mcp_embeddings_tools' ) ) : ?>
164
+
<p class="description">
165
+
<?php echo esc_html__( 'Requires latest update of the "Aimogen Extension - MCP Server Creator" plugin.', 'aiomatic-automatic-ai-content-writer' ); ?>
166
+
</p>
167
+
<?php endif; ?>
168
+
</td>
169
+
</tr>
170
+
<tr class="mcp_sse">
171
+
<th scope="row">
172
+
<?php echo esc_html__( 'Advanced Functionality', 'aiomatic-automatic-ai-content-writer' ); ?>
173
+
</th>
174
+
<td>
175
+
<input type="hidden" name="aiomatic_mcp_settings[advanced_sse]" value="" />
176
+
<label>
177
+
<input type="checkbox"
178
+
name="aiomatic_mcp_settings[advanced_sse]"
179
+
<?php checked( $opt['advanced_sse'], 'on' ); ?>
180
+
<?php disabled( ! function_exists( 'aiomatic_mcp_advanced_tools' ) ); ?> />
181
+
<?php echo esc_html__( 'Access tools like: Amazon Product Details, Scrape Sites & RSS, Internet Search Result, YouTube Video Search & Captions, Send Email (optional)', 'aiomatic-automatic-ai-content-writer' ); ?>
182
+
</label>
183
+
<?php if ( ! function_exists( 'aiomatic_mcp_advanced_tools' ) ) : ?>
184
+
<p class="description">
185
+
<?php echo esc_html__( 'Requires latest update of the "Aimogen Extension - MCP Server Creator" plugin.', 'aiomatic-automatic-ai-content-writer' ); ?>
186
+
</p>
187
+
<?php endif; ?>
188
+
</td>
189
+
</tr>
190
+
<tr class="mcp_sse">
191
+
<th scope="row">
192
+
<?php echo esc_html__( 'WooCommerce Related Functionality', 'aiomatic-automatic-ai-content-writer' ); ?>
193
+
</th>
194
+
<td>
195
+
<input type="hidden" name="aiomatic_mcp_settings[tuned_woocommerce]" value="" />
196
+
<label>
197
+
<input type="checkbox"
198
+
name="aiomatic_mcp_settings[tuned_woocommerce]"
199
+
<?php checked( $opt['tuned_woocommerce'], 'on' ); ?>
200
+
<?php disabled( ! class_exists( 'WooCommerce' ) ); ?> />
201
+
<?php echo esc_html__( 'WooCommerce oriented helpers (optional)', 'aiomatic-automatic-ai-content-writer' ); ?>
202
+
</label>
203
+
<?php if ( ! class_exists( 'WooCommerce' ) ) : ?>
204
+
<p class="description">
205
+
<?php echo esc_html__( 'Requires WooCommerce to be active.', 'aiomatic-automatic-ai-content-writer' ); ?>
206
+
</p>
207
+
<?php endif; ?>
208
+
</td>
209
+
</tr>
210
+
<tr class="mcp_sse">
211
+
<td colspan="2">
212
+
213
+
<h3><?php echo esc_html__('Endpoints', 'aiomatic-automatic-ai-content-writer'); ?></h3>
214
+
<table class="widefat striped">
215
+
<tbody>
216
+
<tr>
217
+
<th class="align-top pr-4 text-gray-600 font-medium">
218
+
<?php echo esc_html__('SSE Endpoint', 'aiomatic-automatic-ai-content-writer'); ?>
219
+
</th>
220
+
<td>
221
+
<div class="flex items-center gap-2 bg-gray-100 rounded-xl px-3 py-2 border border-gray-200">
222
+
<strong class="cr_red">
223
+
<code class="text-sm text-gray-800 break-all">
224
+
<?php echo esc_html($sse_url); ?>
225
+
</code>
226
+
</strong>
227
+
<button
228
+
type="button"
229
+
class="ml-2 inline-flex items-center px-2 py-1 text-xs font-medium text-gray-600 bg-white border border-gray-300 rounded-lg shadow-sm hover:bg-gray-50 active:bg-gray-100 transition"
230
+
onclick="navigator.clipboard.writeText('<?php echo esc_js($sse_url); ?>'); this.innerText='Copied!'; setTimeout(() => this.innerText='Copy', 2000);"
231
+
>
232
+
<?php echo esc_html__('Copy', 'aiomatic-automatic-ai-content-writer'); ?>
233
+
</button>
234
+
</div>
235
+
</td>
236
+
</tr>
237
+
<tr><th> <?php echo esc_html__('Messages Endpoint', 'aiomatic-automatic-ai-content-writer'); ?></th><td><code><?php echo esc_html($messages_url); ?></code></td></tr>
238
+
</tbody>
239
+
</table>
240
+
</td>
241
+
</tr>
242
+
</table>
243
+
<p class="crsubmit"><input type="submit" name="btnSubmit" id="btnSubmit" class="button button-primary" onclick="unsaved = false;" value="<?php echo esc_html__("Save Settings", 'aiomatic-automatic-ai-content-writer');?>"/></p>
244
+
</form>
245
+
246
+
<h3><?php echo esc_html__('Debug', 'aiomatic-automatic-ai-content-writer'); ?></h3>
247
+
<p><button class="button" id="aiomatic-mcp-refresh"><?php echo esc_html__('Refresh Function List', 'aiomatic-automatic-ai-content-writer'); ?></button>
248
+
<span id="aiomatic-mcp-refresh-status" style="margin-left:6px;"></span></p>
249
+
<pre id="aiomatic-mcp-functions" style="max-height:380px;overflow:auto;background:#111;color:#eee;padding:12px;border-radius:8px;"></pre>
250
+
<?php
251
+
}
252
+
else
253
+
{
254
+
?>
255
+
<div style="padding:20px; border-radius:12px; background:#f9f9f9; border:1px solid #ddd; text-align:center; max-width:600px; margin:20px auto;">
256
+
<h2 style="margin-bottom:10px; color:#333;">
257
+
<?php echo esc_html__('MCP Extension Required', 'aiomatic-automatic-ai-content-writer'); ?>
258
+
</h2>
259
+
<p style="margin-bottom:15px; color:#555; font-size:15px;">
260
+
<?php echo esc_html__('This functionality is only available if the Aimogen MCP Server Extension plugin is active.', 'aiomatic-automatic-ai-content-writer'); ?>
261
+
</p>
262
+
<a href="https://wpbay.com/product/aiomatic-extension-mcp-server-creator/" target="_blank"
263
+
style="display:inline-block; padding:10px 20px; background:#0073aa; color:#fff; text-decoration:none; border-radius:6px; font-weight:bold;">
264
+
<?php echo esc_html__('Purchase Plugin', 'aiomatic-automatic-ai-content-writer'); ?>
265
+
</a>
266
+
</div>
267
+
<?php
268
+
}
269
+
?>
270
+
</div>
271
+
<?php
272
+
$aiomatic_Main_Settings = get_option('aiomatic_Main_Settings', false);
273
+
274
+
$aiomatic_enabled = isset($aiomatic_Main_Settings['aiomatic_enabled']) ? $aiomatic_Main_Settings['aiomatic_enabled'] : '';
275
+
$responses_api = isset($aiomatic_Main_Settings['responses_api']) ? $aiomatic_Main_Settings['responses_api'] : '';
276
+
$api_selector = isset($aiomatic_Main_Settings['api_selector']) ? $aiomatic_Main_Settings['api_selector'] : 'openai';
277
+
278
+
$is_aiomaticapi = false;
279
+
$token = '';
280
+
if (!empty($aiomatic_Main_Settings['app_id'])) {
281
+
$appids = preg_split('/\r\n|\r|\n/', trim($aiomatic_Main_Settings['app_id']));
282
+
$appids = array_filter($appids);
283
+
if (count($appids) == 1) {
284
+
$token = $appids[array_rand($appids)];
285
+
$token = apply_filters('aimogen_openai_api_key', $token);$token = apply_filters('aiomatic_openai_api_key', $token);
286
+
if (aiomatic_is_aiomaticapi_key($token)) {
287
+
$call_count = get_transient('aiomaticapi_tokens');
288
+
if ($token != '' && $call_count !== false) {
289
+
$is_aiomaticapi = true;
290
+
}
291
+
}
292
+
}
293
+
}
294
+
?>
295
+
<div id="tab-2" class="tab-content" style="display:none">
296
+
<br/>
297
+
<h3><?php echo esc_html__('MCP Server Connections', 'aiomatic-automatic-ai-content-writer'); ?></h3>
298
+
<?php if ($aiomatic_enabled === 'on' && $responses_api === 'on' && $api_selector === 'openai' && !$is_aiomaticapi): ?>
299
+
<p><?php echo esc_html__('Configure external MCP servers here. These servers extend AI capabilities by providing tools and functions that AI models can call during conversations.', 'aiomatic-automatic-ai-content-writer'); ?></p>
300
+
<hr/><br/>
301
+
<div class="mcp-servers-container">
302
+
<button type="button" class="button button-primary" id="add-mcp-server"><?php echo esc_html__('New MCP Server Connection', 'aiomatic-automatic-ai-content-writer'); ?></button>
303
+
<div id="mcp-server-list" style="margin-top:20px;">
304
+
<?php
305
+
$mcp_servers = get_option('aiomatic_mcp_servers', array());
306
+
if (!empty($mcp_servers)) {
307
+
foreach ($mcp_servers as $id => $server) {
308
+
?>
309
+
<div class="mcp-server-entry" data-id="<?php echo esc_attr($id); ?>" style="border:1px solid #ccd0d4;padding:12px;margin-bottom:12px;border-radius:6px;background:#fff;">
310
+
<h4><?php echo esc_html($server['name']); ?></h4>
311
+
<?php if (!empty($server['description'])): ?>
312
+
<p><strong><?php echo esc_html__('Description:', 'aiomatic-automatic-ai-content-writer'); ?></strong> <span class="descr"><?php echo esc_html($server['description']); ?></span></p>
313
+
<?php endif; ?>
314
+
<p>
315
+
<strong><?php echo esc_html__('URL:', 'aiomatic-automatic-ai-content-writer'); ?></strong>
316
+
<?php echo esc_html($server['url']); ?>
317
+
<span class="srv-url" style="display:none;"><?php echo esc_attr($server['url']); ?></span>
318
+
</p>
319
+
<p>
320
+
<strong><?php echo esc_html__('Token:', 'aiomatic-automatic-ai-content-writer'); ?></strong>
321
+
<?php if (!empty($server['token'])): ?>
322
+
********
323
+
<span class="tkn" style="display:none;"><?php echo esc_html($server['token']); ?></span>
324
+
<?php else: ?>
325
+
-
326
+
<?php endif; ?>
327
+
</p>
328
+
<p>
329
+
<strong><?php echo esc_html__('Enabled Globally:', 'aiomatic-automatic-ai-content-writer'); ?></strong>
330
+
<?php echo !empty($server['global']) && $server['global'] === 'on' ? esc_html__('Yes', 'aiomatic-automatic-ai-content-writer') : esc_html__('No', 'aiomatic-automatic-ai-content-writer'); ?>
331
+
<span class="srv-global" style="display:none;"><?php echo !empty($server['global']) && $server['global'] === 'on' ? 'on' : 'off'; ?></span>
332
+
</p>
333
+
<p><strong><?php echo esc_html__('Server ID:', 'aiomatic-automatic-ai-content-writer'); ?></strong> <?php echo esc_html($id); ?></p>
334
+
<button type="button" class="button edit-mcp-server"><?php echo esc_html__('Edit', 'aiomatic-automatic-ai-content-writer'); ?></button>
335
+
<button type="button" class="button delete-mcp-server" onclick="unsaved = false;"><?php echo esc_html__('Delete', 'aiomatic-automatic-ai-content-writer'); ?></button>
336
+
</div>
337
+
<?php
338
+
}
339
+
} else {
340
+
echo '<p>' . esc_html__('No MCP servers configured yet.', 'aiomatic-automatic-ai-content-writer') . '</p>';
341
+
}
342
+
?>
343
+
</div>
344
+
</div>
345
+
346
+
<!-- Add/Edit form -->
347
+
<div id="mcp-server-form" style="display:none; margin-top:20px; background:#f9f9f9; padding:15px; border:1px solid #ccd0d4; border-radius:6px;">
348
+
<h4><?php echo esc_html__('Add / Edit MCP Server', 'aiomatic-automatic-ai-content-writer'); ?></h4>
349
+
<table class="form-table">
350
+
<tr>
351
+
<th><label for="mcp-server-name"><?php echo esc_html__('Name', 'aiomatic-automatic-ai-content-writer'); ?></label></th>
352
+
<td>
353
+
<input type="text" id="mcp-server-name" class="regular-text" placeholder="Your MCP Server Name" />
354
+
<input type="hidden" id="mcp-server-id" />
355
+
</td>
356
+
</tr>
357
+
<tr>
358
+
<th><label for="mcp-server-description"><?php echo esc_html__('Description', 'aiomatic-automatic-ai-content-writer'); ?></label></th>
359
+
<td>
360
+
<textarea id="mcp-server-description" class="large-text" rows="3" placeholder="Short description of what this server does"></textarea>
361
+
</td>
362
+
</tr>
363
+
<tr>
364
+
<th><label for="mcp-server-url"><?php echo esc_html__('URL', 'aiomatic-automatic-ai-content-writer'); ?></label></th>
365
+
<td><input type="text" id="mcp-server-url" class="regular-text" placeholder="Example: https://dmcp-server.deno.dev/sse" /></td>
366
+
</tr>
367
+
<tr>
368
+
<th><label for="mcp-server-token"><?php echo esc_html__('Token', 'aiomatic-automatic-ai-content-writer'); ?></label></th>
369
+
<td><input type="password" id="mcp-server-token" class="regular-text" placeholder="Bearer token for authentication (optional)" /></td>
370
+
</tr>
371
+
<tr>
372
+
<th><label for="mcp-server-global"><?php echo esc_html__('Enable Globally', 'aiomatic-automatic-ai-content-writer'); ?></label></th>
373
+
<td><input type="checkbox" id="mcp-server-global" /></td>
374
+
</tr>
375
+
</table>
376
+
<p>
377
+
<button type="button" class="button button-primary" onclick="unsaved = false;" id="save-mcp-server"><?php echo esc_html__('Save Server Connection', 'aiomatic-automatic-ai-content-writer'); ?></button>
378
+
<button type="button" class="button" id="cancel-mcp-server"><?php echo esc_html__('Cancel', 'aiomatic-automatic-ai-content-writer'); ?></button>
379
+
</p>
380
+
</div>
381
+
<?php else: ?>
382
+
<div style="margin:20px 0; padding:20px; border:1px solid #ccd0d4; border-radius:8px; background:#fff3cd; color:#856404;">
383
+
<strong><?php echo esc_html__('MCP Servers Disabled', 'aiomatic-automatic-ai-content-writer'); ?></strong>
384
+
<p><?php echo esc_html__('This functionality is only available when Aimogen is enabled, Responses API is turned on, the API selector is set to OpenAI, and you are not using an Aimogen API key. Please adjust your settings to enable MCP server connections. This will work in OpenAI models and also for Anthropic models.', 'aiomatic-automatic-ai-content-writer'); ?></p>
385
+
</div>
386
+
<?php endif; ?>
387
+
</div>
388
+
</div>
389
+
<script>
390
+
jQuery(document).ready(function($) {
391
+
function toggleMcpSse() {
392
+
if ($('input[name="aiomatic_mcp_settings[enable_sse]"]').is(':checked')) {
393
+
$('.mcp_sse').show();
394
+
} else {
395
+
$('.mcp_sse').hide();
396
+
}
397
+
}
398
+
399
+
toggleMcpSse();
400
+
401
+
$(document).on('change', 'input[name="aiomatic_mcp_settings[enable_sse]"]', function() {
402
+
toggleMcpSse();
403
+
});
404
+
});
405
+
(function(){
406
+
const tabs = document.querySelectorAll('.nav-tab-wrapper .nav-tab');
407
+
const contents = document.querySelectorAll('.tab-content');
408
+
tabs.forEach(tab => tab.addEventListener('click', function(e){
409
+
e.preventDefault();
410
+
tabs.forEach(t => t.classList.remove('nav-tab-active'));
411
+
this.classList.add('nav-tab-active');
412
+
contents.forEach(c => c.style.display = 'none');
413
+
const target = document.querySelector(this.getAttribute('href'));
414
+
if (target) target.style.display = 'block';
415
+
}));
416
+
const btn = document.getElementById('aiomatic-mcp-refresh');
417
+
if (btn) {
418
+
btn.addEventListener('click', async function(){
419
+
const pre = document.getElementById('aiomatic-mcp-functions');
420
+
const status = document.getElementById('aiomatic-mcp-refresh-status');
421
+
status.textContent = 'Loading...';
422
+
try {
423
+
const res = await fetch('<?php echo esc_js($tools_url); ?>', {
424
+
method: 'POST',
425
+
headers: {
426
+
'Content-Type': 'application/json',
427
+
'Authorization': 'Bearer <?php echo esc_js($bearer_token); ?>'
428
+
}
429
+
});
430
+
if (!res.ok) throw new Error("HTTP " + res.status);
431
+
const json = await res.json();
432
+
pre.textContent = JSON.stringify(json, null, 2);
433
+
status.textContent = 'Done';
434
+
} catch(e){
435
+
status.textContent = 'Error';
436
+
pre.textContent = e.message;
437
+
}
438
+
});
439
+
}
440
+
const addBtn = document.getElementById('add-mcp-server');
441
+
const form = document.getElementById('mcp-server-form');
442
+
const saveBtn = document.getElementById('save-mcp-server');
443
+
const cancelBtn = document.getElementById('cancel-mcp-server');
444
+
445
+
const idInput = document.getElementById('mcp-server-id');
446
+
const nameInput = document.getElementById('mcp-server-name');
447
+
const descInput = document.getElementById('mcp-server-description');
448
+
const description = descInput.value.trim();
449
+
const urlInput = document.getElementById('mcp-server-url');
450
+
const tokenInput = document.getElementById('mcp-server-token');
451
+
const enableGlobal = document.getElementById('mcp-server-global');
452
+
453
+
addBtn?.addEventListener('click', () => {
454
+
form.style.display = 'block';
455
+
idInput.value = '';
456
+
nameInput.value = '';
457
+
urlInput.value = '';
458
+
descInput.value = '';
459
+
tokenInput.value = '';
460
+
enableGlobal.checked = false;
461
+
});
462
+
463
+
cancelBtn?.addEventListener('click', () => {
464
+
form.style.display = 'none';
465
+
});
466
+
467
+
saveBtn?.addEventListener('click', async () => {
468
+
const name = nameInput.value.trim();
469
+
const url = urlInput.value.trim();
470
+
const token = tokenInput.value.trim();
471
+
const description = descInput.value.trim();
472
+
const id = idInput.value || 'srv-' + Math.random().toString(36).substr(2, 9);
473
+
const globalEnabled = enableGlobal.checked ? 'on' : 'off';
474
+
475
+
if (!name) {
476
+
alert('Please enter a server name.');
477
+
return;
478
+
}
479
+
if (!url) {
480
+
alert('Please enter a server URL.');
481
+
return;
482
+
}
483
+
if (!/^http.+/i.test(url)) {
484
+
alert('The URL must start with http');
485
+
return;
486
+
}
487
+
488
+
const data = {
489
+
action: 'aiomatic_save_mcp_server',
490
+
id: id,
491
+
name: name,
492
+
description: description,
493
+
url: url,
494
+
global: globalEnabled,
495
+
token: token,
496
+
_ajax_nonce: '<?php echo wp_create_nonce("aiomatic_mcp_nonce"); ?>'
497
+
};
498
+
499
+
try {
500
+
const res = await fetch(ajaxurl, {
501
+
method: 'POST',
502
+
body: new URLSearchParams(data)
503
+
});
504
+
const json = await res.json();
505
+
if (!json.success) {
506
+
alert('Error saving MCP server.');
507
+
} else {
508
+
location.reload();
509
+
}
510
+
} catch (e) {
511
+
alert('Request failed: ' + e.message);
512
+
}
513
+
});
514
+
515
+
document.querySelectorAll('.edit-mcp-server').forEach(btn =>
516
+
btn.addEventListener('click', e => {
517
+
const entry = e.target.closest('.mcp-server-entry');
518
+
idInput.value = entry.dataset.id;
519
+
nameInput.value = entry.querySelector('h4').textContent.trim();
520
+
const descrSpan = entry.querySelector('.descr');
521
+
descInput.value = descrSpan ? descrSpan.textContent.trim() : '';
522
+
523
+
const urlSpan = entry.querySelector('.srv-url');
524
+
urlInput.value = urlSpan ? urlSpan.textContent.trim() : '';
525
+
526
+
const tkn = entry.querySelector('.tkn');
527
+
tokenInput.value = tkn ? tkn.textContent.trim() : '';
528
+
529
+
const globalSpan = entry.querySelector('.srv-global');
530
+
enableGlobal.checked = globalSpan && globalSpan.textContent.trim() === 'on';
531
+
532
+
form.style.display = 'block';
533
+
})
534
+
);
535
+
536
+
document.querySelectorAll('.delete-mcp-server').forEach(btn => btn.addEventListener('click', async e => {
537
+
if (!confirm('Delete this server?')) return;
538
+
const entry = e.target.closest('.mcp-server-entry');
539
+
try {
540
+
const res = await fetch(ajaxurl, {
541
+
method: 'POST',
542
+
body: new URLSearchParams({
543
+
action: 'aiomatic_delete_mcp_server',
544
+
id: entry.dataset.id,
545
+
_ajax_nonce: '<?php echo wp_create_nonce("aiomatic_mcp_nonce"); ?>'
546
+
})
547
+
});
548
+
const json = await res.json();
549
+
if (json.success) {
550
+
location.reload();
551
+
} else {
552
+
alert('Error deleting server.');
553
+
}
554
+
} catch (e) {
555
+
alert('Delete failed: ' + e.message);
556
+
}
557
+
}));
558
+
559
+
})();
560
+
</script>
561
+
<?php
562
+
}
563
+
?>