openlibrary WebMCP
Browser tool configuration for openlibrary
Tools (4)
openlibrary_get_book_details()
Fetch the current work or edition details as JSON
Parameters
JavaScript Handler
(params) => {
const path = params.path || window.location.pathname;
const normalized = path.endsWith('.json') ? path : path.replace(/\/$/, '') + '.json';
return fetch('https://openlibrary.org' + normalized)
.then((resp) => resp.ok ? resp.json() : Promise.reject(new Error('HTTP ' + resp.status)))
.then((data) => ({
success: true,
path,
details: {
title: data.title || document.querySelector('h1')?.textContent?.trim() || '',
description: typeof data.description === 'string' ? data.description : (data.description?.value || ''),
subjects: data.subjects || [],
firstPublishDate: data.first_publish_date || null,
covers: data.covers || [],
url: 'https://openlibrary.org' + path.replace(/\.json$/, '')
}
}))
.catch((error) => ({ success: false, message: error.message, path }));
}
openlibrary_open_book()
Open an Open Library work page by work ID
Parameters
JavaScript Handler
(params) => {
window.location.href = 'https://openlibrary.org/works/' + params.workId;
return { success: true, message: 'Opening work page...', workId: params.workId };
}
openlibrary_search()
Open Library 图书搜索
Parameters
JavaScript Handler
(params) => {
const run = async function(args) {
const query = encodeURIComponent(args.query);
const limit = args.count || 10;
const resp = await fetch(`https://openlibrary.org/search.json?q=${query}&limit=${limit}`);
if (!resp.ok) return {error: 'HTTP ' + resp.status};
const data = await resp.json();
return {
total: data.numFound,
count: data.docs.length,
books: data.docs.map(d => ({
title: d.title,
authors: d.author_name || [],
firstPublishYear: d.first_publish_year,
isbn: (d.isbn || []).slice(0, 3),
subjects: (d.subject || []).slice(0, 5),
pages: d.number_of_pages_median,
cover: d.cover_i ? `https://covers.openlibrary.org/b/id/${d.cover_i}-M.jpg` : null,
url: d.key ? `https://openlibrary.org${d.key}` : null
}))
};
};
return run(params || {});
}
openlibrary_search_books()
Search books from Open Library and return structured results
Parameters
JavaScript Handler
(params) => {
const limit = Math.max(1, Math.min(20, Number(params.limit || 10)));
return fetch('https://openlibrary.org/search.json?q=' + encodeURIComponent(params.query) + '&limit=' + limit)
.then((resp) => resp.ok ? resp.json() : Promise.reject(new Error('HTTP ' + resp.status)))
.then((data) => {
const books = (data.docs || []).slice(0, limit).map((doc, index) => ({
rank: index + 1,
title: doc.title || '',
authors: doc.author_name || [],
firstPublishYear: doc.first_publish_year || null,
editionCount: doc.edition_count || 0,
cover: doc.cover_i ? 'https://covers.openlibrary.org/b/id/' + doc.cover_i + '-M.jpg' : null,
workKey: doc.key || null,
url: doc.key ? 'https://openlibrary.org' + doc.key : null
}));
return {
success: true,
query: params.query,
total: data.numFound || 0,
count: books.length,
books
};
})
.catch((error) => ({ success: false, message: error.message }));
}
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.openlibrary.com/...
Third-party clients can use the same endpoint as mcp-chrome. Execute the returned JavaScript handler in your own browser page context.