/
home
/
altere25
/
.trash
/
wp-to-sanity-migration.10
/
/home/altere25/.trash/wp-to-sanity-migration.10
mkdir
upload
Name
Size
Mode
Actions
acf-json\.gitkeep
0
0644
edit
dl
rm
assets\css\admin.css
12113
0644
edit
dl
rm
assets\js\admin.js
52894
0644
edit
dl
rm
includes\class-ad-admin.php
10358
0644
edit
dl
rm
includes\class-ad-ai-client.php
10724
0644
edit
dl
rm
includes\class-ad-auth.php
9189
0644
edit
dl
rm
includes\class-ad-cli.php
8671
0644
edit
dl
rm
includes\class-ad-extractor.php
17237
0644
edit
dl
rm
includes\class-ad-mcp.php
6429
0644
edit
dl
rm
includes\class-ad-plugin-core.php
10252
0644
edit
dl
rm
includes\class-ad-progress.php
8022
0644
edit
dl
rm
includes\class-ad-rest.php
43443
0644
edit
dl
rm
includes\class-ad-uninstall.php
1966
0644
edit
dl
rm
includes\class-ad-webhook.php
24172
0644
edit
dl
rm
languages\.gitkeep
0
0644
edit
dl
rm
templates\admin\wizard.php
29414
0644
edit
dl
rm
wp-to-sanity-migration\acf-json\.gitkeep
0
0644
edit
dl
rm
wp-to-sanity-migration\assets\
0
0644
edit
dl
rm
wp-to-sanity-migration\assets\css\admin.css
12113
0644
edit
dl
rm
wp-to-sanity-migration\assets\js\admin.js
52894
0644
edit
dl
rm
wp-to-sanity-migration\includes\class-ad-admin.php
10358
0644
edit
dl
rm
wp-to-sanity-migration\includes\class-ad-ai-client.php
10724
0644
edit
dl
rm
wp-to-sanity-migration\includes\class-ad-auth.php
9189
0644
edit
dl
rm
wp-to-sanity-migration\includes\class-ad-cli.php
8671
0644
edit
dl
rm
wp-to-sanity-migration\includes\class-ad-extractor.php
17237
0644
edit
dl
rm
wp-to-sanity-migration\includes\class-ad-mcp.php
6429
0644
edit
dl
rm
wp-to-sanity-migration\includes\class-ad-plugin-core.php
10252
0644
edit
dl
rm
wp-to-sanity-migration\includes\class-ad-progress.php
8022
0644
edit
dl
rm
wp-to-sanity-migration\includes\class-ad-rest.php
43443
0644
edit
dl
rm
wp-to-sanity-migration\includes\class-ad-uninstall.php
1966
0644
edit
dl
rm
wp-to-sanity-migration\includes\class-ad-webhook.php
24172
0644
edit
dl
rm
wp-to-sanity-migration\languages\.gitkeep
0
0644
edit
dl
rm
wp-to-sanity-migration\package.json
220
0644
edit
dl
rm
wp-to-sanity-migration\readme.txt
8174
0644
edit
dl
rm
wp-to-sanity-migration\templates\
0
0644
edit
dl
rm
wp-to-sanity-migration\templates\admin\wizard.php
29414
0644
edit
dl
rm
wp-to-sanity-migration\uninstall.php
365
0644
edit
dl
rm
wp-to-sanity-migration\wp-to-sanity-migration.php
4418
0644
edit
dl
rm
Edit:
/home/altere25/.trash/wp-to-sanity-migration.10/includes\class-ad-mcp.php
(6429B)
<?php /** * Altered Digital Migration — Claude/MCP Hand-off (Phase D5) * * The single biggest user-friendliness lever for non-technical customers: * after migration, they can drive their migrated Sanity project through * Claude Desktop chat — "show me all posts without a featured image", "fix * the alt text on the homepage hero" — without touching Studio or GROQ. * * This class builds the per-customer MCP config by proxying to the Worker's * /v2/mcp/* routes. The Worker stores a SEPARATE, revocable Sanity token * (mcp_token) so the customer can revoke the Claude connection without * breaking in-flight migrations. * * Worker endpoints used: * POST /v2/mcp/token — store a customer-supplied MCP token, return config * GET /v2/mcp/config — return existing config (for re-visits) * POST /v2/mcp/revoke — clear the MCP token * * @package AlteredDigitalMigration */ if (!defined('ABSPATH')) { exit; } class AD_MCP { /** @var AD_Plugin_Core */ private $core; public function __construct(AD_Plugin_Core $core) { $this->core = $core; } /** * Mint (store) an MCP token. The customer creates a scoped read/write * token in Sanity Manage → API → Tokens and pastes it into the plugin; * we forward it to the Worker, which encrypts + stores it separately * from the migration write token and returns the Claude Desktop config * snippet + deep-link + starter prompts. * * @return array {success, data} envelope */ public function mint_token(string $mcp_token): array { $service_url = $this->core->setting('service_url', ''); $admin_token = $this->core->setting('admin_token', ''); $tenant_id = $this->core->setting('tenant_id', ''); if (empty($service_url) || empty($admin_token) || empty($tenant_id)) { return ['success' => false, 'data' => ['error' => 'not_configured', 'message' => 'Connect to the Altered Digital service first.']]; } if (empty($mcp_token)) { return ['success' => false, 'data' => ['error' => 'mcp_token_required']]; } $endpoint = rtrim($service_url, '/') . '/v2/mcp/token'; $response = wp_remote_post($endpoint, [ 'timeout' => 20, 'headers' => [ 'Content-Type' => 'application/json', 'Authorization' => 'Bearer ' . $admin_token, 'X-AD-Tenant' => $tenant_id, ], 'body' => wp_json_encode(['mcp_token' => $mcp_token]), ]); return $this->envelope($response, 'mint_token'); } /** * Fetch the existing MCP config for re-visits. Returns the same shape as * mint_token() minus the token-creation step. When the tenant has no * stored MCP token yet, returns success=false with error=mcp_token_not_set * so the plugin UI can prompt the customer to mint one. * * @return array {success, data} envelope */ public function fetch_config(): array { $service_url = $this->core->setting('service_url', ''); $admin_token = $this->core->setting('admin_token', ''); $tenant_id = $this->core->setting('tenant_id', ''); if (empty($service_url) || empty($admin_token) || empty($tenant_id)) { return ['success' => false, 'data' => ['error' => 'not_configured', 'message' => 'Connect to the Altered Digital service first.']]; } $endpoint = rtrim($service_url, '/') . '/v2/mcp/config?tenant_id=' . rawurlencode($tenant_id); $response = wp_remote_get($endpoint, [ 'timeout' => 15, 'headers' => [ 'Authorization' => 'Bearer ' . $admin_token, 'X-AD-Tenant' => $tenant_id, ], ]); return $this->envelope($response, 'fetch_config'); } /** * Revoke the MCP token (clears the Claude connection without touching * the migration write token). * * @return array {success, data} envelope */ public function revoke(): array { $service_url = $this->core->setting('service_url', ''); $admin_token = $this->core->setting('admin_token', ''); $tenant_id = $this->core->setting('tenant_id', ''); if (empty($service_url) || empty($admin_token) || empty($tenant_id)) { return ['success' => false, 'data' => ['error' => 'not_configured']]; } $endpoint = rtrim($service_url, '/') . '/v2/mcp/revoke'; $response = wp_remote_post($endpoint, [ 'timeout' => 15, 'headers' => [ 'Content-Type' => 'application/json', 'Authorization' => 'Bearer ' . $admin_token, 'X-AD-Tenant' => $tenant_id, ], 'body' => wp_json_encode([]), ]); return $this->envelope($response, 'revoke'); } // ----------------------------------------------------------------- // Helpers // ----------------------------------------------------------------- /** * Normalize a wp_remote_* response into the {success, data} envelope the * REST handlers return. Worker errors are surfaced as success=false with * the Worker's error string preserved. */ private function envelope($response, string $op): array { if (is_wp_error($response)) { return ['success' => false, 'data' => ['error' => $response->get_error_message(), 'op' => $op]]; } $code = wp_remote_retrieve_response_code($response); $decoded = json_decode(wp_remote_retrieve_body($response), true); if (!is_array($decoded)) { return ['success' => false, 'data' => ['error' => 'Worker returned ' . intval($code) . ' (invalid JSON)', 'op' => $op]]; } // 404 from GET /config when no token is set is a known state, not a // hard error — pass it through so the UI can prompt to mint. if ($code === 404) { return ['success' => false, 'data' => array_merge($decoded, ['op' => $op])]; } if ($code < 200 || $code >= 300) { $err = !empty($decoded['error']) ? $decoded['error'] : 'Worker returned ' . intval($code); return ['success' => false, 'data' => array_merge($decoded, ['error' => $err, 'op' => $op])]; } return ['success' => true, 'data' => $decoded]; } }
Save
cmd:
run