困惑XPC-Windows集成帮助程序
一个本地AI代理,通过后台服务、系统托盘应用程序、资源管理器上下文菜单和MCP(模型上下文协议)服务器管理将Perplexity AI集成到Windows中。
PerplexyXPC运行一个Windows服务,该服务仅绑定到 127.0.0.1:47777,代理对困惑声纳API的请求,管理MCP服务器进程,并公开REST/WebSocket API供托盘应用程序、上下文菜单、PowerShell模块、脚本和任何其他本地工具使用。您的API密钥在休息时使用DPAPI加密,并且从不通过任何HTTP端点公开。
______________________________________________________________________
目录
- 热键和托盘应用程序 - HTTP API - PowerShell模块 - 上下文菜单 - MCP服务器
______________________________________________________________________
建筑
+---------------------------------------------------------------------+
| PerplexityXPC |
| |
| +------------------+ Named Pipe +--------------------------+ |
| | System Tray App | | Windows Service | |
| | (Ctrl+Shift+A) | | (PerplexityXPC) | |
| +------------------+ | | |
| | HTTP: 127.0.0.1:47777 | |
| +------------------+ HTTP/SSE | WS: ws://127.0.0.1: | |
| | Context Menu | | 47777/ws | |
| | (Right-click) | | | |
| +------------------+ | +--------------------+ | |
| | | Perplexity API | | |
| +------------------+ HTTP/SSE | | Proxy | | |
| | PowerShell / | | | | | |
| | curl / scripts | | | sonar | | |
| +------------------+ | | sonar-pro | | |
| | | sonar-reasoning | | |
| | | sonar-deep-research| | |
| | +--------------------+ | |
| | | |
| | +--------------------+ | |
| | | MCP Server Manager | | |
| | | | | |
| | | filesystem | | |
| | | github | | |
| | | brave-search | | |
| | | memory | | |
| | | sqlite | | |
| | | (custom...) | | |
| | +--------------------+ | |
| +--------------------------+ |
+---------------------------------------------------------------------+______________________________________________________________________
特性
- Windows服务代理 -Kestrel HTTP/WebSocket服务器绑定到
127.0.0.1:47777仅 - 系统托盘应用程序 -
Ctrl+Shift+A浮动查询弹出窗口的全局热键 - 资源管理器上下文菜单 -右键单击任何文本文件或文件夹将其发送到困惑
- MCP服务器管理器 -通过stdio上的JSON-RPC 2.0启动、停止和重新启动MCP服务器
- 困惑声纳代理 -支持所有四种声纳型号,具有全参数传递功能
- SSE流媒体 -通过服务器发送事件进行实时令牌流式传输
- WebSocket接口 -流式响应的持久连接
- PowerShell模块 -14个功能,涵盖查询、文件分析、批处理研究和IT集成
- DPAPI加密密钥存储 -API密钥在机器+用户范围内加密;从未通过HTTP公开
- 命名管道IPC -每个用户ACL通过
PipeAccessRule用于安全的进程间通信 - PowerShell安装程序 -与PS 5.1和PS 7兼容的单脚本安装/卸载+
- 防火墙规则 -阻止外部访问端口47777的自动规则
- 黑暗/光明主题 -托盘弹出窗口适应Windows系统主题
- Atera和Intune集成 -用于IT管理工作流的专用PowerShell功能
- 批量查询和报告生成 -研究多个主题并编写结构化报告
- 自包含的可执行文件 -没有。目标计算机上需要.NET运行时
______________________________________________________________________
先决条件
| 要求 | 注意事项 |
|---|---|
| Windows 10内部版本1809+ 或Windows 11 | 必需 |
| .NET 8 SDK(x64) | 下载 -只建造;编译的EXE是自包含的 |
| Node.js LTS(x64) | 下载 -MCP服务器在运行时需要通过 npx |
| 困惑API键 | 在此处生成 -格式: pplx-... |
| 管理员权限 | 安装程序需要(服务注册、防火墙、上下文菜单) |
______________________________________________________________________
快速开始
1.建造
cd PerplexityXPC
.\scripts\Build-PerplexityXPC.ps1构建脚本将所有三个项目编译为 bin\ 作为自包含的单文件可执行文件。
常见的构建错误:
# Missing NuGet source
dotnet nuget add source https://api.nuget.org/v3/index.json --name nuget.org
# Execution policy
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned2.安装
# Interactive - prompts for API key
.\scripts\Install-PerplexityXPC.ps1
# Pre-supply API key
.\scripts\Install-PerplexityXPC.ps1 -ApiKey "pplx-"
# Custom install path
.\scripts\Install-PerplexityXPC.ps1 -InstallPath "D:\Apps\PerplexityXPC"
# Quiet install (CI/RMM)
.\scripts\Install-PerplexityXPC.ps1 -ApiKey "pplx-" -Quiet安装程序:
- 将二进制文件复制到
C:\Program Files\PerplexityXPC\ - 在以下位置创建配置
%LOCALAPPDATA%\PerplexityXPC\ - 注册并启动Windows服务
- 为端口47777添加Windows防火墙入站阻止规则
- 注册资源管理器上下文菜单项
- 将托盘应用程序添加到Windows启动中
- 通过DPAPI加密您的API密钥
3.验证
# Check service is running
Get-Service PerplexityXPC
# Test the HTTP endpoint
Invoke-RestMethod http://localhost:47777/status
# Send a test query
Invoke-RestMethod http://localhost:47777/perplexity -Method Post `
-ContentType 'application/json' `
-Body '{"model":"sonar","messages":[{"role":"user","content":"Hello!"}]}'______________________________________________________________________
用法
热键和托盘应用程序
按 Ctrl+Shift+A 从Windows中的任何位置打开浮动查询弹出窗口。
系统托盘图标显示服务运行状况:
- 绿色 -服务正在运行,已配置API密钥
- 黄色 -服务正在运行,没有API密钥或已降级
- 红 -无法访问服务
右键单击托盘图标以:
- 打开查询弹出窗口
- 查看并重新启动MCP服务器
- 打开设置
- 控制服务(启动/停止/重新启动)
- 退出托盘应用程序
HTTP API
所有端点均可在 http://127.0.0.1:47777。参见 docs/API.md文件 用于完整的请求/响应模式。
| 方法 | 路径 | 描述 |
|---|---|---|
POST | /perplexity | 将聊天请求代理到困惑声纳API |
POST | /perplexity/stream | SSE流媒体代理-返回 text/event-stream |
GET | /status | 服务运行状况、版本、正常运行时间、MCP服务器列表 |
POST | /mcp | 向指定的MCP服务器发送JSON-RPC 2.0请求 |
GET | /mcp/servers | 列出所有已注册的MCP服务器及其状态 |
POST | /mcp/servers/{name}/restart | 按名称重新启动特定的MCP服务器 |
GET | /config | 读取非敏感代理配置 |
PUT | /config | 在运行时更新代理配置 |
WS | /ws | 用于流式响应的WebSocket连接 |
快速示例:
# Query Perplexity
$body = @{
model = 'sonar-pro'
messages = @(@{ role = 'user'; content = 'What is VLAN trunking?' })
} | ConvertTo-Json
Invoke-RestMethod http://localhost:47777/perplexity -Method Post -ContentType 'application/json' -Body $body
# Check status
Invoke-RestMethod http://localhost:47777/status
# List MCP servers
Invoke-RestMethod http://localhost:47777/mcp/servers
# Restart an MCP server
Invoke-RestMethod http://localhost:47777/mcp/servers/filesystem/restart -Method Post# curl
curl -s -X POST http://127.0.0.1:47777/perplexity \
-H "Content-Type: application/json" \
-d '{"model":"sonar","messages":[{"role":"user","content":"What is BGP?"}]}'PowerShell模块
安装并导入:
# Install to user module path
$dest = "$env:USERPROFILE\Documents\PowerShell\Modules\PerplexityXPC"
Copy-Item -Path ".\module\PerplexityXPC" -Destination $dest -Recurse
Import-Module PerplexityXPC
# Basic usage
Invoke-Perplexity 'What is zero trust networking?'
Get-XPCStatus
Get-McpServer看 docs/MODULE.md 以获取完整的函数参考,包括参数表和示例。
可用功能:
| 类别 | 功能 |
|---|---|
| 核心 | Invoke-Perplexity, Get-XPCStatus, Get-XPCConfig, Set-XPCConfig |
| MCP管理 | Get-McpServer, Restart-McpServer, Invoke-McpRequest |
| 文件分析 | Invoke-PerplexityFileAnalysis, Invoke-PerplexityFolderAnalysis |
| 批量研究 | Invoke-PerplexityBatch, Invoke-PerplexityReport |
| IT集成 | Invoke-PerplexityTicketAnalysis, Invoke-PerplexityDeviceAnalysis, Invoke-PerplexitySecurityAnalysis |
上下文菜单
在Windows资源管理器中右键单击任何基于文本的文件或文件夹:
- “询问有关此文件的困惑” -读取文件内容(不超过配置的大小限制),并打开预装有分析查询的托盘弹出窗口
- “询问有关此文件夹的困惑” -发送目录列表并要求进行结构分析
上下文菜单按用户注册 HKCU\Software\Classes.使用 .\scripts\Register-ContextMenu.ps1 如果更新后条目消失,则重新注册。
MCP服务器
MCP(模型上下文协议)服务器扩展了对本地文件、GitHub、网络搜索、SQLite数据库等的访问。
配置文件: %LOCALAPPDATA%\PerplexityXPC\mcp-servers.json
{
"mcpServers": {
"filesystem": {
"disabled": false,
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "C:\\Users\\YourUsername\\Documents"],
"env": {}
},
"github": {
"disabled": false,
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": ""
}
},
"brave-search": {
"disabled": false,
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-brave-search"],
"env": {
"BRAVE_API_KEY": ""
}
}
}
}复制 config\mcp-servers.template.json 作为一个起点。集 "disabled": false 以激活服务器。服务器通过Windows服务自动启动。
通过PowerShell进行管理:
# List all servers
Get-McpServer
# Restart one
Restart-McpServer -Name 'filesystem'
# Send a request
Invoke-McpRequest -Server 'filesystem' -Method 'tools/list'
Invoke-McpRequest -Server 'filesystem' -Method 'tools/call' -Params @{
name = 'read_file'
arguments = @{ path = 'C:\Users\YourUsername\Documents\notes.txt' }
}______________________________________________________________________
配置
应用程序参数
位于 %LOCALAPPDATA%\PerplexityXPC\appsettings.json 安装后。模板位于 config\appsettings.template.json.
| 密钥 | 默认值 | 描述 |
|---|---|---|
PerplexityXPC.ApiEndpoint | https://api.perplexity.ai | 困惑API基础URL |
PerplexityXPC.HttpPort | 47777 | 本地HTTP端口 |
PerplexityXPC.PipeServerName | PerplexityXPCPipe | 命名管道服务器名称 |
PerplexityXPC.LogLevel | Information | 日志记录级别(跟踪/调试/信息/警告/错误) |
PerplexityXPC.DefaultModel | sonar | 默认声纳型号 |
PerplexityXPC.ApiTimeoutSec | 60 | API调用超时(秒) |
PerplexityXPC.MaxTokens | 2048 | 默认每个响应的最大令牌数 |
PerplexityXPC.MaxFileSizeKB | 10240 | 上下文菜单读取的最大文件大小 |
Mcp.AutoRestart | true | 自动重启导致MCP进程崩溃 |
Mcp.TimeoutSec | 30 | MCP请求超时 |
Mcp.MaxConcurrentServers | 5 | 最大同时MCP进程数 |
mcp-servers.json
位于 %LOCALAPPDATA%\PerplexityXPC\mcp-servers.json.下的每个条目 mcpServers 定义一个MCP服务器:
| 字段 | 类型 | 描述 |
|---|---|---|
disabled | boolean | 设置为 true 从自动启动中排除 |
description | string | 人类可读的描述(可选) |
command | string | 可执行文件(例如。, npx, node) |
args | array | 传递给命令的参数 |
env | object | 注入进程的环境变量 |
环境变量
| 变量 | 描述 |
|---|---|
PERPLEXITYXPC_DEBUG | 设置为 1 启用详细调试日志记录 |
PERPLEXITYXPC_PORT | 覆盖HTTP端口(默认值:47777) |
______________________________________________________________________
安全
- 红隼与
127.0.0.1仅 -无法从网络层的其他计算机访问该服务 - Windows防火墙规则 -端口47777上的入站阻止规则提供了对环回旁路技术的深度防御
- 命名管道ACL -IPC管道通过以下方式限制为当前用户SID
PipeAccessRule;其他用户或服务无法连接 - DPAPI加密 -API密钥使用加密
ProtectedData.Protect使用DataProtectionScope.CurrentUser和LocalMachine熵;纯文本密钥仅在API调用期间存在于内存中 - HTTP响应中没有API密钥 -The
/config端点故意省略API密钥;无法通过HTTP检索 - 运行时不需要管理员 -Windows服务作为LocalService运行;仅在安装过程中需要管理员权限
______________________________________________________________________
故障排除
服务未启动
# Check Windows Event Log for errors
Get-EventLog -LogName System -Source PerplexityXPC -Newest 20
# Check service status
Get-Service PerplexityXPC | Select-Object Status, StartType
# Try starting manually and watching output
Start-Service PerplexityXPC
Get-Content "$env:LOCALAPPDATA\PerplexityXPC\logs\service-*.log" -Tail 30API密钥不被接受
# Re-run the installer to re-encrypt the key
.\scripts\Install-PerplexityXPC.ps1 -ApiKey "pplx-"
# Verify the key file exists
Test-Path "$env:LOCALAPPDATA\PerplexityXPC\api-key.enc"47777端口已在使用中
# Find the conflicting process
netstat -ano | findstr :47777
# Change the port in appsettings.json
# Then restart the service
Restart-Service PerplexityXPCMCP服务器未启动
# Check Node.js is installed
node --version
npx --version
# Test an MCP server manually
npx -y @modelcontextprotocol/server-filesystem "C:\Users\YourUsername\Documents"
# Check MCP logs
Get-Content "$env:LOCALAPPDATA\PerplexityXPC\logs\service-*.log" -Tail 50 | Select-String "MCP"缺少上下文菜单项
# Re-register context menu
.\scripts\Register-ContextMenu.ps1
# Or check the registry directly
Get-Item "HKCU:\Software\Classes\*\shell\PerplexityXPC"执行策略错误
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSignedASR(攻击面减少)阻止安装程序
如果Windows Defender ASR规则阻止PowerShell脚本执行,请暂时禁用相关ASR规则或使用已签名的脚本。看 docs/INSTALL.md 了解详情。
启用调试日志
[Environment]::SetEnvironmentVariable("PERPLEXITYXPC_DEBUG", "1", "Machine")
Restart-Service PerplexityXPC
Get-Content "$env:LOCALAPPDATA\PerplexityXPC\logs\service-*.log" -Tail 50 -Wait______________________________________________________________________
项目结构
PerplexityXPC/
+-- PerplexityXPC.sln
+-- README.md
+-- CHANGELOG.md
+-- LICENSE
+-- .gitignore
+-- config/
| +-- appsettings.template.json
| +-- mcp-servers.template.json
+-- docs/
| +-- INSTALL.md
| +-- MODULE.md
| +-- API.md
+-- module/
| +-- PerplexityXPC/
| +-- PerplexityXPC.psd1
| +-- PerplexityXPC.psm1
+-- scripts/
| +-- Build-PerplexityXPC.ps1
| +-- Install-PerplexityXPC.ps1
| +-- Uninstall-PerplexityXPC.ps1
| +-- Register-ContextMenu.ps1
+-- src/
+-- PerplexityXPC.Service/
| +-- Configuration/
| | +-- AppConfig.cs
| +-- Models/
| | +-- ChatRequest.cs
| | +-- ChatResponse.cs
| | +-- McpServerConfig.cs
| | +-- McpServerInfo.cs
| +-- Services/
| | +-- HttpBroker.cs
| | +-- McpServerManager.cs
| | +-- NamedPipeServer.cs
| | +-- PerplexityApiClient.cs
| +-- Program.cs
| +-- appsettings.json
+-- PerplexityXPC.Tray/
| +-- Forms/
| | +-- QueryPopup.cs
| | +-- SettingsForm.cs
| +-- Helpers/
| | +-- HotkeyManager.cs
| | +-- StartupManager.cs
| | +-- ThemeManager.cs
| +-- Services/
| | +-- ServiceClient.cs
| +-- TrayApplicationContext.cs
| +-- Program.cs
| +-- Properties/Settings.cs
+-- PerplexityXPC.ContextMenu/
+-- ContextMenuHandler.cs
+-- app.manifest______________________________________________________________________
贡献
- 分叉存储库
- 创建要素分支:
git checkout -b feature/my-feature - 进行更改并确保不包含个人信息
- 在Windows 10/11上使用PowerShell 5.1和PowerShell 7进行测试
- 提交拉取请求
规范标准:
- C#代码遵循标准。NET命名约定
- PowerShell遵循Verb Noun函数命名标准
- 任何文档中都没有em破折号-仅使用连字符
- 在PowerShell中,所有具有用户可见文本的字符串都应使用单引号
- 错误处理必须使用
try/catch带有描述性Write-Error消息
______________________________________________________________________
相关项目
- 困惑窗口xpc --Windows的困惑AI——PowerShell、系统托盘、Office集成
- 困惑连接器 -困惑声纳API连接器-CLI,流式,异步,结构化输出
- atera仪表板 --Atera RMM NOC仪表板——React+Vite+Tailwind+Recharts
- atera连接器 -Atera RMM API v3连接器-Python CLI,完全支持CRUD
- 滑膜连接器 -Synology DSM Web API连接器-10个模块中的40个CLI操作
- udm-nspawn pki --UniFi Dream Machine Pro系统中的两层PKI
- wireguard vpn spk --Synology DS220+的WireGuard VPN隧道SPK(用户空间WireGuard去)
- nas git同步 --自动GitHub到Synology NAS仓库同步脚本
作者
布莱恩·维森特 --网络协调员和网络安全管理员
建于 困惑计算机
许可证
MIT许可证-请参阅 许可证 了解详情。
______________________________________________________________________
致谢
- 困惑AI 用于Sonar API和支持此集成的型号
- .NET 8 用于跨平台运行时和自包含的可执行文件支持
- WPF(Windows演示文稿基础) 用于托盘应用程序UI框架
- Serilog 用于结构化滚动文件诊断日志记录
- 模型上下文协议 用于实现本地工具与AI模型集成的开放标准
