temba-mcp 0.3.5 → 0.4.1

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,6 +1,6 @@
1
1
  {
2
2
  "name": "temba-mcp",
3
- "version": "0.3.5",
3
+ "version": "0.4.1",
4
4
  "description": "MCP for Temba documentation",
5
5
  "author": "Bouwe (https://bouwe.io)",
6
6
  "scripts": {
package/src/cli.js CHANGED
@@ -1,11 +1,35 @@
1
1
  #!/usr/bin/env node
2
2
  import { startMcpServer } from './mcp.js'
3
+ import { searchDocs } from './searchDocs.js'
3
4
 
4
5
  const args = process.argv.slice(2)
5
6
  const isDebug = args.includes('--debug')
7
+ const queryIndex = args.findIndex((a) => a === '-q' || a === '--query')
6
8
 
7
9
  if (isDebug) {
8
10
  console.error('✨ Temba Docs MCP running in DEBUG mode')
9
11
  }
10
12
 
13
+ // Check for the testing flag
14
+ if (queryIndex !== -1 && args[queryIndex + 1]) {
15
+ const query = args[queryIndex + 1]
16
+
17
+ try {
18
+ // 1. Fetch from the exact same remote location the MCP server uses
19
+ const response = await fetch('https://temba.bouwe.io/search_index.json')
20
+ if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`)
21
+ const index = await response.json()
22
+
23
+ // 2. Execute logic
24
+ const results = searchDocs(query, index)
25
+
26
+ // 3. Output raw JSON (Agent-fidelity)
27
+ process.stdout.write(JSON.stringify(results, null, 2))
28
+ process.exit(0)
29
+ } catch (err) {
30
+ console.error('❌ Failed to fetch remote index for test:', err.message)
31
+ process.exit(1)
32
+ }
33
+ }
34
+
11
35
  startMcpServer({ debug: isDebug }).catch(console.error)
package/src/searchDocs.js CHANGED
@@ -1,16 +1,67 @@
1
+ const stopWords = new Set([
2
+ 'a',
3
+ 'an',
4
+ 'the',
5
+ 'is',
6
+ 'i',
7
+ 'do',
8
+ 'how',
9
+ 'to',
10
+ 'and',
11
+ 'or',
12
+ 'of',
13
+ 'in',
14
+ 'on',
15
+ 'for',
16
+ 'with',
17
+ 'by',
18
+ 'as',
19
+ 'at',
20
+ 'from',
21
+ 'that',
22
+ 'this',
23
+ 'it',
24
+ 'are',
25
+ 'was',
26
+ 'were',
27
+ 'be',
28
+ 'been',
29
+ ])
30
+
1
31
  export const searchDocs = (query, index) => {
2
32
  const lowerQuery = query?.toLowerCase().trim()
33
+ if (!lowerQuery) return []
34
+
35
+ const tokens = lowerQuery.split(/\s+/).filter((token) => !stopWords.has(token))
3
36
 
4
- if (!lowerQuery) {
5
- return []
6
- }
37
+ // Early return if the user only searched for stop words
38
+ if (tokens.length === 0) return []
7
39
 
8
40
  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
- ) || []
41
+ index
42
+ .map((page) => {
43
+ const content = (page.content || '').toLowerCase()
44
+ const title = (page.title || '').toLowerCase()
45
+ const keywords = (page.keywords || []).map((k) => k.toLowerCase())
46
+
47
+ // Count how many tokens are found in this page
48
+ let score = 0
49
+ tokens.forEach((token) => {
50
+ if (
51
+ content.includes(token) ||
52
+ title.includes(token) ||
53
+ keywords.some((k) => k.includes(token))
54
+ ) {
55
+ score += 1
56
+ }
57
+ })
58
+
59
+ return { page, score }
60
+ })
61
+ // Filter out pages that didn't match at least one token
62
+ .filter((item) => item.score > 0)
63
+ // Sort by most matches first
64
+ .sort((a, b) => b.score - a.score)
65
+ .map((item) => item.page)
15
66
  )
16
67
  }