@thomas.tan/typescript-mcp-demo-server
Version:
TypeScript MCP demo server with web extraction, search, and datetime utilities
25 lines (24 loc) • 821 B
JavaScript
export async function searchEndpoint(query) {
try {
const searchUrl = `http://localhost:420/search`;
const response = await fetch(searchUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ query }),
});
if (!response.ok) {
throw new Error(`Search request failed: ${response.status} ${response.statusText}`);
}
const data = await response.json();
// Return the search results as formatted text
return JSON.stringify(data, null, 2);
}
catch (error) {
if (error instanceof Error) {
throw new Error(`Search failed: ${error.message}`);
}
throw new Error('Search failed: Unknown error');
}
}