@upstash/context7-mcp 1.0.32-canary-20251209084107 → 1.0.33

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 CHANGED
@@ -1,4 +1,4 @@
1
- ![Cover](public/cover.png)
1
+ ![Cover](https://github.com/upstash/context7/blob/master/public/cover.png?raw=true)
2
2
 
3
3
  [![Install MCP Server](https://cursor.com/deeplink/mcp-install-dark.svg)](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/index.js CHANGED
@@ -103,7 +103,8 @@ For ambiguous queries, request clarification before proceeding with a best-guess
103
103
  },
104
104
  }, async ({ libraryName }) => {
105
105
  const ctx = requestContext.getStore();
106
- const searchResponse = await searchLibraries(libraryName, ctx?.clientIp, ctx?.apiKey);
106
+ const apiKey = ctx?.apiKey || globalApiKey;
107
+ const searchResponse = await searchLibraries(libraryName, ctx?.clientIp, apiKey);
107
108
  if (!searchResponse.results || searchResponse.results.length === 0) {
108
109
  return {
109
110
  content: [
package/dist/lib/api.js CHANGED
@@ -22,27 +22,36 @@ function parseLibraryId(libraryId) {
22
22
  };
23
23
  }
24
24
  /**
25
- * Generates appropriate error messages based on HTTP status codes
26
- * @param errorCode The HTTP error status code
27
- * @param apiKey Optional API key (used for rate limit message)
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 createErrorMessage(errorCode, apiKey) {
31
- switch (errorCode) {
32
- case 429:
33
- return apiKey
34
- ? "Rate limited due to too many requests. Please try again later."
35
- : "Rate limited due to too many requests. You can create a free API key at https://context7.com/dashboard for higher rate limits.";
36
- case 404:
37
- return "The library you are trying to access does not exist. Please try with a different library ID.";
38
- case 401:
39
- if (!apiKey) {
40
- return "Unauthorized. Please provide an API key.";
41
- }
42
- return `Unauthorized. Please check your API key. API keys should start with 'ctx7sk'`;
43
- default:
44
- return `Failed to fetch documentation. Please try again later. Error code: ${errorCode}`;
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 errorCode = response.status;
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 errorCode = response.status;
126
- const errorMessage = createErrorMessage(errorCode, apiKey);
133
+ const errorMessage = await parseErrorResponse(response, apiKey);
127
134
  console.error(errorMessage);
128
135
  return errorMessage;
129
136
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@upstash/context7-mcp",
3
- "version": "1.0.32-canary-20251209084107",
3
+ "version": "1.0.33",
4
4
  "mcpName": "io.github.upstash/context7",
5
5
  "description": "MCP server for Context7",
6
6
  "repository": {