perplexity-web-mcp-cli 0.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. perplexity_web_mcp_cli-0.5.0/PKG-INFO +439 -0
  2. perplexity_web_mcp_cli-0.5.0/README.md +399 -0
  3. perplexity_web_mcp_cli-0.5.0/pyproject.toml +126 -0
  4. perplexity_web_mcp_cli-0.5.0/src/perplexity_web_mcp/__init__.py +58 -0
  5. perplexity_web_mcp_cli-0.5.0/src/perplexity_web_mcp/api/__init__.py +12 -0
  6. perplexity_web_mcp_cli-0.5.0/src/perplexity_web_mcp/api/server.py +1304 -0
  7. perplexity_web_mcp_cli-0.5.0/src/perplexity_web_mcp/api/session_manager.py +423 -0
  8. perplexity_web_mcp_cli-0.5.0/src/perplexity_web_mcp/api/tool_calling.py +367 -0
  9. perplexity_web_mcp_cli-0.5.0/src/perplexity_web_mcp/cli/__init__.py +6 -0
  10. perplexity_web_mcp_cli-0.5.0/src/perplexity_web_mcp/cli/ai_doc.py +227 -0
  11. perplexity_web_mcp_cli-0.5.0/src/perplexity_web_mcp/cli/auth.py +406 -0
  12. perplexity_web_mcp_cli-0.5.0/src/perplexity_web_mcp/cli/doctor.py +140 -0
  13. perplexity_web_mcp_cli-0.5.0/src/perplexity_web_mcp/cli/main.py +319 -0
  14. perplexity_web_mcp_cli-0.5.0/src/perplexity_web_mcp/cli/setup.py +255 -0
  15. perplexity_web_mcp_cli-0.5.0/src/perplexity_web_mcp/cli/skill.py +286 -0
  16. perplexity_web_mcp_cli-0.5.0/src/perplexity_web_mcp/config.py +51 -0
  17. perplexity_web_mcp_cli-0.5.0/src/perplexity_web_mcp/constants.py +52 -0
  18. perplexity_web_mcp_cli-0.5.0/src/perplexity_web_mcp/core.py +566 -0
  19. perplexity_web_mcp_cli-0.5.0/src/perplexity_web_mcp/data/SKILL.md +202 -0
  20. perplexity_web_mcp_cli-0.5.0/src/perplexity_web_mcp/data/references/api-endpoints.md +118 -0
  21. perplexity_web_mcp_cli-0.5.0/src/perplexity_web_mcp/data/references/mcp-tools.md +147 -0
  22. perplexity_web_mcp_cli-0.5.0/src/perplexity_web_mcp/data/references/models.md +79 -0
  23. perplexity_web_mcp_cli-0.5.0/src/perplexity_web_mcp/enums.py +85 -0
  24. perplexity_web_mcp_cli-0.5.0/src/perplexity_web_mcp/exceptions.py +105 -0
  25. perplexity_web_mcp_cli-0.5.0/src/perplexity_web_mcp/http.py +273 -0
  26. perplexity_web_mcp_cli-0.5.0/src/perplexity_web_mcp/limits.py +15 -0
  27. perplexity_web_mcp_cli-0.5.0/src/perplexity_web_mcp/logging.py +121 -0
  28. perplexity_web_mcp_cli-0.5.0/src/perplexity_web_mcp/mcp/__init__.py +14 -0
  29. perplexity_web_mcp_cli-0.5.0/src/perplexity_web_mcp/mcp/__main__.py +9 -0
  30. perplexity_web_mcp_cli-0.5.0/src/perplexity_web_mcp/mcp/server.py +418 -0
  31. perplexity_web_mcp_cli-0.5.0/src/perplexity_web_mcp/models.py +65 -0
  32. perplexity_web_mcp_cli-0.5.0/src/perplexity_web_mcp/py.typed +0 -0
  33. perplexity_web_mcp_cli-0.5.0/src/perplexity_web_mcp/rate_limits.py +352 -0
  34. perplexity_web_mcp_cli-0.5.0/src/perplexity_web_mcp/resilience.py +101 -0
  35. perplexity_web_mcp_cli-0.5.0/src/perplexity_web_mcp/shared.py +282 -0
  36. perplexity_web_mcp_cli-0.5.0/src/perplexity_web_mcp/token_store.py +80 -0
  37. perplexity_web_mcp_cli-0.5.0/src/perplexity_web_mcp/types.py +49 -0
@@ -0,0 +1,439 @@
1
+ Metadata-Version: 2.4
2
+ Name: perplexity-web-mcp-cli
3
+ Version: 0.5.0
4
+ Summary: CLI, MCP server, and Anthropic/OpenAI API-compatible interface for Perplexity AI.
5
+ Keywords: perplexity,ai,mcp,anthropic,api,client
6
+ Author: Jacob Ben David
7
+ License-Expression: MIT
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Topic :: Internet :: WWW/HTTP
18
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
+ Classifier: Typing :: Typed
20
+ Requires-Dist: curl-cffi>=0.14.0,<1.0
21
+ Requires-Dist: loguru>=0.7.3,<1.0
22
+ Requires-Dist: orjson>=3.11.6,<4.0
23
+ Requires-Dist: pydantic>=2.12.5,<3.0
24
+ Requires-Dist: tenacity>=9.1.2,<10.0
25
+ Requires-Dist: python-dotenv>=1.0.0,<2.0
26
+ Requires-Dist: rich>=13.0.0,<15.0
27
+ Requires-Dist: perplexity-web-mcp-cli[mcp,api] ; extra == 'all'
28
+ Requires-Dist: fastapi>=0.115.0,<1.0 ; extra == 'api'
29
+ Requires-Dist: uvicorn>=0.30.0,<1.0 ; extra == 'api'
30
+ Requires-Dist: httpx>=0.27.0,<1.0 ; extra == 'api'
31
+ Requires-Dist: fastmcp>=2.14.4,<3.0 ; extra == 'mcp'
32
+ Requires-Python: >=3.10, <3.14
33
+ Project-URL: Homepage, https://github.com/jacob-bd/perplexity-web-mcp
34
+ Project-URL: Repository, https://github.com/jacob-bd/perplexity-web-mcp.git
35
+ Project-URL: Issues, https://github.com/jacob-bd/perplexity-web-mcp/issues
36
+ Provides-Extra: all
37
+ Provides-Extra: api
38
+ Provides-Extra: mcp
39
+ Description-Content-Type: text/markdown
40
+
41
+ <p align="center">
42
+ <img src="assets/logo.png" alt="Perplexity Web MCP" width="700">
43
+ </p>
44
+
45
+ # Perplexity Web MCP
46
+
47
+ MCP server, CLI, and API-compatible interface for Perplexity AI's web interface.
48
+
49
+ Use your Perplexity Pro/Max subscription to access premium models (GPT-5.2, Claude 4.6 Opus, Claude 4.5 Sonnet, Gemini 3, Grok 4.1, Kimi K2.5) from the terminal, through MCP tools, or as an API endpoint.
50
+
51
+ ## Features
52
+
53
+ - **CLI**: Query Perplexity models directly from the terminal (`pwm ask`, `pwm research`)
54
+ - **MCP Server**: 17 MCP tools for AI agents with citations and rate limit checking
55
+ - **API Server**: Drop-in Anthropic Messages API and OpenAI Chat Completions API
56
+ - **10 Models**: GPT-5.2, Claude 4.6 Opus, Claude 4.5 Sonnet, Gemini 3 Flash/Pro, Grok 4.1, Kimi K2.5, Sonar
57
+ - **Thinking Mode**: Extended thinking support for all compatible models
58
+ - **Deep Research**: Full support for Perplexity's Deep Research mode
59
+ - **Setup & Skill Management**: Auto-configure MCP for Claude, Cursor, Windsurf, Gemini CLI; install Agent Skills across platforms
60
+ - **Doctor**: Diagnose installation, auth, config, rate limits, and skill status
61
+
62
+ ---
63
+
64
+ ## Installation
65
+
66
+ ### From PyPI (recommended)
67
+
68
+ **Using uv:**
69
+
70
+ ```bash
71
+ uv tool install "perplexity-web-mcp-cli[all]"
72
+ ```
73
+
74
+ **Using pipx:**
75
+
76
+ ```bash
77
+ pipx install "perplexity-web-mcp-cli[all]"
78
+ ```
79
+
80
+ **Using pip:**
81
+
82
+ ```bash
83
+ pip install "perplexity-web-mcp-cli[all]"
84
+ ```
85
+
86
+ > **Note:** Requires Python 3.10-3.13.
87
+
88
+ ### From source (for development)
89
+
90
+ ```bash
91
+ git clone https://github.com/jacob-bd/perplexity-web-mcp.git
92
+ cd perplexity-web-mcp
93
+ uv venv && source .venv/bin/activate
94
+ uv pip install -e ".[all]"
95
+ ```
96
+
97
+ ### Install variants
98
+
99
+ - `[all]` -- MCP server + API server (recommended)
100
+ - `[mcp]` -- MCP server only
101
+ - `[api]` -- API server only
102
+ - No extras -- CLI + Python library only
103
+
104
+ ### Upgrading
105
+
106
+ ```bash
107
+ pip install --upgrade perplexity-web-mcp-cli[all]
108
+ ```
109
+
110
+ After upgrading, restart your MCP client (Claude Code, Cursor, etc.) to reload the server.
111
+
112
+ ---
113
+
114
+ ## Quick Start
115
+
116
+ ```bash
117
+ # 1. Authenticate
118
+ pwm login
119
+
120
+ # 2. Ask a question
121
+ pwm ask "What is quantum computing?"
122
+
123
+ # 3. Deep research
124
+ pwm research "agentic AI trends 2026"
125
+
126
+ # 4. Check your remaining quotas
127
+ pwm usage
128
+
129
+ # 5. Set up MCP for your AI tools
130
+ pwm setup add claude-code
131
+ pwm setup add cursor
132
+
133
+ # 6. Install the Agent Skill
134
+ pwm skill install claude-code
135
+
136
+ # 7. Diagnose any issues
137
+ pwm doctor
138
+ ```
139
+
140
+ ---
141
+
142
+ ## CLI Reference
143
+
144
+ ### Querying
145
+
146
+ ```bash
147
+ pwm ask "What is quantum computing?" # Auto-select best model
148
+ pwm ask "latest AI news" -m gpt52 -s academic # GPT-5.2 + academic sources
149
+ pwm ask "explain transformers" -m claude_sonnet --thinking # Claude 4.5 + thinking
150
+ pwm ask "query" --json # JSON output
151
+ pwm ask "query" --no-citations # No citation URLs
152
+ ```
153
+
154
+ ### Deep Research
155
+
156
+ ```bash
157
+ pwm research "agentic AI trends 2026" # Full research report
158
+ pwm research "climate policy" -s academic --json # Academic + JSON output
159
+ ```
160
+
161
+ ### Authentication
162
+
163
+ ```bash
164
+ pwm login # Interactive login (email + OTP)
165
+ pwm login --check # Check if authenticated
166
+ pwm login --email user@example.com # Send verification code (non-interactive)
167
+ pwm login --email user@example.com --code 123456 # Complete auth with code
168
+ ```
169
+
170
+ ### Usage & Limits
171
+
172
+ ```bash
173
+ pwm usage # Check remaining rate limits
174
+ pwm usage --refresh # Force-refresh from Perplexity servers
175
+ ```
176
+
177
+ ### MCP Setup
178
+
179
+ ```bash
180
+ pwm setup list # Show supported tools and MCP configuration status
181
+ pwm setup add claude-code # Add MCP server to Claude Code
182
+ pwm setup add cursor # Add MCP server to Cursor
183
+ pwm setup add windsurf # Add MCP server to Windsurf
184
+ pwm setup add gemini # Add MCP server to Gemini CLI
185
+ pwm setup remove cursor # Remove MCP server from a tool
186
+ ```
187
+
188
+ ### Skill Management
189
+
190
+ ```bash
191
+ pwm skill list # Show installation status per platform
192
+ pwm skill install claude-code # Install skill for Claude Code
193
+ pwm skill install cursor --level project # Install at project level
194
+ pwm skill uninstall gemini-cli # Remove skill
195
+ pwm skill update # Update all outdated skills
196
+ pwm skill show # Display skill content
197
+ ```
198
+
199
+ ### Doctor
200
+
201
+ ```bash
202
+ pwm doctor # Diagnose installation, auth, config, limits
203
+ pwm doctor -v # Verbose (includes security + per-platform skill status)
204
+ ```
205
+
206
+ ### AI Documentation
207
+
208
+ ```bash
209
+ pwm --ai # Print comprehensive AI-optimized reference
210
+ ```
211
+
212
+ ---
213
+
214
+ ## Models
215
+
216
+ | CLI Name | Provider | Thinking | Notes |
217
+ |----------|----------|----------|-------|
218
+ | `auto` | Perplexity | No | Auto-selects best model |
219
+ | `sonar` | Perplexity | No | Perplexity's latest model |
220
+ | `deep_research` | Perplexity | No | Monthly quota, in-depth reports |
221
+ | `gpt52` | OpenAI | Toggle | GPT-5.2 |
222
+ | `claude_sonnet` | Anthropic | Toggle | Claude 4.5 Sonnet |
223
+ | `claude_opus` | Anthropic | Toggle | Claude 4.6 Opus (Max tier required) |
224
+ | `gemini_flash` | Google | Toggle | Gemini 3 Flash |
225
+ | `gemini_pro` | Google | Always | Gemini 3 Pro |
226
+ | `grok` | xAI | Toggle | Grok 4.1 |
227
+ | `kimi` | Moonshot | Always | Kimi K2.5 |
228
+
229
+ **Source focus options:** `web` (default), `academic`, `social`, `finance`, `all`
230
+
231
+ ---
232
+
233
+ ## MCP Server
234
+
235
+ ### Setup
236
+
237
+ The easiest way to configure MCP:
238
+
239
+ ```bash
240
+ pwm setup add claude-code
241
+ ```
242
+
243
+ Or configure manually for any MCP client:
244
+
245
+ **Claude Code CLI:**
246
+ ```bash
247
+ claude mcp add perplexity pwm-mcp
248
+ ```
249
+
250
+ **Claude Desktop** (`~/Library/Application Support/Claude/claude_desktop_config.json`):
251
+ ```json
252
+ {
253
+ "mcpServers": {
254
+ "perplexity": {
255
+ "command": "pwm-mcp"
256
+ }
257
+ }
258
+ }
259
+ ```
260
+
261
+ **Cursor** (`~/.cursor/mcp.json`):
262
+ ```json
263
+ {
264
+ "mcpServers": {
265
+ "perplexity": {
266
+ "command": "pwm-mcp"
267
+ }
268
+ }
269
+ }
270
+ ```
271
+
272
+ ### Available MCP Tools
273
+
274
+ **Query tools (14):**
275
+
276
+ | Tool | Description |
277
+ |------|-------------|
278
+ | `pplx_query` | Flexible: model selection + thinking toggle |
279
+ | `pplx_ask` | Quick Q&A (auto-selects best model) |
280
+ | `pplx_deep_research` | In-depth reports with sources |
281
+ | `pplx_sonar` | Perplexity Sonar |
282
+ | `pplx_gpt52` / `pplx_gpt52_thinking` | GPT-5.2 |
283
+ | `pplx_claude_sonnet` / `pplx_claude_sonnet_think` | Claude 4.5 Sonnet |
284
+ | `pplx_gemini_flash` / `pplx_gemini_flash_think` | Gemini 3 Flash |
285
+ | `pplx_gemini_pro_think` | Gemini 3 Pro (thinking always on) |
286
+ | `pplx_grok` / `pplx_grok_thinking` | Grok 4.1 |
287
+ | `pplx_kimi_thinking` | Kimi K2.5 (thinking always on) |
288
+
289
+ **Usage & auth tools (4):**
290
+
291
+ | Tool | Description |
292
+ |------|-------------|
293
+ | `pplx_usage` | Check remaining quotas |
294
+ | `pplx_auth_status` | Check authentication status |
295
+ | `pplx_auth_request_code` | Send verification code to email |
296
+ | `pplx_auth_complete` | Complete auth with 6-digit code |
297
+
298
+ All query tools support `source_focus`: `web`, `academic`, `social`, `finance`, `all`.
299
+
300
+ ---
301
+
302
+ ## API Server
303
+
304
+ Use Perplexity models through Anthropic or OpenAI compatible API endpoints.
305
+
306
+ ### Start the server
307
+
308
+ ```bash
309
+ pwm-api
310
+ ```
311
+
312
+ ### Anthropic API (Claude Code)
313
+
314
+ ```bash
315
+ export ANTHROPIC_BASE_URL=http://localhost:8080
316
+ export ANTHROPIC_AUTH_TOKEN=perplexity
317
+ claude --model gpt-5.2
318
+ ```
319
+
320
+ ### OpenAI API
321
+
322
+ ```bash
323
+ export OPENAI_BASE_URL=http://localhost:8080/v1
324
+ export OPENAI_API_KEY=anything
325
+ ```
326
+
327
+ ### API Model Names
328
+
329
+ | API Name | Perplexity Model | Thinking |
330
+ |----------|------------------|----------|
331
+ | `perplexity-auto` | Best (auto-select) | No |
332
+ | `gpt-5.2` | GPT-5.2 | Toggle |
333
+ | `claude-sonnet-4-5` | Claude 4.5 Sonnet | Toggle |
334
+ | `claude-opus-4-6` | Claude 4.6 Opus | Toggle |
335
+ | `gemini-3-flash` | Gemini 3 Flash | Toggle |
336
+ | `gemini-3-pro` | Gemini 3 Pro | Always |
337
+ | `grok-4.1` | Grok 4.1 | Toggle |
338
+ | `kimi-k2.5` | Kimi K2.5 | Always |
339
+
340
+ Legacy aliases (`claude-3-5-sonnet`, `claude-3-opus`) are supported for compatibility.
341
+
342
+ ---
343
+
344
+ ## Python API
345
+
346
+ ```python
347
+ from perplexity_web_mcp import Perplexity, ConversationConfig, Models
348
+
349
+ client = Perplexity(session_token="your_token")
350
+ conversation = client.create_conversation(
351
+ ConversationConfig(model=Models.CLAUDE_45_SONNET)
352
+ )
353
+
354
+ conversation.ask("What is quantum computing?")
355
+ print(conversation.answer)
356
+
357
+ for result in conversation.search_results:
358
+ print(f"Source: {result.url}")
359
+
360
+ # Follow-up (context preserved)
361
+ conversation.ask("Explain it simpler")
362
+ print(conversation.answer)
363
+ ```
364
+
365
+ ---
366
+
367
+ ## Subscription Tiers & Rate Limits
368
+
369
+ | Tier | Cost | Pro Search | Deep Research | Labs |
370
+ |------|------|------------|---------------|------|
371
+ | Free | $0 | 3/day | 1/month | No |
372
+ | Pro | $20/mo | Weekly pool | Monthly pool | Monthly pool |
373
+ | Max | $200/mo | Weekly pool | Monthly pool | Monthly pool |
374
+
375
+ The MCP server checks quotas before each query. Use `pwm usage` or `pplx_usage` to check your limits.
376
+
377
+ ---
378
+
379
+ ## Troubleshooting
380
+
381
+ ### Authentication Errors (403)
382
+
383
+ Session tokens last ~30 days. Re-authenticate when expired:
384
+
385
+ ```bash
386
+ pwm login
387
+ ```
388
+
389
+ **Non-interactive (for AI agents):**
390
+
391
+ ```bash
392
+ pwm login --email your@email.com
393
+ ```
394
+ ```bash
395
+ pwm login --email your@email.com --code 123456
396
+ ```
397
+
398
+ **Via MCP tools (for AI agents without shell):**
399
+
400
+ 1. Call `pplx_auth_request_code(email="your@email.com")`
401
+ 2. Check email for 6-digit code
402
+ 3. Call `pplx_auth_complete(email="your@email.com", code="123456")`
403
+
404
+ ### Diagnose Issues
405
+
406
+ ```bash
407
+ pwm doctor
408
+ ```
409
+
410
+ This checks installation, authentication, rate limits, MCP configuration, and skill installation -- with fix suggestions for every issue found.
411
+
412
+ ### Rate Limiting
413
+
414
+ - **CLI/MCP**: Auto-checks quotas before each query, blocks if exhausted
415
+ - **API server**: Enforces 5-second minimum between requests
416
+
417
+ ---
418
+
419
+ ## Agent Skill
420
+
421
+ This project includes a portable [Agent Skill](https://agentskills.io/) (SKILL.md) that teaches AI agents how to use the CLI and MCP tools. Install it for your platform:
422
+
423
+ ```bash
424
+ pwm skill install claude-code
425
+ pwm skill install cursor
426
+ pwm skill install gemini-cli
427
+ ```
428
+
429
+ The skill follows Anthropic's Agent Skills open standard and works across any compliant AI platform.
430
+
431
+ ---
432
+
433
+ ## Credits
434
+
435
+ Originally forked from [perplexity-webui-scraper](https://github.com/henrique-coder/perplexity-webui-scraper) by [henrique-coder](https://github.com/henrique-coder).
436
+
437
+ ## License
438
+
439
+ MIT