temba-mcp 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +8 -6
- package/{mcp.js → src/mcp.js} +26 -9
- package/src/searchDocs.js +16 -0
- package/src/version.js +1 -0
- package/searchDocs.js +0 -9
- package/version.js +0 -1
- /package/{cli.js → src/cli.js} +0 -0
package/package.json
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "temba-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "MCP for Temba documentation",
|
|
5
5
|
"author": "Bouwe (https://bouwe.io)",
|
|
6
6
|
"scripts": {
|
|
7
|
+
"test": "vitest run",
|
|
8
|
+
"test:watch": "vitest --watch",
|
|
7
9
|
"update": "npx -y jelmerro/nus"
|
|
8
10
|
},
|
|
9
11
|
"bin": {
|
|
10
|
-
"temba-mcp": "./cli.js"
|
|
12
|
+
"temba-mcp": "./src/cli.js"
|
|
11
13
|
},
|
|
12
14
|
"type": "module",
|
|
13
15
|
"files": [
|
|
14
|
-
"
|
|
15
|
-
"mcp.js",
|
|
16
|
-
"searchDocs.js",
|
|
17
|
-
"version.js"
|
|
16
|
+
"src"
|
|
18
17
|
],
|
|
19
18
|
"dependencies": {
|
|
20
19
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
21
20
|
"zod": "4.4.3"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"vitest": "^4.0.18"
|
|
22
24
|
}
|
|
23
25
|
}
|
package/{mcp.js → src/mcp.js}
RENAMED
|
@@ -4,21 +4,37 @@ import { z } from 'zod'
|
|
|
4
4
|
import { searchDocs } from './searchDocs.js'
|
|
5
5
|
import { version } from './version.js'
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
let index = []
|
|
8
|
+
let lastFetched = 0
|
|
9
|
+
const CACHE_TTL = 3600000 // 1 hour in milliseconds
|
|
10
|
+
const searchIndexUrl = 'https://docs.temba.io/search-index.json'
|
|
11
|
+
|
|
12
|
+
async function ensureFreshIndex() {
|
|
13
|
+
if (Date.now() - lastFetched < CACHE_TTL && index.length > 0) return
|
|
12
14
|
|
|
13
|
-
// Fetch the index once on startup
|
|
14
|
-
let index = []
|
|
15
|
-
const searchIndexUrl = 'https://temba.bouwe.io/search-index.json'
|
|
16
15
|
try {
|
|
17
16
|
const response = await fetch(searchIndexUrl)
|
|
17
|
+
if (!response.ok) {
|
|
18
|
+
throw new Error(`HTTP ${response.status} ${response.statusText}`)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const contentType = response.headers.get('content-type') || ''
|
|
22
|
+
if (!contentType.includes('application/json')) {
|
|
23
|
+
throw new Error(`Expected JSON, received ${contentType || 'unknown content type'}`)
|
|
24
|
+
}
|
|
25
|
+
|
|
18
26
|
index = await response.json()
|
|
27
|
+
lastFetched = Date.now()
|
|
19
28
|
} catch (e) {
|
|
20
|
-
console.error('
|
|
29
|
+
console.error('Refresh failed, using stale index:', e)
|
|
21
30
|
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const startMcpServer = async () => {
|
|
34
|
+
const server = new McpServer({
|
|
35
|
+
name: 'temba-docs-mcp',
|
|
36
|
+
version,
|
|
37
|
+
})
|
|
22
38
|
|
|
23
39
|
// Register the tool
|
|
24
40
|
server.tool(
|
|
@@ -26,6 +42,7 @@ export const startMcpServer = async () => {
|
|
|
26
42
|
'Search the library documentation',
|
|
27
43
|
{ query: z.string() },
|
|
28
44
|
async ({ query }) => {
|
|
45
|
+
await ensureFreshIndex()
|
|
29
46
|
const results = searchDocs(query, index).slice(0, 5) // Limit to top 5 results
|
|
30
47
|
|
|
31
48
|
if (results.length === 0) {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const searchDocs = (query, index) => {
|
|
2
|
+
const lowerQuery = query?.toLowerCase().trim()
|
|
3
|
+
|
|
4
|
+
if (!lowerQuery) {
|
|
5
|
+
return []
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
return (
|
|
9
|
+
index?.filter(
|
|
10
|
+
(page) =>
|
|
11
|
+
page.content.toLowerCase().includes(lowerQuery) ||
|
|
12
|
+
page.title.toLowerCase().includes(lowerQuery) ||
|
|
13
|
+
(page.keywords && page.keywords.some((k) => k.toLowerCase().includes(lowerQuery))),
|
|
14
|
+
) || []
|
|
15
|
+
)
|
|
16
|
+
}
|
package/src/version.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const version = '0.1.3'
|
package/searchDocs.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export const searchDocs = (query, index) => {
|
|
2
|
-
const lowerQuery = query.toLowerCase()
|
|
3
|
-
return index.filter(
|
|
4
|
-
(page) =>
|
|
5
|
-
page.content.toLowerCase().includes(lowerQuery) ||
|
|
6
|
-
page.title.toLowerCase().includes(lowerQuery) ||
|
|
7
|
-
(page.keywords && page.keywords.some((k) => k.toLowerCase().includes(lowerQuery))),
|
|
8
|
-
)
|
|
9
|
-
}
|
package/version.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const version = '0.1.2'
|
/package/{cli.js → src/cli.js}
RENAMED
|
File without changes
|