temba-mcp 0.3.0 → 0.3.2

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.
Files changed (3) hide show
  1. package/package.json +1 -1
  2. package/src/log.js +11 -0
  3. package/src/mcp.js +15 -15
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "temba-mcp",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "MCP for Temba documentation",
5
5
  "author": "Bouwe (https://bouwe.io)",
6
6
  "scripts": {
package/src/log.js ADDED
@@ -0,0 +1,11 @@
1
+ const LOG_FILE = path.join(process.cwd(), 'temba-mcp.log')
2
+
3
+ export const createLogger = (debug = false) => {
4
+ return (message) => {
5
+ if (debug) {
6
+ const timestamp = new Date().toISOString()
7
+ const entry = `[${timestamp}] ${message}\n`
8
+ fs.appendFileSync(LOG_FILE, entry)
9
+ }
10
+ }
11
+ }
package/src/mcp.js CHANGED
@@ -1,23 +1,16 @@
1
1
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
2
2
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
3
3
  import { z } from 'zod'
4
+ import { createLogger } from './log.js'
4
5
  import { searchDocs } from './searchDocs.js'
5
6
  import { version } from './version.js'
6
7
 
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
8
  let index = []
16
9
  let lastFetched = 0
17
10
  const CACHE_TTL = 3600000 // 1 hour in milliseconds
18
11
  const searchIndexUrl = 'https://docs.temba.io/search-index.json'
19
12
 
20
- async function ensureFreshIndex() {
13
+ async function ensureFreshIndex(log) {
21
14
  if (Date.now() - lastFetched < CACHE_TTL && index.length > 0) return
22
15
 
23
16
  try {
@@ -34,7 +27,7 @@ async function ensureFreshIndex() {
34
27
  index = await response.json()
35
28
  lastFetched = Date.now()
36
29
  } catch (e) {
37
- console.error('Refresh failed, using stale index:', e)
30
+ log(`Refresh failed, using stale index: ${e.message}`)
38
31
  }
39
32
  }
40
33
 
@@ -44,22 +37,29 @@ export const startMcpServer = async ({ debug = false } = {}) => {
44
37
  version,
45
38
  })
46
39
 
40
+ const log = createLogger(debug)
41
+
47
42
  // Register the tool
48
43
  server.tool(
49
44
  'search_docs',
50
45
  'Search the library documentation',
51
46
  { query: z.string() },
52
47
  async ({ query }) => {
53
- await ensureFreshIndex()
48
+ await ensureFreshIndex(log)
49
+
50
+ log(`Current index size: ${index.length}`)
51
+ log(`First title: ${index[0]?.title}`)
52
+
54
53
  const results = searchDocs(query, index).slice(0, 5) // Limit to top 5 results
55
54
 
56
- if (debug) {
57
- log(`Query: "${query}" | Results: ${results.length}`)
58
- }
55
+ log(`Query: "${query}" | Results: ${results.length}`)
59
56
 
57
+ // Return a friendly message instead of an empty result to avoid LLM confusion.
60
58
  if (results.length === 0) {
61
59
  return {
62
- content: [{ type: 'text', text: 'No documentation found for your query.' }],
60
+ content: [
61
+ { type: 'text', text: `No Temba documentation found for your query "${query}".` },
62
+ ],
63
63
  }
64
64
  }
65
65