trader.ts•1.69 kB
import { sellStock, buyStock, getHoldings, getPositions } from "./index.js";
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";
// Create an MCP server
const server = new McpServer({
name: "Zerodha Trader Bot",
version: "1.0.0",
});
// Add an addition tool
server.tool("add", { a: z.number(), b: z.number() }, async ({ a, b }) => ({
content: [{ type: "text", text: String(a + b) }],
}));
server.tool(
"sellStock",
{ tradingsymbol: z.string(), quantity: z.number() },
async ({ tradingsymbol, quantity }) => {
await sellStock(tradingsymbol, quantity);
return {
content: [{ type: "text", text: "Stock sold successfully" }],
};
}
);
server.tool(
"buyStock",
{ tradingsymbol: z.string(), quantity: z.number() },
async ({ tradingsymbol, quantity }) => {
await buyStock(tradingsymbol, quantity);
return {
content: [{ type: "text", text: "Stock bought successfully" }],
};
}
);
server.tool("getPositions", {}, async () => {
const json = await getPositions();
return {
content: [{ type: "text", text: JSON.stringify(json) }],
};
});
server.tool("getHoldings", {}, async () => {
const json = await getHoldings();
return {
content: [{ type: "text", text: JSON.stringify(json) }],
};
});
// Start receiving messages on stdin and sending messages on stdout
const transport = new StdioServerTransport();
await server.connect(transport);
// await init();
// await buyStock("MOTHERSON", 1);
// await sellStock("MOTHERSON", 1);
// await getProfile();
// await getHoldings();
// await getPositions();