web-search-zaimcp
v0.1.2
Published
Minimal CommonJS helper to call BigModel MCP webSearchPrime with per-call connection and robust parsing.
Downloads
40
Maintainers
Readme
web-search-zaimcp — Minimal CommonJS Utility
- Zero-dependency helper that calls the BigModel MCP
webSearchPrimetool. - Pure JavaScript (CommonJS), easy to embed in any agent framework or script.
- Handles double-stringified JSON and
{items|results|data}wrappers. Each call now creates a fresh connection and closes it afterwards.
Files
src/index.js— exportswebSearchPrime(queryOrParams, options).examples/run-web-search.js— CLI example that loads.envand prints normalized results.
Prerequisites
- Node.js 18+.
- Install deps already listed in
package.json(@modelcontextprotocol/sdk,dotenv).
Environment Setup
- Set
BIGMODEL_API_KEYin your shell or add it to.envat repo root. - Utilities never call
dotenvautomatically; every script should dorequire('dotenv').config()first.
Run the Example
node examples/run-web-search.js "你的查询"- Without args it defaults to
福建舰正式服役的外媒报道. - Output prints
- title+ URL + optional summary snippet.
webSearchPrime Usage
- CommonJS:
const { webSearchPrime } = require('web-search-zaimcp') - ESM/TypeScript (CJS package default import):
import pkg from 'web-search-zaimcp'; const { webSearchPrime } = pkg;- Or
createRequire:const { webSearchPrime } = createRequire(import.meta.url)('web-search-zaimcp')
- Accepts either a string (
'query') or full MCP params object. - Supported params mirror BigModel’s tool:
search_query,count(1-50),content_size,location,search_domain_filter,search_recency_filter. options(all optional):apiKey(defaults toprocess.env.BIGMODEL_API_KEY).endpoint(defaults to official WebSearch Prime MCP endpoint).reuseConnection(deprecated; ignored — connections are per call).
TypeScript
- This package ships
src/index.d.tsand sets"types"andexports.types. - With NodeNext resolution,
exports.defaultenables ESM default import to the CJS entry.
Return Value
{ items, rawBlocks }where each item includes{ title, url, summary, icon, siteName, media, publishedAt, refer, raw }.rawBlocksexposes the original MCP text blocks for debugging or custom parsing.
Integrating With Agents
- Wrap
webSearchPrimeinside any framework’s tool abstraction (LangChain StructuredTool, deepagents, LangGraph, custom orchestrators). - Typical handler:
const { items } = await webSearchPrime(args); return JSON.stringify(items).
Further Customization
- Add your own timeout wrapper via
Promise.raceif needed. - For TS users, consider adding a thin
.d.tsfile or porting the helper to.tswith types. - Modify
_normalizeItemsinsrc/index.jsif you need different fields.
