1(function registerCoalesceDocsWebMcpTools() { 2 "use strict"; 3 4 var ALGOLIA_APP_ID = "M9YDBKPFWK"; 5 var ALGOLIA_API_KEY = "53408dbbda710f9c0b8b772cdbf48d78"; 6 var ALGOLIA_INDEX = "developer_documentation"; 7 var SITE_ORIGIN = "https://docs.coalesce.io"; 8 9 function getModelContext() { 10 return document.modelContext; 11 } 12 13 function getMarkdownUrl() { 14 var path = window.location.pathname.replace(/\/$/, ""); 15 if (!path || path === "/") { 16 return SITE_ORIGIN + "/llms.txt"; 17 } 18 if (path.endsWith(".md")) { 19 return window.location.origin + path; 20 } 21 if (path === "/docs") { 22 return window.location.origin + "/docs.md"; 23 } 24 if (path.indexOf("/docs/") === 0) { 25 return window.location.origin + path + ".md"; 26 } 27 return null; 28 } 29 30 async function searchDocs(query) { 31 var response = await fetch( 32 "https://" + ALGOLIA_APP_ID + "-dsn.algolia.net/1/indexes/" + ALGOLIA_INDEX + "/query", 33 { 34 method: "POST", 35 headers: { 36 "X-Algolia-Application-Id": ALGOLIA_APP_ID, 37 "X-Algolia-API-Key": ALGOLIA_API_KEY, 38 "Content-Type": "application/json", 39 }, 40 body: JSON.stringify({ query: query, hitsPerPage: 10 }), 41 } 42 ); 43 44 if (!response.ok) { 45 throw new Error("Documentation search failed with status " + response.status); 46 } 47 48 var payload = await response.json(); 49 return { 50 query: query, 51 results: (payload.hits || []).map(function (hit) { 52 return { 53 title: hit.hierarchy && hit.hierarchy.lvl0 ? hit.hierarchy.lvl0 : hit.title, 54 url: hit.url, 55 snippet: hit.content || "", 56 }; 57 }), 58 }; 59 } 60 61 async function fetchLlmsIndex() { 62 var response = await fetch("/llms.txt", { headers: { Accept: "text/plain" } }); 63 if (!response.ok) { 64 throw new Error("Failed to fetch llms.txt with status " + response.status); 65 } 66 return { 67 url: SITE_ORIGIN + "/llms.txt", 68 content: await response.text(), 69 }; 70 } 71 72 function registerTools() { 73 var modelContext = getModelContext(); 74 if (!modelContext || typeof modelContext.registerTool !== "function") { 75 return; 76 } 77 78 modelContext.registerTool({ 79 name: "search-docs", 80 description: "Search Coalesce product documentation by keyword or phrase.", 81 inputSchema: { 82 type: "object", 83 properties: { 84 query: { 85 type: "string", 86 description: "Search query for Coalesce documentation.", 87 }, 88 }, 89 required: ["query"], 90 }, 91 execute: function (input) { 92 return searchDocs(input.query); 93 }, 94 }); 95 96 modelContext.registerTool({ 97 name: "get-llms-index", 98 description: "Fetch the llms.txt documentation section index for agent discovery.", 99 inputSchema: { 100 type: "object", 101 properties: {}, 102 }, 103 execute: fetchLlmsIndex, 104 }); 105 106 modelContext.registerTool({ 107 name: "get-page-markdown-url", 108 description: "Return the markdown URL for the current documentation page.", 109 inputSchema: { 110 type: "object", 111 properties: {}, 112 }, 113 execute: async function () { 114 var markdownUrl = getMarkdownUrl(); 115 return { 116 title: document.title, 117 html_url: window.location.href, 118 markdown_url: markdownUrl, 119 markdown_available: markdownUrl !== null, 120 llms_index: SITE_ORIGIN + "/llms.txt", 121 }; 122 }, 123 }); 124 } 125 126 if (document.readyState === "loading") { 127 document.addEventListener("DOMContentLoaded", registerTools); 128 } else { 129 registerTools(); 130 } 131})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.