smartrabbit-mcp 1.6.0 → 1.6.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/index.js +28 -71
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -9,27 +9,35 @@ import {
|
|
|
9
9
|
|
|
10
10
|
const API_URL = "https://smartrabbit-rapidapi.contactjccoaching.workers.dev";
|
|
11
11
|
const PUBMED_BASE = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils";
|
|
12
|
+
const MAX_RETRIES = 3;
|
|
13
|
+
const RETRY_DELAYS = [1000, 2000, 4000]; // ms
|
|
12
14
|
|
|
13
|
-
//
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
};
|
|
15
|
+
// Fetch with retry + exponential backoff
|
|
16
|
+
async function fetchWithRetry(url, options) {
|
|
17
|
+
for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
|
|
18
|
+
try {
|
|
19
|
+
const response = await fetch(url, options);
|
|
20
|
+
if (response.ok) return response;
|
|
21
|
+
if (response.status >= 500 && attempt < MAX_RETRIES) {
|
|
22
|
+
console.error(`API returned ${response.status}, retrying (${attempt + 1}/${MAX_RETRIES})...`);
|
|
23
|
+
await new Promise(r => setTimeout(r, RETRY_DELAYS[attempt]));
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
return response;
|
|
27
|
+
} catch (error) {
|
|
28
|
+
if (attempt < MAX_RETRIES) {
|
|
29
|
+
console.error(`Fetch failed: ${error.message}, retrying (${attempt + 1}/${MAX_RETRIES})...`);
|
|
30
|
+
await new Promise(r => setTimeout(r, RETRY_DELAYS[attempt]));
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
28
37
|
|
|
29
38
|
// Search PubMed for scientific articles
|
|
30
39
|
async function searchPubMed(query, maxResults = 3) {
|
|
31
40
|
try {
|
|
32
|
-
// Search for article IDs
|
|
33
41
|
const searchUrl = `${PUBMED_BASE}/esearch.fcgi?db=pubmed&term=${encodeURIComponent(query)}&retmax=${maxResults}&retmode=json&sort=relevance`;
|
|
34
42
|
const searchResponse = await fetch(searchUrl);
|
|
35
43
|
const searchData = await searchResponse.json();
|
|
@@ -37,7 +45,6 @@ async function searchPubMed(query, maxResults = 3) {
|
|
|
37
45
|
const ids = searchData.esearchresult?.idlist || [];
|
|
38
46
|
if (ids.length === 0) return [];
|
|
39
47
|
|
|
40
|
-
// Get article summaries
|
|
41
48
|
const summaryUrl = `${PUBMED_BASE}/esummary.fcgi?db=pubmed&id=${ids.join(",")}&retmode=json`;
|
|
42
49
|
const summaryResponse = await fetch(summaryUrl);
|
|
43
50
|
const summaryData = await summaryResponse.json();
|
|
@@ -63,61 +70,11 @@ async function searchPubMed(query, maxResults = 3) {
|
|
|
63
70
|
}
|
|
64
71
|
}
|
|
65
72
|
|
|
66
|
-
// Build search queries based on profile
|
|
67
|
-
function buildPubMedQueries(profile) {
|
|
68
|
-
const queries = [];
|
|
69
|
-
const goalQueries = PUBMED_QUERIES[profile.goal] || PUBMED_QUERIES.muscle;
|
|
70
|
-
const levelMod = LEVEL_MODIFIERS[profile.level] || "";
|
|
71
|
-
|
|
72
|
-
// Add goal-specific queries
|
|
73
|
-
for (const q of goalQueries) {
|
|
74
|
-
queries.push(`${q} ${levelMod}`.trim());
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// Add equipment-specific query if relevant
|
|
78
|
-
if (profile.equipment === "bodyweight") {
|
|
79
|
-
queries.push("bodyweight exercise muscle activation");
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Add limitation-specific query if present
|
|
83
|
-
if (profile.limitations) {
|
|
84
|
-
if (profile.limitations.toLowerCase().includes("knee")) {
|
|
85
|
-
queries.push("knee injury resistance training rehabilitation");
|
|
86
|
-
}
|
|
87
|
-
if (profile.limitations.toLowerCase().includes("back") || profile.limitations.toLowerCase().includes("dos")) {
|
|
88
|
-
queries.push("low back pain resistance exercise");
|
|
89
|
-
}
|
|
90
|
-
if (profile.limitations.toLowerCase().includes("shoulder") || profile.limitations.toLowerCase().includes("épaule")) {
|
|
91
|
-
queries.push("shoulder injury exercise modification");
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return queries.slice(0, 3); // Limit to 3 queries
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Format PubMed results for prompt
|
|
99
|
-
function formatPubMedReferences(articles) {
|
|
100
|
-
if (articles.length === 0) return "";
|
|
101
|
-
|
|
102
|
-
let text = "\n\n📚 SCIENTIFIC REFERENCES (PubMed):\n";
|
|
103
|
-
text += "Use these studies to support your justifications:\n\n";
|
|
104
|
-
|
|
105
|
-
for (const article of articles) {
|
|
106
|
-
text += `• ${article.title}\n`;
|
|
107
|
-
text += ` ${article.authors} (${article.year}) - ${article.journal}\n`;
|
|
108
|
-
text += ` PMID: ${article.pmid} | ${article.url}\n\n`;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
text += "Cite relevant findings from these studies in your physiological and neuromuscular justifications.\n";
|
|
112
|
-
|
|
113
|
-
return text;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
73
|
// Create MCP server
|
|
117
74
|
const server = new Server(
|
|
118
75
|
{
|
|
119
76
|
name: "Smart Rabbit Fitness",
|
|
120
|
-
version: "1.6.
|
|
77
|
+
version: "1.6.1",
|
|
121
78
|
},
|
|
122
79
|
{
|
|
123
80
|
capabilities: {
|
|
@@ -274,8 +231,8 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
274
231
|
const outputFormat = args.format || "text";
|
|
275
232
|
const endpoint = outputFormat === "react" ? "/generate" : "/generate-text";
|
|
276
233
|
|
|
277
|
-
// Get the base prompt from API
|
|
278
|
-
const response = await
|
|
234
|
+
// Get the base prompt from API (with retry)
|
|
235
|
+
const response = await fetchWithRetry(`${API_URL}${endpoint}`, {
|
|
279
236
|
method: "POST",
|
|
280
237
|
headers: {
|
|
281
238
|
"Content-Type": "application/json"
|
|
@@ -513,7 +470,7 @@ FEATURES:
|
|
|
513
470
|
async function main() {
|
|
514
471
|
const transport = new StdioServerTransport();
|
|
515
472
|
await server.connect(transport);
|
|
516
|
-
console.error("🐰 Smart Rabbit Fitness MCP v1.6.
|
|
473
|
+
console.error("🐰 Smart Rabbit Fitness MCP v1.6.1 ready");
|
|
517
474
|
}
|
|
518
475
|
|
|
519
476
|
main().catch(console.error);
|
package/package.json
CHANGED