2import { Hono, Context } from 'npm:hono';
3import { SSETransport } from 'npm:hono-mcp-server-sse-transport';
4import { toFetchResponse, toReqRes } from "npm:fetch-to-node";
5import { z } from "npm:zod";
6import lunr from "https://cdn.skypack.dev/lunr";
183 { limit: z.number().optional() },
184 async ({ limit }) => {
185 console.log(`${new Date().toISOString()} Fetching proverbs data`);
186 const proverbs = await fetch("https://www.joshbeckman.org/assets/js/proverbs.json").then((res) => res.json());
187 const results = proverbs
188 .sort(() => Math.random() - 0.5)
189 .slice(0, limit || 100);
190 console.log(`${new Date().toISOString()} Proverbs data fetched`);
191 const data = results.join("\n");
192 return {
200 { limit: z.number().optional(), tag: z.string() },
201 async ({ limit, tag }) => {
202 console.log(`${new Date().toISOString()} Fetching sequences data for tag: ${tag}`);
203 const sequences = await fetch("https://www.joshbeckman.org/assets/js/sequences.json").then((res) => res.json());
204 const results = sequences
205 .filter((seq: any) => seq.topic == tag)
206 .slice(0, limit || 100);
207 console.log(`${new Date().toISOString()} Sequences data fetched`);
208 if (results.length == 0) {
209 return {
224 { id: z.string() },
225 async ({ id }) => {
226 console.log(`${new Date().toISOString()} Fetching sequence data for ID: ${id}`);
227 const sequences = await fetch("https://www.joshbeckman.org/assets/js/sequences.json").then((res) => res.json());
228 const sequence = sequences.find((seq: any) => seq.id == id);
229 console.log(`${new Date().toISOString()} Sequence data fetched`);
230 if (!sequence) {
231 return {
244 { query: z.string(), limit: z.number().optional() },
245 async ({ query, limit }) => {
246 console.log(`${new Date().toISOString()} Fetching tags data for search`);
247 const tags = await fetch("https://www.joshbeckman.org/assets/js/tags.json").then((res) => res.json());
248 const tagsIndex = buildTagsIndex(tags);
249 console.log(`${new Date().toISOString()} Tags search index built`);
270 { tags: z.array(z.string()) },
271 async () => {
272 console.log(`${new Date().toISOString()} Fetching tags data`);
273 const sourceTags = await fetch("https://www.joshbeckman.org/assets/js/tags.json")
274 .then((res) => res.json());
275 console.log(`${new Date().toISOString()} Tags data fetched`);
276 const data = sourceTags.filter((tag) => tags.includes(tag.name)).map((tag) => {
277 return `[${tag.name}](${SITE_URL}${tag.url})`;
287 {},
288 async () => {
289 console.log(`${new Date().toISOString()} Fetching tags data`);
290 const tags = await fetch("https://www.joshbeckman.org/assets/js/tags.json")
291 .then((res) => res.json());
292 const data = tags.sort((a, b) => a.name.localeCompare(b.name)).map((tag) => {
293 return tag.name;
294 }).join("\n");
295 console.log(`${new Date().toISOString()} Tags data fetched`);
296 return {
297 content: [{ type: "text", text: data }]
304 { url: z.string() },
305 async ({ url }) => {
306 console.log(`${new Date().toISOString()} Fetching post data for URL: ${url}`);
307 const searchData = await fetch("https://www.joshbeckman.org/assets/js/SearchData.json").then((res) => res.json());
308 const db: Array<Post> = Object.values(searchData).filter(postFilter).map((post) => {
309 post.author_id = post.author_id || "joshbeckman";
312 });
313 const post = db.find((post) => post.url == url || `${SITE_URL}${post.url}` == url);
314 console.log(`${new Date().toISOString()} Post data fetched`);
315 if (!post) {
316 return {
339 console.log(`${new Date().toISOString()} loading search data`);
340 const [searchData, indexCache] = await Promise.all([
341 fetch("https://www.joshbeckman.org/assets/js/SearchData.json").then((res) => res.json()),
342 fetch("https://www.joshbeckman.org/assets/js/lunr-index.json").then((res) => res.json()),
343 ]);
344 console.log(`${new Date().toISOString()} search data loaded`);
452 });
453
454 return toFetchResponse(res);
455 } catch (e) {
456 console.error(e);
503 * This will be exposed as a Val.town HTTP endpoint
504 */
505export default app.fetch;
506