### Running the Main Script - Shell Source: https://github.com/stripe/agent-toolkit/blob/main/python/examples/langchain/README.md Executes the main Python script located at `main.py`. This command starts the application and runs the LangChain example logic defined in the script. Requires Python and the project dependencies to be installed. ```shell python main.py ``` -------------------------------- ### Setting up Environment Variables - Shell Source: https://github.com/stripe/agent-toolkit/blob/main/python/examples/langchain/README.md Copies the `.env.template` file to `.env`. This is a standard step to initialize configuration settings for the project, requiring the user to then populate the new `.env` file with specific credentials or parameters. Requires a Unix-like shell environment. ```shell cp .env.template .env ``` -------------------------------- ### Copy Environment Example File (bash) Source: https://github.com/stripe/agent-toolkit/blob/main/python/examples/openai/customer_support/README.md Copies the example environment configuration file (`.env.example`) to the active environment file (`.env`). Users must then edit the `.env` file to add their specific credentials and API keys. ```bash cp .env.example .env ``` -------------------------------- ### Running AI SDK Example Script (Shell) Source: https://github.com/stripe/agent-toolkit/blob/main/typescript/examples/ai-sdk/README.md Executes the `index.ts` TypeScript file using `ts-node` via `npx`. The `--env` flag suggests environment-specific configuration is being passed or utilized during execution. This command starts the main application logic. ```shell npx ts-node index.ts --env ``` -------------------------------- ### Copying Environment File Template (Shell) Source: https://github.com/stripe/agent-toolkit/blob/main/typescript/examples/ai-sdk/README.md Copies the `.env.template` file to `.env` to create a local environment configuration file, which needs to be populated with specific values for the AI SDK example. This is a prerequisite for running the application. ```shell cp .env.template .env ``` -------------------------------- ### Install Dependencies with uv (bash) Source: https://github.com/stripe/agent-toolkit/blob/main/python/examples/openai/customer_support/README.md Installs all required project dependencies listed in the project's dependency file (typically requirements.txt when using uv) within the currently active virtual environment. This command fetches and installs the libraries needed for the email agent to function. ```bash uv sync ``` -------------------------------- ### Install uv Package Manager (bash) Source: https://github.com/stripe/agent-toolkit/blob/main/python/examples/openai/customer_support/README.md Installs the 'uv' package manager, a fast Python package installer and resolver, by downloading and executing an installation script. This is a prerequisite for managing project dependencies and virtual environments efficiently. ```bash curl -LsSf https://astral.sh/uv/install.sh | sh ``` -------------------------------- ### Running TypeScript Example Script with ts-node (Shell) Source: https://github.com/stripe/agent-toolkit/blob/main/typescript/examples/openai/README.md Executes the `index.ts` script using `ts-node`, which allows running TypeScript files directly without prior compilation. `npx` ensures the locally installed `ts-node` executable is used. The `--env` flag likely indicates environment variables should be loaded or used by the script. Requires Node.js, npx, and ts-node installed. ```Shell npx ts-node index.ts --env ``` -------------------------------- ### Executing the Stripe Agent Toolkit Example Script (Bash) Source: https://github.com/stripe/agent-toolkit/blob/main/python/examples/openai/file_search/README.md This snippet provides the command to run the main Python script for the Stripe Agent Toolkit web search example. It assumes a `main.py` file exists and the Python environment is set up correctly, initiating the agent's functionality. ```bash python main.py ``` -------------------------------- ### Copying Environment Template File (Shell) Source: https://github.com/stripe/agent-toolkit/blob/main/typescript/examples/openai/README.md Copies the `.env.template` file to `.env`. This is a common step to set up environment variables for a project by creating a local configuration file based on a provided template. Requires shell access. ```Shell cp .env.template .env ``` -------------------------------- ### Executing Main Python Script (Shell) Source: https://github.com/stripe/agent-toolkit/blob/main/python/examples/crewai/README.md This shell command executes the main Python script named `main.py`. It uses the `python` interpreter to run the file, starting the CrewAI example application. ```Shell python main.py ``` -------------------------------- ### Defining a Test Case with Async Setup (Javascript) Source: https://github.com/stripe/agent-toolkit/blob/main/evals/README.md This snippet illustrates how to use an async function for test case setup. It fetches customer data from Stripe using the `stripe` object before defining the prompt and toolkit configuration. This is useful for tests that require specific state or context to be prepared beforehand. ```javascript test(async () => { const customers = await stripe.customers.list(); return { prompt: "What are my payments", toolkitConfig: { context: { customer: customers.data[0].id, }, }, fn: ({ toolCalls, messages }) => [], }; }); ``` -------------------------------- ### Setting Up Development Environment with pnpm Source: https://github.com/stripe/agent-toolkit/blob/main/typescript/examples/cloudflare/README.md This snippet installs project dependencies and starts the local development server for the PaidMcpAgent. It uses `pnpm` for package management and `pnpm dev` to run the application, typically on `localhost`. ```Shell pnpm i pnpm dev ``` -------------------------------- ### Create and Activate Virtual Environment (bash) Source: https://github.com/stripe/agent-toolkit/blob/main/python/examples/openai/customer_support/README.md Creates a dedicated virtual environment using 'uv' to isolate project dependencies and provides commands to activate it on both Unix/macOS and Windows operating systems. Activating the virtual environment is crucial before installing dependencies. ```bash uv venv source .venv/bin/activate # On Unix/macOS # or .venv\Scripts\activate # On Windows ``` -------------------------------- ### Executing Agent Application - Bash Source: https://github.com/stripe/agent-toolkit/blob/main/python/examples/openai/web_search/README.md This snippet provides the command to run the main application script. It assumes the script is written in Python and named `main.py`, located in the current directory. Executing this command starts the agent process. ```bash python main.py ``` -------------------------------- ### Run the Email Support Agent (bash) Source: https://github.com/stripe/agent-toolkit/blob/main/python/examples/openai/customer_support/README.md Executes the main application script (`main.py`) using the Python interpreter within the active virtual environment. This command starts the email support agent's primary loop to check emails and generate responses. ```bash python main.py ``` -------------------------------- ### Copying Environment Template File (Shell) Source: https://github.com/stripe/agent-toolkit/blob/main/python/examples/crewai/README.md This shell command copies the `.env.template` file to `.env`. This is a standard practice to create a local configuration file from a template, which should then be populated with specific environment variables required for the application. ```Shell cp .env.template .env ``` -------------------------------- ### Copying Environment Template File (Shell) Source: https://github.com/stripe/agent-toolkit/blob/main/typescript/examples/langchain/README.md This command copies the `.env.template` file to `.env`. This is a common step in project setup to create a local configuration file based on a provided template. Users should then edit the `.env` file with their specific environment variable values. ```Shell cp .env.template .env ``` -------------------------------- ### Setting up Development Environment (Shell) Source: https://github.com/stripe/agent-toolkit/blob/main/python/README.md Provides the sequence of shell commands to set up a Python virtual environment, activate it, and install the necessary dependencies for developing or contributing to the Stripe Agent Toolkit library. ```sh python3 -m venv venv source venv/bin/activate pip install -r requirements.txt ``` -------------------------------- ### Running Stripe MCP Server with npx (Bash) Source: https://github.com/stripe/agent-toolkit/blob/main/README.md Command to quickly start the Stripe Model Context Protocol (MCP) server using `npx`. It enables all available tools (`--tools=all`) and requires providing your Stripe secret key (`--api-key`) for authentication. ```bash npx -y @stripe/mcp --tools=all --api-key=YOUR_STRIPE_SECRET_KEY ``` -------------------------------- ### Run the Agent REPL (bash) Source: https://github.com/stripe/agent-toolkit/blob/main/python/examples/openai/customer_support/README.md Executes the Read-Eval-Print Loop script (`repl.py`) using the Python interpreter. This provides an interactive console for testing the agent's capabilities and tools without processing live emails. ```bash python repl.py ``` -------------------------------- ### Running Evaluations with tsx (Shell) Source: https://github.com/stripe/agent-toolkit/blob/main/evals/README.md This command executes the `eval.ts` script using `tsx`, a command-line tool for running TypeScript files. It's used to start the evaluation process for testing the agent toolkit after setting up the environment. ```shell tsx eval.ts ``` -------------------------------- ### Setting Environment Variables for Stripe Agent Toolkit (Bash) Source: https://github.com/stripe/agent-toolkit/blob/main/python/examples/openai/file_search/README.md This snippet shows the required environment variables for configuring the Stripe Agent Toolkit example. It includes keys for OpenAI API, OpenAI Vector Store ID, and Stripe Secret Key, which must be populated with actual values for the application to function. ```bash OPENAI_API_KEY=your_openai_api_key OPENAI_VECTOR_STORE_ID=your_openai_vector_store_id STRIPE_SECRET_KEY=your_stripe_secret_key ``` -------------------------------- ### Installing Stripe Agent Toolkit (Shell) Source: https://github.com/stripe/agent-toolkit/blob/main/python/README.md Provides the standard command-line instruction to install the `stripe-agent-toolkit` package using pip. This is the required step before using the library in your Python project. ```sh pip install stripe-agent-toolkit ``` -------------------------------- ### Configuring Environment Variables - Bash Source: https://github.com/stripe/agent-toolkit/blob/main/python/examples/openai/web_search/README.md This snippet shows the required environment variables for running the agent application. It includes keys for OpenAI and Stripe API access, a specific Stripe customer ID, and the ID of the Stripe Billing Meter to record usage. These variables are typically stored in a `.env` file. ```bash OPENAI_API_KEY=your_openai_api_key STRIPE_SECRET_KEY=your_stripe_secret_key STRIPE_CUSTOMER_ID=your_stripe_customer_id STRIPE_METER=your_stripe_meter ``` -------------------------------- ### Installing Stripe Agent Toolkit (TypeScript/Node.js) Source: https://github.com/stripe/agent-toolkit/blob/main/README.md Command to install the `@stripe/agent-toolkit` package from npm. This package is required for using the toolkit functionalities in TypeScript or Node.js projects and needs Node 18+. ```sh npm install @stripe/agent-toolkit ``` -------------------------------- ### Installing Stripe Agent Toolkit (Python) Source: https://github.com/stripe/agent-toolkit/blob/main/README.md Command to install the `stripe-agent-toolkit` Python package from PyPI using pip. This package is required to use the toolkit functionalities in Python projects and needs Python 3.11+. ```sh pip install stripe-agent-toolkit ``` -------------------------------- ### Defining a Simple Agent Test Case (Javascript) Source: https://github.com/stripe/agent-toolkit/blob/main/evals/README.md This snippet demonstrates how to define a basic test case using the built-in framework. It includes a `prompt` for the agent and an assertion function (`fn`) that checks for specific `toolCalls` and verifies the content of the LLM's response using `llmCriteriaMet`. Dependencies include the testing framework functions like `test`, `expectToolCall`, and `llmCriteriaMet`. ```javascript test({ prompt: "Create a product called 'Test Product' with a description 'A test product for evaluation'", fn: ({ toolCalls, messages }) => [ expectToolCall(toolCalls, ["create_product"]), llmCriteriaMet( messages, "The message should include a successful production creation response" ), ], }); ``` -------------------------------- ### Installing Stripe Agent Toolkit Source: https://github.com/stripe/agent-toolkit/blob/main/typescript/src/cloudflare/README.md This command installs the `@stripe/agent-toolkit` package, which provides the `PaidMcpAgent` functionality for integrating payments into your MCP server. ```shell npm install @stripe/agent-toolkit ``` -------------------------------- ### Integrating Toolkit Tools with Agent (Python) Source: https://github.com/stripe/agent-toolkit/blob/main/README.md Shows how to get the tools from the initialized `stripe_agent_toolkit` instance and pass them as a list to an `Agent` constructor. This allows the agent (compatible with frameworks like OpenAI Agent SDK, LangChain, CrewAI) to utilize the integrated Stripe functionalities. ```python from agents import Agent stripe_agent = Agent( name="Stripe Agent", instructions="You are an expert at integrating with Stripe", tools=stripe_agent_toolkit.get_tools() ) ``` -------------------------------- ### Debugging Stripe MCP Server with MCP Inspector (npx) Source: https://github.com/stripe/agent-toolkit/blob/main/modelcontextprotocol/README.md This command starts the MCP Inspector along with the Stripe MCP server, enabling debugging. It launches the server with all tools and requires `YOUR_STRIPE_SECRET_KEY` for authentication. The Inspector UI can then be used to test individual tools. ```bash npx @modelcontextprotocol/inspector node dist/index.js --tools=all --api-key=YOUR_STRIPE_SECRET_KEY ``` -------------------------------- ### Configuring Evaluation Environment Variables (.env) Source: https://github.com/stripe/agent-toolkit/blob/main/evals/README.md This snippet shows the required environment variables for running evaluations, including API keys for Braintrust and Stripe, and configuration for the OpenAI API endpoint. These settings are typically stored in a `.env` file. ```dotenv BRAINTRUST_API_KEY=... STRIPE_SECRET_KEY=sk_test_.... OPENAI_BASE_URL=http://0.0.0.0:8000/v1 OPENAI_API_KEY=EMPTY ``` -------------------------------- ### Executing TypeScript Script with ts-node (Shell) Source: https://github.com/stripe/agent-toolkit/blob/main/typescript/examples/langchain/README.md This command uses `npx` to run `ts-node`, which directly executes the `index.ts` TypeScript file without prior compilation. The `--env` flag is passed to the script, likely indicating that it should load environment variables from the `.env` file created in the previous step. ```Shell npx ts-node index.ts --env ``` -------------------------------- ### Defining a Basic Unpaid Tool in TypeScript Source: https://github.com/stripe/agent-toolkit/blob/main/typescript/src/cloudflare/README.md This code defines a simple tool named 'add' that takes two numbers (`a` and `b`) as input and returns their sum. This serves as a baseline example before implementing payment requirements. ```typescript this.server.tool('add', {a: z.number(), b: z.number()}, ({a, b}) => { return { content: [{type: 'text', text: `Result: ${a + b}`}], }; }); ``` -------------------------------- ### Setting Up Stripe MCP Server with npx Source: https://github.com/stripe/agent-toolkit/blob/main/modelcontextprotocol/README.md These commands demonstrate how to initialize the Stripe Model Context Protocol (MCP) server using `npx`. They allow setting up all available tools or specific ones, and configuring a Stripe connected account. The `YOUR_STRIPE_SECRET_KEY` placeholder must be replaced with an actual Stripe secret key. ```bash # To set up all available tools npx -y @stripe/mcp --tools=all --api-key=YOUR_STRIPE_SECRET_KEY ``` ```bash # To set up specific tools npx -y @stripe/mcp --tools=customers.create,customers.read,products.create --api-key=YOUR_STRIPE_SECRET_KEY ``` ```bash # To configure a Stripe connected account npx -y @stripe/mcp --tools=all --api-key=YOUR_STRIPE_SECRET_KEY --stripe-account=CONNECTED_ACCOUNT_ID ``` -------------------------------- ### Setting up Custom Stripe MCP Server (TypeScript) Source: https://github.com/stripe/agent-toolkit/blob/main/README.md Shows how to programmatically create and run a custom Stripe Model Context Protocol (MCP) server using the toolkit in TypeScript. It demonstrates configuring allowed actions (like creating payment links, products, prices) and setting up communication using `StdioServerTransport`. ```typescript import { StripeAgentToolkit } from "@stripe/agent-toolkit/modelcontextprotocol"; import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; const server = new StripeAgentToolkit({ secretKey: process.env.STRIPE_SECRET_KEY!, configuration: { actions: { paymentLinks: { create: true, }, products: { create: true, }, prices: { create: true, }, }, }, }); async function main() { const transport = new StdioServerTransport(); await server.connect(transport); console.error("Stripe MCP Server running on stdio"); } main().catch((error) => { console.error("Fatal error in main():", error); process.exit(1); }); ``` -------------------------------- ### Initializing Stripe Agent Toolkit (Python) Source: https://github.com/stripe/agent-toolkit/blob/main/README.md Demonstrates how to initialize the `StripeAgentToolkit` class in Python, providing the Stripe secret key and an optional configuration object to enable specific actions, such as creating payment links. ```python from stripe_agent_toolkit.openai.toolkit import StripeAgentToolkit stripe_agent_toolkit = StripeAgentToolkit( secret_key="sk_test_...", configuration={ "actions": { "payment_links": { "create": True, }, } }, ) ``` -------------------------------- ### Initializing Stripe Agent Toolkit (Python) Source: https://github.com/stripe/agent-toolkit/blob/main/python/README.md Demonstrates how to import and initialize the `StripeAgentToolkit` class from the library. Initialization requires your Stripe secret key and can include a configuration dictionary to specify allowed actions or other settings. ```python from stripe_agent_toolkit.openai.toolkit import StripeAgentToolkit stripe_agent_toolkit = StripeAgentToolkit( secret_key="sk_test_...", configuration={ "actions": { "payment_links": { "create": True, }, } }, ) ``` -------------------------------- ### Building Stripe MCP Server Source: https://github.com/stripe/agent-toolkit/blob/main/modelcontextprotocol/README.md This command builds the Stripe MCP server, typically used as a prerequisite before running or debugging the server. It compiles the project source code into an executable format. ```bash npm run build ``` -------------------------------- ### Initializing Toolkit for LangChain (TypeScript) Source: https://github.com/stripe/agent-toolkit/blob/main/README.md Demonstrates how to initialize the `StripeAgentToolkit` specifically for LangChain in TypeScript. It requires providing the Stripe secret key (typically from environment variables) and can include a configuration to specify permitted actions. ```typescript import { StripeAgentToolkit } from "@stripe/agent-toolkit/langchain"; const stripeAgentToolkit = new StripeAgentToolkit({ secretKey: process.env.STRIPE_SECRET_KEY!, configuration: { actions: { paymentLinks: { create: true, }, }, }, }); ``` -------------------------------- ### Configuring Claude Desktop for Stripe MCP (Docker) Source: https://github.com/stripe/agent-toolkit/blob/main/modelcontextprotocol/README.md This JSON configuration snippet for `claude_desktop_config.json` integrates the Stripe MCP server using Docker. It defines the `docker run` command and arguments to launch the server with all tools, requiring `STRIPE_SECRET_KEY` to be replaced with the actual API key. ```json { "mcpServers": { "stripe": { "command": "docker", "args": [ "run", "--rm", "-i", "mcp/stripe", "--tools=all", "--api-key=STRIPE_SECRET_KEY" ] } } } ``` -------------------------------- ### Configuring Claude Desktop for Stripe MCP (npx) Source: https://github.com/stripe/agent-toolkit/blob/main/modelcontextprotocol/README.md This JSON configuration snippet is used within `claude_desktop_config.json` to integrate the Stripe MCP server. It specifies the `npx` command and arguments to launch the server with all tools, requiring `STRIPE_SECRET_KEY` to be replaced with the actual API key. ```json { "mcpServers": { "stripe": { "command": "npx", "args": [ "-y", "@stripe/mcp", "--tools=all", "--api-key=STRIPE_SECRET_KEY" ] } } } ``` -------------------------------- ### Setting Up Stripe MCP Server with Stdio Transport Source: https://github.com/stripe/agent-toolkit/blob/main/typescript/README.md Initializes the Stripe Agent Toolkit for the Model Context Protocol (MCP) as a server and sets up a standard I/O transport. This allows communication with MCP clients over stdio, exposing configured Stripe actions like creating payment links, products, and prices. ```typescript import {StripeAgentToolkit} from '@stripe/agent-toolkit/modelcontextprotocol'; import {StdioServerTransport} from '@modelcontextprotocol/sdk/server/stdio.js'; const server = new StripeAgentToolkit({ secretKey: process.env.STRIPE_SECRET_KEY!, configuration: { actions: { paymentLinks: { create: true, }, products: { create: true, }, prices: { create: true, }, }, }, }); async function main() { const transport = new StdioServerTransport(); await server.connect(transport); console.error('Stripe MCP Server running on stdio'); } main().catch((error) => { console.error('Fatal error in main():', error); process.exit(1); }); ``` -------------------------------- ### Using Stripe Toolkit Tools with LangChain Agent Source: https://github.com/stripe/agent-toolkit/blob/main/typescript/README.md Demonstrates how to obtain the tools provided by the Stripe Agent Toolkit instance and integrate them with a LangChain structured chat agent and executor. Requires an initialized toolkit instance, an LLM, and a prompt. ```typescript import {AgentExecutor, createStructuredChatAgent} from 'langchain/agents'; const tools = stripeAgentToolkit.getTools(); const agent = await createStructuredChatAgent({ llm, tools, prompt, }); const agentExecutor = new AgentExecutor({ agent, tools, }); ``` -------------------------------- ### Initializing StripeAgentToolkit for LangChain Source: https://github.com/stripe/agent-toolkit/blob/main/typescript/README.md Initializes the StripeAgentToolkit instance for use with LangChain. Requires a Stripe secret key and allows configuration of allowed actions, such as creating payment links. ```typescript import {StripeAgentToolkit} from '@stripe/agent-toolkit/langchain'; const stripeAgentToolkit = new StripeAgentToolkit({ secretKey: process.env.STRIPE_SECRET_KEY!, configuration: { actions: { paymentLinks: { create: true, }, }, }, }); ``` -------------------------------- ### Initializing Toolkit with Context (Python) Source: https://github.com/stripe/agent-toolkit/blob/main/python/README.md Illustrates how to initialize the `StripeAgentToolkit` and provide default context values, such as the `account` ID for making API calls on behalf of a connected account in a Stripe Connect integration. ```python stripe_agent_toolkit = StripeAgentToolkit( secret_key="sk_test_...", configuration={ "context": { "account": "acct_123" } } ) ``` -------------------------------- ### Integrating Toolkit Tools with LangChain Agent (TypeScript) Source: https://github.com/stripe/agent-toolkit/blob/main/README.md Shows how to retrieve the tools exposed by the `stripeAgentToolkit` and use them to configure a LangChain `StructuredChatAgent` and an `AgentExecutor`, enabling the agent to perform Stripe operations. ```typescript import { AgentExecutor, createStructuredChatAgent } from "langchain/agents"; const tools = stripeAgentToolkit.getTools(); const agent = await createStructuredChatAgent({ llm, tools, prompt, }); const agentExecutor = new AgentExecutor({ agent, tools, }); ``` -------------------------------- ### Building Stripe MCP Server Docker Image Source: https://github.com/stripe/agent-toolkit/blob/main/modelcontextprotocol/README.md This Docker command builds a Docker image for the Stripe MCP server. The image is tagged as `mcp/stripe` and can be used to run the server in a containerized environment. ```docker docker build -t mcp/stripe . ``` -------------------------------- ### Integrating Toolkit Tools with an Agent (Python) Source: https://github.com/stripe/agent-toolkit/blob/main/python/README.md Shows how to pass the tools exposed by the initialized `stripe_agent_toolkit` instance to an agent object within an agent framework. The `get_tools()` method provides the necessary interface for integration. ```python from agents import Agent stripe_agent = Agent( name="Stripe Agent", instructions="You are an expert at integrating with Stripe", tools=stripe_agent_toolkit.get_tools() ) ``` -------------------------------- ### Configuring Context in Toolkit (Python) Source: https://github.com/stripe/agent-toolkit/blob/main/README.md Shows how to initialize the `StripeAgentToolkit` in Python with a `context` configuration object. This is used to set default values, such as a connected `account` ID, for subsequent API calls made through the toolkit. ```python stripe_agent_toolkit = StripeAgentToolkit( secret_key="sk_test_...", configuration={ "context": { "account": "acct_123" } } ) ``` -------------------------------- ### Configuring Middleware for Metered Billing (TypeScript) Source: https://github.com/stripe/agent-toolkit/blob/main/README.md Demonstrates how to use the `stripeAgentToolkit.middleware` function with Vercel's AI SDK `wrapLanguageModel`. This middleware is configured for metered billing, specifying the Stripe customer ID and meters for tracking input and output tokens. ```typescript import { StripeAgentToolkit } from "@stripe/agent-toolkit/ai-sdk"; import { openai } from "@ai-sdk/openai"; import { generateText, experimental_wrapLanguageModel as wrapLanguageModel, } from "ai"; const stripeAgentToolkit = new StripeAgentToolkit({ secretKey: process.env.STRIPE_SECRET_KEY!, configuration: { actions: { paymentLinks: { create: true, }, }, }, }); const model = wrapLanguageModel({ model: openai("gpt-4o"), middleware: stripeAgentToolkit.middleware({ billing: { customer: "cus_123", meters: { input: "input_tokens", output: "output_tokens", }, }, }), }); ``` -------------------------------- ### Initializing StripeAgentToolkit with Account Context Source: https://github.com/stripe/agent-toolkit/blob/main/typescript/README.md Initializes the StripeAgentToolkit instance with a specific connected account ID in the configuration context. This allows subsequent API calls made through the toolkit to be performed on behalf of the specified account. ```typescript const stripeAgentToolkit = new StripeAgentToolkit({ secretKey: process.env.STRIPE_SECRET_KEY!, configuration: { context: { account: 'acct_123', }, }, }); ``` -------------------------------- ### Configuring Context in Toolkit (TypeScript) Source: https://github.com/stripe/agent-toolkit/blob/main/README.md Shows how to initialize the `StripeAgentToolkit` in TypeScript with a `context` configuration object. This is used to set default values, such as a connected `account` ID, for subsequent API calls made through the toolkit. ```typescript const stripeAgentToolkit = new StripeAgentToolkit({ secretKey: process.env.STRIPE_SECRET_KEY!, configuration: { context: { account: "acct_123", }, }, }); ``` -------------------------------- ### Integrating Stripe Metered Billing with Vercel AI SDK Source: https://github.com/stripe/agent-toolkit/blob/main/typescript/README.md Initializes the StripeAgentToolkit for Vercel's AI SDK and wraps an AI model with the toolkit's middleware. This middleware automatically submits billing events for input and output tokens based on the provided customer ID and meter names. ```typescript import {StripeAgentToolkit} from '@stripe/agent-toolkit/ai-sdk'; import {openai} from '@ai-sdk/openai'; import { generateText, experimental_wrapLanguageModel as wrapLanguageModel, } from 'ai'; const stripeAgentToolkit = new StripeAgentToolkit({ secretKey: process.env.STRIPE_SECRET_KEY!, configuration: { actions: { paymentLinks: { create: true, }, }, }, }); const model = wrapLanguageModel({ model: openai('gpt-4o'), middleware: stripeAgentToolkit.middleware({ billing: { customer: 'cus_123', meters: { input: 'input_tokens', output: 'output_tokens', }, }, }), }); ``` -------------------------------- ### Debugging Stripe MCP Server with MCP Inspector (Docker) Source: https://github.com/stripe/agent-toolkit/blob/main/modelcontextprotocol/README.md This Docker command runs the MCP Inspector and the Stripe MCP server within Docker containers. It maps necessary ports and mounts the Docker socket to allow the Inspector to manage the server container. `YOUR_STRIPE_SECRET_KEY` is required for server authentication. ```docker docker run -p 3000:3000 -p 5173:5173 -v /var/run/docker.sock:/var/run/docker.sock mcp/inspector docker run --rm -i mcp/stripe --tools=all --api-key=YOUR_STRIPE_SECRET_KEY ``` -------------------------------- ### Connecting to MCP Server for Testing with npx Inspector Source: https://github.com/stripe/agent-toolkit/blob/main/typescript/examples/cloudflare/README.md This command uses the `@modelcontextprotocol/inspector` tool via `npx` to connect to the local MCP server. It's used for testing and debugging the server's SSE (Server-Sent Events) endpoint, typically running on `http://localhost:4242/sse`. ```Shell npx @modelcontextprotocol/inspector@latest http://localhost:4242/sse ``` -------------------------------- ### Monetizing a Tool with PaidMcpAgent in TypeScript Source: https://github.com/stripe/agent-toolkit/blob/main/typescript/src/cloudflare/README.md This snippet shows how to convert a standard tool into a paid tool using `this.paidTool`. It requires a `priceId` from Stripe, a `successUrl` for redirection after payment, and a `paymentReason` string to explain the charge to the user. ```typescript this.paidTool( 'add_numbers', { a: z.number(), b: z.number(), }, ({a, b}) => { return { content: [{type: 'text', text: `Result: ${a + b}`}], }; }, { priceId: '{{PRICE_ID}}', successUrl: 'https://mcp.mysite.com/success', paymentReason: 'You must pay a subscription to add two big numbers together.', } ); ``` -------------------------------- ### Registering a Paid Tool with MCP Server (TypeScript) Source: https://github.com/stripe/agent-toolkit/blob/main/typescript/src/modelcontextprotocol/README.md This snippet demonstrates how to use the `registerPaidTool` function to integrate a paid tool, 'add_numbers', with an MCP server. It defines the tool's input schema, its callback logic, and specifies payment options including a Stripe price ID, success URL, email, payment reason, and Stripe secret key. This enables requiring payment for tool usage. ```TypeScript import {registerPaidTool} from './register-paid-tool'; import {McpServer} from '@modelcontextprotocol/sdk/server/mcp.js'; const server = new McpServer({ name: 'mcp-typescript server', version: '0.1.0', }); registerPaidTool( server, 'add_numbers', { a: z.number(), b: z.number(), }, ({a, b}) => { return { content: [{type: 'text', text: `Result: ${a + b}`}], }; }, { priceId: '{{PRICE_ID}}', successUrl: '{{CALLBACK_URL}}', email: '{{EMAIL}}', paymentReason: 'You must pay a subscription to add two big numbers together.', stripeSecretKey: '{{SECRET_KEY}}', } ); ``` -------------------------------- ### Deploying Stripe Secrets with Wrangler CLI Source: https://github.com/stripe/agent-toolkit/blob/main/typescript/examples/cloudflare/README.md These commands deploy critical Stripe API keys and price IDs as secrets to the Cloudflare Workers environment using the `wrangler secret put` command. This ensures sensitive information is securely stored and accessible to the deployed agent. ```Shell npx wrangler secret put STRIPE_SECRET_KEY npx wrangler secret put STRIPE_PRICE_ID_ONE_TIME_PAYMENT npx wrangler secret put STRIPE_ONETIME_SUBSCRIPTION_PRICE_ID npx wrangler secret put STRIPE_PRICE_ID_USAGE_BASED_SUBSCRIPTION ``` -------------------------------- ### Extending McpAgent with PaidMcpAgent in TypeScript Source: https://github.com/stripe/agent-toolkit/blob/main/typescript/src/cloudflare/README.md This TypeScript snippet demonstrates how to modify an existing MCP server to extend `PaidMcpAgent` instead of `McpAgent`. It imports `PaymentState` and `experimental_PaidMcpAgent`, and defines `Props` and `State` types for user email and payment state management. ```typescript import { PaymentState, experimental_PaidMcpAgent as PaidMcpAgent, } from '@stripe/agent-toolkit/cloudflare'; type Props = { userEmail: string; }; type State = PaymentState & {}; export class MyMCP extends PaidMcpAgent {} ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.