Skip to content

Commit ad23996

Browse files
fix: remove detailed 401 response (#1124)
* fix: remove detailed 401 response * ci: add changeset
1 parent 6d1e644 commit ad23996

File tree

3 files changed

+6
-21
lines changed

3 files changed

+6
-21
lines changed

.changeset/good-geese-start.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@upstash/context7-mcp": patch
3+
---
4+
5+
Remove masked API key display from unauthorized error responses

packages/mcp/src/lib/api.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { SearchResponse } from "./types.js";
22
import { generateHeaders } from "./encryption.js";
33
import { ProxyAgent, setGlobalDispatcher } from "undici";
44
import { DocumentationMode, DOCUMENTATION_MODES } from "./types.js";
5-
import { maskApiKey } from "./utils.js";
65

76
const CONTEXT7_API_BASE_URL = "https://context7.com/api";
87
const DEFAULT_TYPE = "txt";
@@ -52,7 +51,7 @@ function createErrorMessage(errorCode: number, apiKey?: string): string {
5251
if (!apiKey) {
5352
return "Unauthorized. Please provide an API key.";
5453
}
55-
return `Unauthorized. Please check your API key. The API key you provided (possibly incorrect) is: ${maskApiKey(apiKey)}. API keys should start with 'ctx7sk'`;
54+
return `Unauthorized. Please check your API key. API keys should start with 'ctx7sk'`;
5655
default:
5756
return `Failed to fetch documentation. Please try again later. Error code: ${errorCode}`;
5857
}

packages/mcp/src/lib/utils.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,3 @@ export function formatSearchResults(searchResponse: SearchResponse): string {
6767
const formattedResults = searchResponse.results.map(formatSearchResult);
6868
return formattedResults.join("\n----------\n");
6969
}
70-
71-
/**
72-
* Masks an API key by showing only the first 10 characters and last 4 characters.
73-
* This prevents full API keys from being exposed in logs while maintaining some
74-
* identifiability for debugging.
75-
*
76-
* @param apiKey The API key to mask
77-
* @returns Masked API key string (e.g., "ctx7sk-abc...xyz1") or "[NO-API-KEY]" if no key provided
78-
*/
79-
export function maskApiKey(apiKey: string): string {
80-
if (apiKey.length <= 14) {
81-
// If the key is too short to mask meaningfully, just show first part
82-
return apiKey.substring(0, 7) + "...";
83-
}
84-
85-
const firstPart = apiKey.substring(0, 10);
86-
const lastPart = apiKey.substring(apiKey.length - 4);
87-
return `${firstPart}...${lastPart}`;
88-
}

0 commit comments

Comments
 (0)