temba-mcp 0.1.3 → 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 CHANGED
@@ -1,23 +1,25 @@
1
1
  {
2
2
  "name": "temba-mcp",
3
- "version": "0.1.3",
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
- "cli.js",
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
  }
@@ -4,15 +4,14 @@ import { z } from 'zod'
4
4
  import { searchDocs } from './searchDocs.js'
5
5
  import { version } from './version.js'
6
6
 
7
- export const startMcpServer = async () => {
8
- const server = new McpServer({
9
- name: 'temba-docs-mcp',
10
- version,
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)
18
17
  if (!response.ok) {
@@ -25,9 +24,17 @@ export const startMcpServer = async () => {
25
24
  }
26
25
 
27
26
  index = await response.json()
27
+ lastFetched = Date.now()
28
28
  } catch (e) {
29
- console.error('Failed to fetch ' + searchIndexUrl, e)
29
+ console.error('Refresh failed, using stale index:', e)
30
30
  }
31
+ }
32
+
33
+ export const startMcpServer = async () => {
34
+ const server = new McpServer({
35
+ name: 'temba-docs-mcp',
36
+ version,
37
+ })
31
38
 
32
39
  // Register the tool
33
40
  server.tool(
@@ -35,6 +42,7 @@ export const startMcpServer = async () => {
35
42
  'Search the library documentation',
36
43
  { query: z.string() },
37
44
  async ({ query }) => {
45
+ await ensureFreshIndex()
38
46
  const results = searchDocs(query, index).slice(0, 5) // Limit to top 5 results
39
47
 
40
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/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
- }
File without changes
File without changes