Check Reddit Session
check_sessionConfirm whether you are connected to a Reddit account. Displays your username if authorized, or shows anonymous status.
Instructions
Check if connected to a Reddit account. Shows username if authorized, or anonymous if not. Run 'authorize' tool to connect your account for write operations.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/auth.ts:14-54 (handler)Handler function for the check_session tool. Calls ensureToken() to get a valid token, then checks whether the session is authenticated (has a username) or anonymous. Returns a JSON response with status, username, and read/write capabilities.
async () => { try { await client.ensureToken(); const username = client.getUsername(); const authenticated = client.isAuthenticated(); return { content: [ { type: "text" as const, text: JSON.stringify( { status: authenticated ? "authenticated" : "anonymous", username, can_read: true, can_write: authenticated, message: authenticated ? `Connected as u/${username}. Full read/write access.` : "Anonymous mode. Reads work. Run 'authorize' to enable writes.", }, null, 2 ), }, ], }; } catch (error) { return { content: [ { type: "text" as const, text: JSON.stringify({ status: "error", error: error instanceof Error ? error.message : String(error), }, null, 2), }, ], isError: true, }; } } ); - src/tools/auth.ts:8-12 (schema)Schema/definition for the check_session tool. It has an empty input schema (no parameters), a title, and a description.
{ title: "Check Reddit Session", description: "Check if connected to a Reddit account. Shows username if authorized, or anonymous if not. Run 'authorize' tool to connect your account for write operations.", inputSchema: z.object({}), - src/tools/auth.ts:6-54 (registration)Registration of the check_session tool on the MCP server via server.registerTool() in the auth module's register function.
server.registerTool( "check_session", { title: "Check Reddit Session", description: "Check if connected to a Reddit account. Shows username if authorized, or anonymous if not. Run 'authorize' tool to connect your account for write operations.", inputSchema: z.object({}), }, async () => { try { await client.ensureToken(); const username = client.getUsername(); const authenticated = client.isAuthenticated(); return { content: [ { type: "text" as const, text: JSON.stringify( { status: authenticated ? "authenticated" : "anonymous", username, can_read: true, can_write: authenticated, message: authenticated ? `Connected as u/${username}. Full read/write access.` : "Anonymous mode. Reads work. Run 'authorize' to enable writes.", }, null, 2 ), }, ], }; } catch (error) { return { content: [ { type: "text" as const, text: JSON.stringify({ status: "error", error: error instanceof Error ? error.message : String(error), }, null, 2), }, ], isError: true, }; } } ); - src/reddit/client.ts:191-193 (helper)Helper method on RedditClient that returns whether the session has a username (i.e., is authenticated). Used by the check_session handler.
isAuthenticated(): boolean { return !!this.session?.username; } - src/reddit/client.ts:187-189 (helper)Helper method on RedditClient that returns the username or '(anonymous)' if not authenticated. Used by the check_session handler.
getUsername(): string { return this.session?.username || "(anonymous)"; }