Skip to main content
Glama
index.ts2.41 kB
import { McpAgent } from "agents/mcp"; import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; import { z } from "zod"; import { PaymentState, experimental_PaidMcpAgent as PaidMcpAgent, } from '@stripe/agent-toolkit/cloudflare'; type Bindings = { // Add environment variables here } type Props = { userEmail: string; }; type State = PaymentState & {}; // Define our MCP agent with tools export class MyMCP extends PaidMcpAgent<Bindings, State, Props> { server = new McpServer({ name: "Authless Calculator", version: "1.0.0", }); async init() { // Simple addition tool this.server.tool( "add", { a: z.number(), b: z.number() }, async ({ a, b }) => ({ content: [{ type: "text", text: String(a + b) }], }) ); // Calculator tool with multiple operations this.server.tool( "calculate", { operation: z.enum(["add", "subtract", "multiply", "divide"]), a: z.number(), b: z.number(), }, async ({ operation, a, b }) => { let result: number; switch (operation) { case "add": result = a + b; break; case "subtract": result = a - b; break; case "multiply": result = a * b; break; case "divide": if (b === 0) return { content: [ { type: "text", text: "Error: Cannot divide by zero", }, ], }; result = a / b; break; } return { content: [{ type: "text", text: String(result) }] }; } ); // Paid tool using Stripe this.paidTool( 'add_numbers', { a: z.number(), b: z.number(), }, ({a, b}) => { return { content: [{type: 'text', text: `Result: ${a + b}`}], }; }, { priceId: '{{PRICE_ID}}', // Replace with your actual price ID from Stripe successUrl: 'https://mcp.mysite.com/success', paymentReason: 'You must pay a subscription to add two big numbers together.', } ); } } export default { fetch(request: Request, env: Env, ctx: ExecutionContext) { const url = new URL(request.url); if (url.pathname === "/sse" || url.pathname === "/sse/message") { // @ts-ignore return MyMCP.serveSSE("/sse").fetch(request, env, ctx); } if (url.pathname === "/mcp") { // @ts-ignore return MyMCP.serve("/mcp").fetch(request, env, ctx); } return new Response("Not found", { status: 404 }); }, };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Brunwo/mcp-stripe'

If you have feedback or need assistance with the MCP directory API, please join our Discord server