pi-web-search
pi-web-search
A web_search tool for the pi coding agent that uses your z.ai GLM Coding Plan's native web search via the web_search_prime MCP endpoint — included in the plan, no extra cost, no separate API key — with a free DuckDuckGo fallback.
Zero dependencies. Zero configuration. ~350 lines of TypeScript.
Goal
One thing, done well: lean native web search through the z.ai Coding Plan, falling back to DuckDuckGo otherwise.
It's search-only by design — there are already good web_fetch extensions out there, so this one doesn't ship a fetcher, and never will. Pair it with whichever you use and you get a full research pipeline: discover → read.
z.ai is the only native provider for now, simply because that's what I use. Other providers may be added down the line, but that's the most this extension will ever grow into.
How it works
web_search(query)
│
├─ key: ZAI_API_KEY env → ~/.pi/agent/auth.json (zai)
▼
┌─────────────────────┐ fail / empty ┌──────────────────────┐
│ ZAI MCP │ ─────────────────► │ DuckDuckGo HTML │
│ web_search_prime │ │ regex scrape │
│ (raw results) │ │ (8 results) │
└─────────────────────┘ └──────────────────────┘
trim to 8 → numbered list (title / URL / snippet)
output annotated with which engine answeredZAI MCP protocol (https://api.z.ai/api/mcp/web_search_prime/mcp):
POSTJSON-RPCinitialize→ captureMcp-Session-Idresponse headerPOSTtools/callwithweb_search_prime+{ search_query }(session header)Parse the SSE
data:line → the text payload is a double-JSON-encoded array of{ title, link, content, refer }
If native search fails or returns nothing, DuckDuckGo takes over automatically, with a visible > zai-mcp unavailable (...) note in the output so you always know which engine answered.
Install
Clone into pi's extensions directory:
git clone <this-repo> ~/.pi/agent/extensions/web-searchRestart pi (or run /reload). The web_search tool appears alongside the built-ins.
Or load it explicitly for a one-off:
pi -e /path/to/pi-web-search/index.tsUsage
The model calls it on its own when it needs current information:
{ "query": "latest stable node version" }Returns:
1. **Node.js 24.x is now LTS ...**
https://nodejs.org/en/blog/announcements/v24-release
Node.js 24 enters long-term support ...
2. **...**Configuration
None required. Optional overrides:
Default | Notes | |
|
| Env var wins if set |
Result count | 8 ( | Client-side trim; edit constant |
Timeouts | MCP 25s / DDG 15s | Edit constants |
Notes
The
Mcp-Session-Idheader from theinitializeresponse is required ontools/callThe MCP text payload is double-JSON-encoded and needs two rounds of
JSON.parseDuckDuckGo's HTML endpoint may bot-wall curl; testing with Node fetch (real browser
User-Agent) matches what the extension actually doesA fresh MCP session is created per search — fine at typical agent search volume
Future work
Additional native provider backends (search only — a fetcher will never be part of this)
Forward optional
count/ domain filters to the MCP endpoint once its input schema is mappedallowed_domains/blocked_domainstool parametersFallback ladder (DDG POST variant →
lite.duckduckgo.com→ Mojeek) if DDG tightens bot detection
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/weibolu-rm/pi-web-search'
If you have feedback or need assistance with the MCP directory API, please join our Discord server