Use Desearch as a Wikipedia API for a topic primer with article links. This Python example searches through Desearch MCP and cleans the returned pages before formatting a summary. This page shows a stored sample; there is no hosted demo.
The problem
An assistant needs sources when it explains a new topic. Search results need checks too. A page title can differ from its linked article, and a result can lead to a discussion page. Developers need a reading list that keeps its links and explains what was excluded.
What the app does
- Searches Wikipedia through the Desearch MCP
ai-searchtool. - Drops non-article namespaces and results whose normalized title differs from the URL slug.
- Removes duplicate links and marks non-English pages.
- Replaces numbered citations with links and removes citations to excluded pages.
- Checks summary numbers against returned snippets and highlights, then re-links or omits sentences when needed.
- Lists up to six cleaned articles and optionally adds up to three web reading links.
How it works
- Read the key. The CLI reads
~/.desearch-api-key, or the file supplied with--key-file. It sends the key in theAuthorizationheader tohttps://mcp.desearch.ai/mcp. - Search the topic.
ai-searchreceivestools: ["wikipedia"]andresult_type: "LINKS_WITH_FINAL_SUMMARY". - Clean the results.
clean_pages()checks namespaces, compares normalized titles with URL slugs, deduplicates links and adds language labels. - Format the primer. The script removes links to excluded pages and sentences cited only to those pages. It checks numbers against returned snippets and highlights. Notes explain exclusions.
- Cross-check if requested.
--webruns a separateweb-searchcall. Those links appear in their own reading list.
The namespace list uses English names. A translated namespace can pass that check. These filters do not verify every claim, so open the linked articles before relying on the summary.
The code
These argument builders are verbatim from wikipedia_primer.py:
def build_args(topic):
if not topic or not topic.strip():
raise ValueError("topic is empty")
t = topic.strip()
return {"prompt": f"{t}: what it is, how it works, key facts, criticism, and related topics",
"tools": ["wikipedia"], "result_type": "LINKS_WITH_FINAL_SUMMARY"}
def web_args(topic):
return {"query": f"{topic.strip()} explained"}
The same file opens the MCP session and calls the tools. The key argument comes from read_key() using the configured key file.
async def run(topic, key, cross_check):
from mcp import ClientSession
from mcp.client.streamable_http import streamable_http_client
from mcp.shared._httpx_utils import create_mcp_http_client
async with create_mcp_http_client(headers={"Authorization": key}) as hc, \
streamable_http_client(MCP_URL, http_client=hc) as streams:
async with ClientSession(streams[0], streams[1]) as s:
await s.initialize()
res = await s.call_tool("ai-search", build_args(topic), read_timeout_seconds=180)
wiki = parse_json([c.model_dump() for c in res.content])
web = None
if cross_check:
res = await s.call_tool("web-search", web_args(topic), read_timeout_seconds=180)
web = parse_json([c.model_dump() for c in res.content]) or {}
return wiki, web
Endpoints
https://mcp.desearch.ai/mcpMCP tool ai-search (tools: wikipedia)MCP tool web-search
Example output
This article-list excerpt comes verbatim from samples/live-run-2026-10-19.md, a stored run for the topic "carbon credits" with the web cross-check enabled. The file includes the summary, reading links and exclusion notes.
### Wikipedia pages
- Verified Carbon Standard: https://en.wikipedia.org/wiki/Verified_Carbon_Standard
- Personal carbon credits: https://en.wikipedia.org/wiki/Personal_Carbon_Credits
- Comercio de emisiones de carbono (es Wikipedia): https://es.wikipedia.org/wiki/Comercio_de_emisiones_de_carbono
- Carbon emission trading: https://en.wikipedia.org/wiki/Carbon_emission_trading
- Compensación de carbono (es Wikipedia): https://es.wikipedia.org/wiki/Compensaci%C3%B3n_de_carbono
- Personal carbon trading: https://en.wikipedia.org/wiki/Personal_carbon_tradingRun it yourself
Open the example folder and follow its README to create a virtual environment and install requirements.txt. Put your key from the console in a file only you can read at ~/.desearch-api-key, or pass its path with --key-file.
Run the command from the saved sample:
python wikipedia_primer.py "carbon credits" --webOmit --web for Wikipedia only. The folder also includes saved-prompt.md for an MCP-compatible assistant and offline tests in tests/.
What it costs
On 2026-10-19, the stored run recorded $0.004 for ai-search and $0.001 for the separate web-search, using each response's cost_usd field. The combined API cost was $0.005. Tool times were 9.3 seconds and 2.4 seconds respectively. These are measurements from that run, not a speed guarantee. See pricing for current rates. Assistant usage is separate.
Ideas to extend it
- Save the cleaned title, link and language fields as a reading-list file.
- Add translated namespace checks for the languages you use.
- Keep dated primers so readers can compare source lists over time.
