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