Generate-Session
Generate a new session token for automated stock trading on the Zerodha platform, enabling seamless integration with the Node.js-based trading bot for advanced operations like buy/sell actions and portfolio management.
Instructions
Generate a new session token using request token
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- index.js:54-63 (handler)Handler function for the 'Generate-Session' MCP tool. It calls tokenManager.generateSession with the requestToken and returns a success or error message in the MCP response format.async ({ requestToken }) => { try { const response = await tokenManager.generateSession(requestToken); return { content: [{ type: "text", text: "Session generated successfully" }], }; } catch (error) { return { content: [{ type: "text", text: `Error: ${error.message}` }] }; } }
- index.js:50-64 (registration)Registration of the 'Generate-Session' tool on the MCP server, including name, description, input schema, and handler.server.tool( "Generate-Session", "Generate a new session token using request token", { requestToken: z.string() }, async ({ requestToken }) => { try { const response = await tokenManager.generateSession(requestToken); return { content: [{ type: "text", text: "Session generated successfully" }], }; } catch (error) { return { content: [{ type: "text", text: `Error: ${error.message}` }] }; } } );
- index.js:53-53 (schema)Input schema for the Generate-Session tool using Zod: requires a string requestToken.{ requestToken: z.string() },
- tokenManager.js:50-61 (helper)Core implementation of session generation in TokenManager class using KiteConnect API, saves the access token to file, and handles errors.async generateSession(requestToken) { try { const response = await this.kc.generateSession( requestToken, this.apiSecret ); await this.saveToken(response); return response; } catch (error) { throw new Error(`Error generating session: ${error.message}`); } }