if ('modelContext' in navigator) {
navigator.modelContext.registerTool({
name: 'searchContent',
readOnly: true,
description: 'Full-text search across all content.
Returns: title, excerpt, URL, publish date.
Use for: finding articles, guides, case studies.',
inputSchema: {
type: 'object',
properties: {
query: { type: 'string',
description: 'Search query' },
contentType: {
type: 'string',
enum: ['article', 'guide', 'case-study', 'all'],
description: 'Filter by content type'
}
},
required: ['query']
},
async execute({ query, contentType = 'all' }) {
try {
const res = await fetch(
`/api/search?q=${encodeURIComponent(query)}&type=${contentType}`
);
if (!res.ok) throw new Error(res.statusText);
return { content: [{
type: 'text', text: await res.text()
}] };
} catch (e) {
return { content: [{
type: 'text',
text: `Search failed: ${e.message}`
}] };
}
}
});
}