Skip to content

Commit d1a296b

Browse files
ashwin-antclaude
andcommitted
feat: remove console statements from SDK code
- Remove all console.log, console.warn, and console.error from src/client and src/server - Add ESLint no-console rule for client and server directories (excluding tests) - Keep console statements in test files, examples, and CLI tools as intended Addresses feedback in PR #665 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 744b9ea commit d1a296b

File tree

9 files changed

+31
-29
lines changed

9 files changed

+31
-29
lines changed

eslint.config.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,12 @@ export default tseslint.config(
1515
{ "argsIgnorePattern": "^_" }
1616
]
1717
}
18+
},
19+
{
20+
files: ["src/client/**/*.ts", "src/server/**/*.ts"],
21+
ignores: ["**/*.test.ts"],
22+
rules: {
23+
"no-console": "error"
24+
}
1825
}
1926
);

src/client/auth.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ export async function auth(
116116
if (resourceMetadata.authorization_servers && resourceMetadata.authorization_servers.length > 0) {
117117
authorizationServerUrl = resourceMetadata.authorization_servers[0];
118118
}
119-
} catch (error) {
120-
console.warn("Could not load OAuth Protected Resource metadata, falling back to /.well-known/oauth-authorization-server", error)
119+
} catch {
120+
// Ignore errors and fall back to /.well-known/oauth-authorization-server
121121
}
122122

123123
const resource: URL | undefined = await selectResourceURL(serverUrl, provider, resourceMetadata);
@@ -175,8 +175,8 @@ export async function auth(
175175

176176
await provider.saveTokens(newTokens);
177177
return "AUTHORIZED";
178-
} catch (error) {
179-
console.error("Could not refresh OAuth tokens:", error);
178+
} catch {
179+
// Could not refresh OAuth tokens
180180
}
181181
}
182182

@@ -222,7 +222,6 @@ export function extractResourceMetadataUrl(res: Response): URL | undefined {
222222

223223
const [type, scheme] = authenticateHeader.split(' ');
224224
if (type.toLowerCase() !== 'bearer' || !scheme) {
225-
console.log("Invalid WWW-Authenticate header format, expected 'Bearer'");
226225
return undefined;
227226
}
228227
const regex = /resource_metadata="([^"]*)"/;
@@ -235,7 +234,6 @@ export function extractResourceMetadataUrl(res: Response): URL | undefined {
235234
try {
236235
return new URL(match[1]);
237236
} catch {
238-
console.log("Invalid resource metadata url: ", match[1]);
239237
return undefined;
240238
}
241239
}

src/client/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,8 @@ export class Client<
486486
try {
487487
const validator = this._ajv.compile(tool.outputSchema);
488488
this._cachedToolOutputValidators.set(tool.name, validator);
489-
} catch (error) {
490-
console.warn(`Failed to compile output schema for tool ${tool.name}: ${error}`);
489+
} catch {
490+
// Ignore schema compilation errors
491491
}
492492
}
493493
}

src/server/auth/handlers/authorize.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ export function authorizationHandler({ provider, rateLimit: rateLimitConfig }: A
9999
const status = error instanceof ServerError ? 500 : 400;
100100
res.status(status).json(error.toResponseObject());
101101
} else {
102-
console.error("Unexpected error looking up client:", error);
103102
const serverError = new ServerError("Internal Server Error");
104103
res.status(500).json(serverError.toResponseObject());
105104
}
@@ -146,7 +145,6 @@ export function authorizationHandler({ provider, rateLimit: rateLimitConfig }: A
146145
if (error instanceof OAuthError) {
147146
res.redirect(302, createErrorRedirect(redirect_uri, error, state));
148147
} else {
149-
console.error("Unexpected error during authorization:", error);
150148
const serverError = new ServerError("Internal Server Error");
151149
res.redirect(302, createErrorRedirect(redirect_uri, serverError, state));
152150
}

src/server/auth/handlers/register.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ export function clientRegistrationHandler({
104104
const status = error instanceof ServerError ? 500 : 400;
105105
res.status(status).json(error.toResponseObject());
106106
} else {
107-
console.error("Unexpected error registering client:", error);
108107
const serverError = new ServerError("Internal Server Error");
109108
res.status(500).json(serverError.toResponseObject());
110109
}

src/server/auth/handlers/revoke.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
InvalidRequestError,
1010
ServerError,
1111
TooManyRequestsError,
12-
OAuthError
12+
OAuthError,
1313
} from "../errors.js";
1414

1515
export type RevocationHandlerOptions = {
@@ -21,7 +21,10 @@ export type RevocationHandlerOptions = {
2121
rateLimit?: Partial<RateLimitOptions> | false;
2222
};
2323

24-
export function revocationHandler({ provider, rateLimit: rateLimitConfig }: RevocationHandlerOptions): RequestHandler {
24+
export function revocationHandler({
25+
provider,
26+
rateLimit: rateLimitConfig,
27+
}: RevocationHandlerOptions): RequestHandler {
2528
if (!provider.revokeToken) {
2629
throw new Error("Auth provider does not support revoking tokens");
2730
}
@@ -37,21 +40,25 @@ export function revocationHandler({ provider, rateLimit: rateLimitConfig }: Revo
3740

3841
// Apply rate limiting unless explicitly disabled
3942
if (rateLimitConfig !== false) {
40-
router.use(rateLimit({
41-
windowMs: 15 * 60 * 1000, // 15 minutes
42-
max: 50, // 50 requests per windowMs
43-
standardHeaders: true,
44-
legacyHeaders: false,
45-
message: new TooManyRequestsError('You have exceeded the rate limit for token revocation requests').toResponseObject(),
46-
...rateLimitConfig
47-
}));
43+
router.use(
44+
rateLimit({
45+
windowMs: 15 * 60 * 1000, // 15 minutes
46+
max: 50, // 50 requests per windowMs
47+
standardHeaders: true,
48+
legacyHeaders: false,
49+
message: new TooManyRequestsError(
50+
"You have exceeded the rate limit for token revocation requests"
51+
).toResponseObject(),
52+
...rateLimitConfig,
53+
})
54+
);
4855
}
4956

5057
// Authenticate and extract client details
5158
router.use(authenticateClient({ clientsStore: provider.clientsStore }));
5259

5360
router.post("/", async (req, res) => {
54-
res.setHeader('Cache-Control', 'no-store');
61+
res.setHeader("Cache-Control", "no-store");
5562

5663
try {
5764
const parseResult = OAuthTokenRevocationRequestSchema.safeParse(req.body);
@@ -62,7 +69,6 @@ export function revocationHandler({ provider, rateLimit: rateLimitConfig }: Revo
6269
const client = req.client;
6370
if (!client) {
6471
// This should never happen
65-
console.error("Missing client information after authentication");
6672
throw new ServerError("Internal Server Error");
6773
}
6874

@@ -73,7 +79,6 @@ export function revocationHandler({ provider, rateLimit: rateLimitConfig }: Revo
7379
const status = error instanceof ServerError ? 500 : 400;
7480
res.status(status).json(error.toResponseObject());
7581
} else {
76-
console.error("Unexpected error revoking token:", error);
7782
const serverError = new ServerError("Internal Server Error");
7883
res.status(500).json(serverError.toResponseObject());
7984
}

src/server/auth/handlers/token.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ export function tokenHandler({ provider, rateLimit: rateLimitConfig }: TokenHand
7979

8080
const client = req.client;
8181
if (!client) {
82-
// This should never happen
83-
console.error("Missing client information after authentication");
8482
throw new ServerError("Internal Server Error");
8583
}
8684

@@ -143,7 +141,6 @@ export function tokenHandler({ provider, rateLimit: rateLimitConfig }: TokenHand
143141
const status = error instanceof ServerError ? 500 : 400;
144142
res.status(status).json(error.toResponseObject());
145143
} else {
146-
console.error("Unexpected error exchanging token:", error);
147144
const serverError = new ServerError("Internal Server Error");
148145
res.status(500).json(serverError.toResponseObject());
149146
}

src/server/auth/middleware/bearerAuth.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ export function requireBearerAuth({ verifier, requiredScopes = [], resourceMetad
8888
} else if (error instanceof OAuthError) {
8989
res.status(400).json(error.toResponseObject());
9090
} else {
91-
console.error("Unexpected error authenticating bearer token:", error);
9291
const serverError = new ServerError("Internal Server Error");
9392
res.status(500).json(serverError.toResponseObject());
9493
}

src/server/auth/middleware/clientAuth.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ export function authenticateClient({ clientsStore }: ClientAuthenticationMiddlew
6464
const status = error instanceof ServerError ? 500 : 400;
6565
res.status(status).json(error.toResponseObject());
6666
} else {
67-
console.error("Unexpected error authenticating client:", error);
6867
const serverError = new ServerError("Internal Server Error");
6968
res.status(500).json(serverError.toResponseObject());
7069
}

0 commit comments

Comments
 (0)