baidu WebMCP
Browser tool configuration for baidu
Tools (1)
baidu_search()
百度搜索
Parameters
JavaScript Handler
(params) => {
const run = async function(args) {
const query = args.query;
if (!query) return {error: 'query is required'};
const count = args.count || 10;
const url = 'https://www.baidu.com/s?wd=' + encodeURIComponent(query) + '&rn=' + count;
const resp = await fetch(url, {credentials: 'include'});
if (!resp.ok) return {error: 'HTTP ' + resp.status};
const html = await resp.text();
const parser = new DOMParser();
const doc = parser.parseFromString(html, 'text/html');
const containers = doc.querySelectorAll('div.result, div.c-container');
const results = [];
containers.forEach(el => {
const titleEl = el.querySelector('h3 a') || el.querySelector('a[href]');
if (!titleEl) return;
const title = (titleEl.textContent || '').trim();
if (!title) return;
const href = titleEl.getAttribute('href') || '';
const snippetEl = el.querySelector('.c-abstract, .c-span-last, span.content-right_8Zs40');
let snippet = '';
if (snippetEl) {
snippet = (snippetEl.textContent || '').trim();
} else {
// fallback: grab text from common snippet containers
const fallback = el.querySelector('span[class*="content"], div[class*="abstract"]');
if (fallback) snippet = (fallback.textContent || '').trim();
}
results.push({
title: title,
url: href,
snippet: snippet.substring(0, 300)
});
});
return {
query: query,
count: results.length,
results: results
};
};
return run(params || {});
}
WebMCP clients
Use mcp-chrome, or fetch the same tools from the public API in your own browser automation runtime.
How to Use WebMCP
WebMCP tools are designed for browser extensions or automation frameworks. The browser extension matches the current URL against the pattern and executes the JavaScript handler when the tool is invoked.
API Endpoint:
GET /api/webmcp/match?url=https://www.baidu.com/...
Third-party clients can use the same endpoint as mcp-chrome. Execute the returned JavaScript handler in your own browser page context.