temba-mcp 0.1.3 → 0.3.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.3.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
  }
package/src/cli.js ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+ import { startMcpServer } from './mcp.js'
3
+
4
+ const args = process.argv.slice(2)
5
+ const isDebug = args.includes('--debug')
6
+
7
+ if (isDebug) {
8
+ console.error('✨ Temba Docs MCP running in DEBUG mode')
9
+ }
10
+
11
+ startMcpServer({ debug: isDebug }).catch(console.error)
@@ -4,15 +4,22 @@ 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
+ const LOG_FILE = path.join(process.cwd(), 'temba-mcp.log')
8
+
9
+ function log(message) {
10
+ const timestamp = new Date().toISOString()
11
+ const entry = `[${timestamp}] ${message}\n`
12
+ fs.appendFileSync(LOG_FILE, entry)
13
+ }
14
+
15
+ let index = []
16
+ let lastFetched = 0
17
+ const CACHE_TTL = 3600000 // 1 hour in milliseconds
18
+ const searchIndexUrl = 'https://docs.temba.io/search-index.json'
19
+
20
+ async function ensureFreshIndex() {
21
+ if (Date.now() - lastFetched < CACHE_TTL && index.length > 0) return
12
22
 
13
- // Fetch the index once on startup
14
- let index = []
15
- const searchIndexUrl = 'https://temba.bouwe.io/search_index.json'
16
23
  try {
17
24
  const response = await fetch(searchIndexUrl)
18
25
  if (!response.ok) {
@@ -25,9 +32,17 @@ export const startMcpServer = async () => {
25
32
  }
26
33
 
27
34
  index = await response.json()
35
+ lastFetched = Date.now()
28
36
  } catch (e) {
29
- console.error('Failed to fetch ' + searchIndexUrl, e)
37
+ console.error('Refresh failed, using stale index:', e)
30
38
  }
39
+ }
40
+
41
+ export const startMcpServer = async ({ debug = false } = {}) => {
42
+ const server = new McpServer({
43
+ name: 'temba-docs-mcp',
44
+ version,
45
+ })
31
46
 
32
47
  // Register the tool
33
48
  server.tool(
@@ -35,8 +50,13 @@ export const startMcpServer = async () => {
35
50
  'Search the library documentation',
36
51
  { query: z.string() },
37
52
  async ({ query }) => {
53
+ await ensureFreshIndex()
38
54
  const results = searchDocs(query, index).slice(0, 5) // Limit to top 5 results
39
55
 
56
+ if (debug) {
57
+ log(`Query: "${query}" | Results: ${results.length}`)
58
+ }
59
+
40
60
  if (results.length === 0) {
41
61
  return {
42
62
  content: [{ type: 'text', text: 'No documentation found for your query.' }],
@@ -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/cli.js DELETED
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env node
2
- import { startMcpServer } from './mcp.js'
3
-
4
- console.error('✨ Temba Docs MCP starting...')
5
-
6
- startMcpServer().catch(console.error)
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