@upstash/context7-mcp 1.0.32-canary-20251209084107 → 1.0.32
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/README.md +1 -1
- package/dist/lib/api.js +29 -22
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-

|
|
1
|
+

|
|
2
2
|
|
|
3
3
|
[](https://cursor.com/en/install-mcp?name=context7&config=eyJ1cmwiOiJodHRwczovL21jcC5jb250ZXh0Ny5jb20vbWNwIn0%3D) [<img alt="Install in VS Code (npx)" src="https://img.shields.io/badge/Install%20in%20VS%20Code-0098FF?style=for-the-badge&logo=visualstudiocode&logoColor=white">](https://insiders.vscode.dev/redirect?url=vscode%3Amcp%2Finstall%3F%7B%22name%22%3A%22context7%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40upstash%2Fcontext7-mcp%40latest%22%5D%7D)
|
|
4
4
|
|
package/dist/lib/api.js
CHANGED
|
@@ -22,27 +22,36 @@ function parseLibraryId(libraryId) {
|
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* @param
|
|
25
|
+
* Parses error response from the Context7 API
|
|
26
|
+
* Extracts the server's error message, falling back to status-based messages if parsing fails
|
|
27
|
+
* @param response The fetch Response object
|
|
28
|
+
* @param apiKey Optional API key (used for fallback messages)
|
|
28
29
|
* @returns Error message string
|
|
29
30
|
*/
|
|
30
|
-
function
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
31
|
+
async function parseErrorResponse(response, apiKey) {
|
|
32
|
+
try {
|
|
33
|
+
const json = (await response.json());
|
|
34
|
+
if (json.message) {
|
|
35
|
+
return json.message;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
// JSON parsing failed, fall through to default
|
|
40
|
+
}
|
|
41
|
+
// Fallback for non-JSON responses
|
|
42
|
+
const status = response.status;
|
|
43
|
+
if (status === 429) {
|
|
44
|
+
return apiKey
|
|
45
|
+
? "Rate limited or quota exceeded. Upgrade your plan at https://context7.com/plans for higher limits."
|
|
46
|
+
: "Rate limited or quota exceeded. Create a free API key at https://context7.com/dashboard for higher limits.";
|
|
47
|
+
}
|
|
48
|
+
if (status === 404) {
|
|
49
|
+
return "The library you are trying to access does not exist. Please try with a different library ID.";
|
|
50
|
+
}
|
|
51
|
+
if (status === 401) {
|
|
52
|
+
return "Invalid API key. Please check your API key. API keys should start with 'ctx7sk' prefix.";
|
|
45
53
|
}
|
|
54
|
+
return `Request failed with status ${status}. Please try again later.`;
|
|
46
55
|
}
|
|
47
56
|
// Pick up proxy configuration in a variety of common env var names.
|
|
48
57
|
const PROXY_URL = process.env.HTTPS_PROXY ??
|
|
@@ -77,8 +86,7 @@ export async function searchLibraries(query, clientIp, apiKey) {
|
|
|
77
86
|
const headers = generateHeaders(clientIp, apiKey);
|
|
78
87
|
const response = await fetch(url, { headers });
|
|
79
88
|
if (!response.ok) {
|
|
80
|
-
const
|
|
81
|
-
const errorMessage = createErrorMessage(errorCode, apiKey);
|
|
89
|
+
const errorMessage = await parseErrorResponse(response, apiKey);
|
|
82
90
|
console.error(errorMessage);
|
|
83
91
|
return {
|
|
84
92
|
results: [],
|
|
@@ -122,8 +130,7 @@ export async function fetchLibraryDocumentation(libraryId, docMode, options = {}
|
|
|
122
130
|
const headers = generateHeaders(clientIp, apiKey, { "X-Context7-Source": "mcp-server" });
|
|
123
131
|
const response = await fetch(url, { headers });
|
|
124
132
|
if (!response.ok) {
|
|
125
|
-
const
|
|
126
|
-
const errorMessage = createErrorMessage(errorCode, apiKey);
|
|
133
|
+
const errorMessage = await parseErrorResponse(response, apiKey);
|
|
127
134
|
console.error(errorMessage);
|
|
128
135
|
return errorMessage;
|
|
129
136
|
}
|