perplexity-web-mcp-cli 0.16.0__tar.gz → 0.16.1__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 (48) hide show
  1. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/PKG-INFO +1 -1
  2. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/pyproject.toml +1 -1
  3. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/pyproject.toml.orig +1 -1
  4. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/core.py +128 -0
  5. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/data/SKILL.md +1 -1
  6. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/README.md +0 -0
  7. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/__init__.py +0 -0
  8. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/api/__init__.py +0 -0
  9. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/api/responses.py +0 -0
  10. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/api/server.py +0 -0
  11. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/api/session_manager.py +0 -0
  12. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/api/tool_calling.py +0 -0
  13. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/auth.py +0 -0
  14. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/catalog.py +0 -0
  15. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/cli/__init__.py +0 -0
  16. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/cli/ai_doc.py +0 -0
  17. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/cli/auth.py +0 -0
  18. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/cli/doctor.py +0 -0
  19. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/cli/hack.py +0 -0
  20. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/cli/main.py +0 -0
  21. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/cli/setup.py +0 -0
  22. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/cli/skill.py +0 -0
  23. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/config.py +0 -0
  24. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/connector_policy.py +0 -0
  25. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/constants.py +0 -0
  26. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/council.py +0 -0
  27. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/data/references/api-endpoints.md +0 -0
  28. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/data/references/mcp-tools.md +0 -0
  29. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/data/references/models.md +0 -0
  30. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/enums.py +0 -0
  31. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/exceptions.py +0 -0
  32. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/http.py +0 -0
  33. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/limits.py +0 -0
  34. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/logging.py +0 -0
  35. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/mcp/__init__.py +0 -0
  36. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/mcp/__main__.py +0 -0
  37. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/mcp/server.py +0 -0
  38. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/models.py +0 -0
  39. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/preferences.py +0 -0
  40. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/py.typed +0 -0
  41. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/rate_limits.py +0 -0
  42. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/resilience.py +0 -0
  43. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/router.py +0 -0
  44. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/sessions.py +0 -0
  45. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/shared.py +0 -0
  46. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/token_store.py +0 -0
  47. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/trace.py +0 -0
  48. {perplexity_web_mcp_cli-0.16.0 → perplexity_web_mcp_cli-0.16.1}/src/perplexity_web_mcp/types.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: perplexity-web-mcp-cli
3
- Version: 0.16.0
3
+ Version: 0.16.1
4
4
  Summary: CLI, MCP server, and Anthropic/OpenAI API-compatible interface for Perplexity AI.
5
5
  Keywords: perplexity,ai,mcp,anthropic,api,client
6
6
  Author: Jacob BD
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "perplexity-web-mcp-cli"
3
- version = "0.16.0"
3
+ version = "0.16.1"
4
4
  description = "CLI, MCP server, and Anthropic/OpenAI API-compatible interface for Perplexity AI."
5
5
  license = "MIT"
6
6
  readme = "README.md"
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "perplexity-web-mcp-cli"
3
- version = "0.16.0"
3
+ version = "0.16.1"
4
4
 
5
5
  description = "CLI, MCP server, and Anthropic/OpenAI API-compatible interface for Perplexity AI."
6
6
  authors = [{ name = "Jacob BD" }]
@@ -5,6 +5,7 @@ from __future__ import annotations
5
5
  from mimetypes import guess_type
6
6
  from os import PathLike
7
7
  from pathlib import Path
8
+ from time import sleep
8
9
  from typing import TYPE_CHECKING, Any
9
10
  from uuid import uuid4
10
11
 
@@ -86,6 +87,87 @@ def _blocks_to_answer_data(blocks: Any) -> dict[str, Any]:
86
87
  return answer_data
87
88
 
88
89
 
90
+ def _extract_final_sources(
91
+ thread_data: dict[str, Any], backend_uuid: str | None = None
92
+ ) -> list[SearchResultItem] | None:
93
+ """Return the ordered source list stored with a thread's final answer.
94
+
95
+ The stored FINAL step embeds the same ``web_results`` payload the answer
96
+ model was given, in the order its ``[n]`` citation markers refer to. This
97
+ is the authoritative numbering for citation footers on multi-step
98
+ searches, where block arrival order does not match the markers. Returns
99
+ ``None`` when the payload cannot provide it (unknown thread, malformed
100
+ data, or a thread stored before the final answer was persisted).
101
+ """
102
+ entries = thread_data.get("entries")
103
+ if not isinstance(entries, list):
104
+ return None
105
+
106
+ entry: dict[str, Any] | None = None
107
+ if backend_uuid:
108
+ for candidate in reversed(entries):
109
+ if isinstance(candidate, dict) and candidate.get("backend_uuid") == backend_uuid:
110
+ entry = candidate
111
+ break
112
+ if entry is None:
113
+ for candidate in reversed(entries):
114
+ if isinstance(candidate, dict):
115
+ entry = candidate
116
+ break
117
+ if entry is None:
118
+ return None
119
+
120
+ raw_steps = entry.get("text")
121
+ try:
122
+ steps = loads(raw_steps) if isinstance(raw_steps, str) else raw_steps
123
+ except JSONDecodeError:
124
+ return None
125
+ if not isinstance(steps, list):
126
+ return None
127
+
128
+ final_step = next(
129
+ (step for step in reversed(steps) if isinstance(step, dict) and step.get("step_type") == "FINAL"),
130
+ None,
131
+ )
132
+ if final_step is None:
133
+ return None
134
+
135
+ content = final_step.get("content")
136
+ raw_answer = content.get("answer") if isinstance(content, dict) else None
137
+ if isinstance(raw_answer, str):
138
+ try:
139
+ answer_data = loads(raw_answer)
140
+ except JSONDecodeError:
141
+ return None
142
+ elif isinstance(raw_answer, dict):
143
+ answer_data = raw_answer
144
+ else:
145
+ return None
146
+ if not isinstance(answer_data, dict):
147
+ return None
148
+
149
+ raw_results: list[Any] = []
150
+ web_results = answer_data.get("web_results")
151
+ if isinstance(web_results, list):
152
+ raw_results.extend(web_results)
153
+ extra_web_results = answer_data.get("extra_web_results")
154
+ if isinstance(extra_web_results, list):
155
+ raw_results.extend(extra_web_results)
156
+
157
+ results: list[SearchResultItem] = []
158
+ seen_urls: set[str] = set()
159
+ for item in raw_results:
160
+ if not isinstance(item, dict):
161
+ continue
162
+ url = item.get("url")
163
+ if not url or url in seen_urls:
164
+ continue
165
+ seen_urls.add(url)
166
+ results.append(SearchResultItem(title=item.get("name"), snippet=item.get("snippet"), url=url))
167
+
168
+ return results or None
169
+
170
+
89
171
  class Perplexity:
90
172
  """Web scraper for Perplexity AI conversations."""
91
173
 
@@ -281,6 +363,7 @@ class Conversation:
281
363
  "_search_results",
282
364
  "_stream_generator",
283
365
  "_title",
366
+ "_web_results_blocks",
284
367
  )
285
368
 
286
369
  def __init__(self, http: HTTPClient, config: ConversationConfig) -> None:
@@ -296,6 +379,7 @@ class Conversation:
296
379
  self._search_results: list[SearchResultItem] = []
297
380
  self._raw_data: dict[str, Any] = {}
298
381
  self._stream_generator: Generator[Response, None, None] | None = None
382
+ self._web_results_blocks = 0
299
383
 
300
384
  @property
301
385
  def answer(self) -> str | None:
@@ -419,6 +503,7 @@ class Conversation:
419
503
  self._search_results = []
420
504
  self._raw_data = {}
421
505
  self._stream_generator = None
506
+ self._web_results_blocks = 0
422
507
 
423
508
  def _validate_files(self, files: list[str | PathLike] | None) -> list[_FileInfo]:
424
509
  if not files:
@@ -647,6 +732,8 @@ class Conversation:
647
732
  if "text" not in data:
648
733
  answer_data = _blocks_to_answer_data(data.get("blocks"))
649
734
  if answer_data:
735
+ if answer_data.get("web_results"):
736
+ self._web_results_blocks += 1
650
737
  self._update_state(data.get("thread_title"), answer_data)
651
738
  return None
652
739
 
@@ -773,6 +860,45 @@ class Conversation:
773
860
  raw_data=self._raw_data,
774
861
  )
775
862
 
863
+ def _refresh_search_results_from_thread(self) -> bool:
864
+ """Align the citation list with the thread's stored FINAL order.
865
+
866
+ Multi-step searches stream several ``web_results`` blocks, and the
867
+ answer's ``[n]`` markers follow the merged, model-facing source list
868
+ stored with the final answer rather than block arrival order. Fetch
869
+ the finished thread once and adopt that order when available; keep
870
+ the accumulated stream order on any failure.
871
+ """
872
+ if self._web_results_blocks <= 1 or not self._backend_uuid:
873
+ return False
874
+
875
+ endpoint = (
876
+ f"{ENDPOINT_THREAD_DETAIL}/{self._backend_uuid}"
877
+ f"?version={API_VERSION}&source=default&limit=100&from_first=true"
878
+ )
879
+ for attempt in (0, 1):
880
+ try:
881
+ response = self._http.get(endpoint)
882
+ thread_data = loads(response.content)
883
+ if isinstance(thread_data, dict):
884
+ ordered = _extract_final_sources(thread_data, self._backend_uuid)
885
+ if ordered:
886
+ previous = len(self._search_results)
887
+ self._search_results = ordered
888
+ log_trace(
889
+ f"[STAGE 3 - CITATION ORDER REFRESH] stored order applied: "
890
+ f"{previous} -> {len(ordered)} sources"
891
+ )
892
+ return True
893
+ except Exception as error: # noqa: BLE001 - best-effort refresh keeps stream order
894
+ logger.debug(f"Citation order refresh failed: {error}")
895
+ log_trace(f"[STAGE 3 - CITATION ORDER REFRESH] attempt {attempt + 1} failed: {error!r}")
896
+ if attempt == 0:
897
+ sleep(1.0)
898
+
899
+ log_trace("[STAGE 3 - CITATION ORDER REFRESH] no stored order found; keeping stream order")
900
+ return False
901
+
776
902
  def _fetch_research_report(self) -> str | None:
777
903
  """Return the full Deep Research report markdown, or ``None``.
778
904
 
@@ -859,6 +985,7 @@ class Conversation:
859
985
  finally:
860
986
  gen.close()
861
987
 
988
+ self._refresh_search_results_from_thread()
862
989
  self._append_research_report()
863
990
 
864
991
  def _stream(self, payload: dict[str, Any]) -> Generator[Response, None, None]:
@@ -874,5 +1001,6 @@ class Conversation:
874
1001
  finally:
875
1002
  gen.close()
876
1003
 
1004
+ self._refresh_search_results_from_thread()
877
1005
  if self._append_research_report():
878
1006
  yield self._build_response()
@@ -2,7 +2,7 @@
2
2
  name: perplexity-web-mcp
3
3
  description: 'Search the web and query AI models via Perplexity AI using perplexity-web-mcp-cli. Supports CLI commands (pwm ask, pwm chat, pwm research, pwm config), MCP tools (pplx_*), and Anthropic/OpenAI-compatible API server. Use when the user mentions "perplexity", "pplx", "pwm", "web search with AI", "chat with Perplexity", "deep research", "search the internet", or wants to query premium models like GPT-6 Sol, GPT-5.6 Terra, Grok 4.7, Claude, Gemini, GLM, Kimi, or Nemotron through Perplexity''s web interface.'
4
4
  metadata:
5
- version: "0.16.0"
5
+ version: "0.16.1"
6
6
  author: "Jacob BD"
7
7
 
8
8
  ---