← Files thinkcellARCHIVED FILE

scripts/installation-help.ps1

6.86 KB · Nov 30, 2026 · 15:10 UTC

↓ Download file

param(
    [ValidateSet('thinkcell_not_found', 'mcp_executable_missing', 'installation_incomplete')]
    [string]$Reason = 'thinkcell_not_found'
)

$ErrorActionPreference = 'Stop'
[Console]::InputEncoding = New-Object System.Text.UTF8Encoding($false)
[Console]::OutputEncoding = New-Object System.Text.UTF8Encoding($false)
$resourceUri = 'ui://thinkcell-charts/installation-help/v4.html'
$restartNote = 'After installing or updating thinkcell, restart the plugin connection and try your chart request again.'

switch ($Reason) {
    'thinkcell_not_found' {
        $title = 'Create thinkcell charts in PowerPoint'
        $message = 'Install thinkcell for PowerPoint to build thinkcell charts.'
        $actionLabel = 'Download thinkcell'
        $website = 'https://server.thinkcell.com/portal/en/trial.srf'
    }
    'mcp_executable_missing' {
        $title = 'Update thinkcell to connect'
        $message = 'Your current thinkcell version isn''t compatible. You can download the latest version here, or ask your IT team to update it.'
        $actionLabel = 'Download thinkcell'
        $website = 'https://www.thinkcell.com/download'
    }
    'installation_incomplete' {
        $title = 'Restore your thinkcell installation'
        $message = 'We found a thinkcell registration, but we couldn''t locate the installed software. Download thinkcell here to reinstall, or ask your IT team for help.'
        $actionLabel = 'Download thinkcell'
        $website = 'https://www.thinkcell.com/download'
    }
}

$state = @{ status = $Reason; title = $title; message = $message; actionLabel = $actionLabel; website = $website; restartNote = $restartNote }
$pluginRoot = Split-Path -Parent $PSScriptRoot
$template = [IO.File]::ReadAllText((Join-Path $pluginRoot 'ui\installation-help.html'))
$banner = [Convert]::ToBase64String([IO.File]::ReadAllBytes((Join-Path $pluginRoot 'assets\thinkcell.png')))
$html = $template.Replace('__THINKCELL_BANNER__', ('data:image/png;base64,' + $banner))
foreach ($key in @('title', 'message', 'actionLabel', 'website', 'restartNote')) {
    $html = $html.Replace(('__' + $key.ToUpperInvariant() + '__'), [System.Net.WebUtility]::HtmlEncode($state[$key]))
}

$tool = @{
    name = 'show_installation_help'
    title = 'Get thinkcell'
    description = 'Shows installation help when thinkcell or its chart connection component is unavailable. Returns a friendly setup card and the same instructions as text. This tool does not install software or create charts.'
    inputSchema = @{ type = 'object'; properties = @{}; additionalProperties = $false }
    annotations = @{ readOnlyHint = $true; destructiveHint = $false; idempotentHint = $true; openWorldHint = $false }
    _meta = @{ ui = @{ resourceUri = $resourceUri }; 'openai/outputTemplate' = $resourceUri }
}

function Write-RpcResult($requestId, $result) {
    [Console]::Out.WriteLine((@{ jsonrpc = '2.0'; id = $requestId; result = $result } | ConvertTo-Json -Depth 30 -Compress))
}

function Write-RpcError($requestId, [int]$code, [string]$message) {
    [Console]::Out.WriteLine((@{ jsonrpc = '2.0'; id = $requestId; error = @{ code = $code; message = $message } } | ConvertTo-Json -Depth 10 -Compress))
}

while ($null -ne ($line = [Console]::In.ReadLine())) {
    if ([string]::IsNullOrWhiteSpace($line)) { continue }
    try { $request = ConvertFrom-Json -InputObject $line -ErrorAction Stop }
    catch { Write-RpcError $null -32700 'Invalid JSON'; continue }
    if ($request.jsonrpc -ne '2.0' -or -not ($request.method -is [string])) {
        Write-RpcError $null -32600 'Invalid JSON-RPC request'
        continue
    }
    # JSON-RPC notifications have no response, including notifications/initialized.
    if (-not ($request.PSObject.Properties.Name -contains 'id') -or $null -eq $request.id) { continue }
    try {
        switch ($request.method) {
            'initialize' {
                $protocol = $request.params.protocolVersion
                if ($protocol -notin @('2025-11-25', '2025-06-18', '2025-03-26', '2024-11-05')) { $protocol = '2025-11-25' }
                Write-RpcResult $request.id @{
                    protocolVersion = $protocol
                    capabilities = @{ tools = @{ listChanged = $false }; resources = @{ subscribe = $false; listChanged = $false } }
                    serverInfo = @{ name = 'thinkcell installation help'; version = '0.1.4' }
                    instructions = 'Chart creation is unavailable until thinkcell setup is complete. Call show_installation_help to show the setup card and provide its text instructions and website link to the user.'
                }
            }
            'ping' { Write-RpcResult $request.id @{} }
            'tools/list' { Write-RpcResult $request.id @{ tools = @($tool) } }
            'tools/call' {
                if ($request.params.name -ne $tool.name) { Write-RpcError $request.id -32602 'Unknown tool'; break }
                if ($null -ne $request.params.arguments -and @($request.params.arguments.PSObject.Properties).Count -gt 0) {
                    Write-RpcError $request.id -32602 'This tool takes no arguments'
                    break
                }
                Write-RpcResult $request.id @{
                    isError = $false
                    structuredContent = $state
                    content = @(@{ type = 'text'; text = "$title. $message $actionLabel`: $website $restartNote" })
                }
            }
            'resources/list' {
                Write-RpcResult $request.id @{ resources = @(@{ uri = $resourceUri; name = 'thinkcell-installation-help'; title = 'Set up thinkcell'; mimeType = 'text/html;profile=mcp-app' }) }
            }
            'resources/templates/list' { Write-RpcResult $request.id @{ resourceTemplates = @() } }
            'resources/read' {
                if ($request.params.uri -ne $resourceUri) { Write-RpcError $request.id -32002 'Resource not found'; break }
                Write-RpcResult $request.id @{
                    contents = @(@{
                        uri = $resourceUri; mimeType = 'text/html;profile=mcp-app'; text = $html
                        _meta = @{
                            ui = @{ prefersBorder = $true; csp = @{ connectDomains = @(); resourceDomains = @() } }
                            'openai/ui' = @{ availableDisplayModes = @('inline'); preferredDisplayMode = 'inline' }
                            'openai/widgetCSP' = @{ connect_domains = @(); resource_domains = @(); redirect_domains = @('https://www.thinkcell.com', 'https://www.think-cell.com') }
                        }
                    })
                }
            }
            default { Write-RpcError $request.id -32601 'Method not found' }
        }
    } catch {
        [Console]::Error.WriteLine($_.Exception.Message)
        Write-RpcError $request.id -32603 'Installation help could not be returned'
    }
}
exit 0

SHA-256: a6febdb38d56308cb38529bf3ffc59e693e77de009ab559d0d08f871cb8f5e9f