Guide · Code

How to build a Stripe Agent.

Write a Python agent in under 50 lines that lists invoices and customers. By piping Stripe's OpenAPI spec through wmcp.sh, Claude natively understands the Stripe API as Model Context Protocol (MCP) tools.

Instead of writing custom Python wrapper classes for every Stripe endpoint, you can provide Claude with dynamically generated MCP tools. wmcp.sh ingests the public Stripe OpenAPI specification and translates it into strict MCP-compliant schemas in milliseconds.

50 lines to agentic Stripe.

Using the official anthropic SDK and httpx, we first fetch the available Stripe tools from wmcp.sh. Then, we let Claude decide which tool to call based on the user's prompt.

import os
import json
import httpx
from anthropic import Anthropic

# 1. Initialize Anthropic client
client = Anthropic(api_key=os.environ.get("ANTHROPIC_API_KEY"))

# 2. Fetch Stripe MCP tools dynamically via wmcp.sh
# We filter by tag "Invoices" to keep the context window small.
wmcp_url = "https://wmcp.sh/api/v1/tools?url=https://raw.githubusercontent.com/stripe/openapi/master/openapi/spec3.json&tag=Invoices"
response = httpx.get(wmcp_url)
tools = response.json().get("tools", [])

# 3. Create the chat completion
prompt = "Please list the latest 3 invoices for customer 'cus_123'."
messages = [{"role": "user", "content": prompt}]

message = client.messages.create(
    model="claude-3-7-sonnet-20250219",
    max_tokens=1024,
    tools=tools,
    messages=messages
)

# 4. Handle the tool call
if message.stop_reason == "tool_use":
    tool_use = message.content[1]
    print(f"Agent chose tool: {tool_use.name}")
    print(f"With arguments: {json.dumps(tool_use.input, indent=2)}")
    
    # In a full agent, you would now execute this against Stripe API directly:
    # result = httpx.get("https://api.stripe.com/v1/invoices", params=tool_use.input, auth=(STRIPE_KEY, ""))
    # Then return the tool_result back to Claude to complete the loop.

Handling API Keys.

Notice that we do not pass the STRIPE_SECRET_KEY to the LLM. The agent only knows the shape of the tools and decides the input parameters (like customer="cus_123"). The actual execution happens locally in your Python environment. Alternatively, if you use wmcp.sh as a managed gateway, you can utilize our encrypted credentials vault for secure static key storage.

Disclaimer: wmcp.sh is not affiliated with Stripe, Anthropic, or OpenAI. All product names and brands are property of their respective owners.
Need this done for you?

Skip the wiring — we build, deploy, and monitor.

Custom adapter + hosted MCP at mcp.yourbrand.com + verified badge. From $499 one-time setup.

See /managed → Submit (free)