← All posts

Building a Stripe-Fluent Claude Agent in 50 Lines of Python

How to connect Claude 3.5 Sonnet to Stripe APIs securely using the Model Context Protocol (MCP) and wmcp.sh.

2026-05-27

The Financial Agent Bottleneck

If you are a developer building a customer support bot or internal operations tool, one of the most common requests is: "Can the AI agent check my Stripe invoices?" or "Can the agent look up a customer subscription status?"

Traditionally, fulfilling this request required building a heavy backend integration.

You had to install the official Stripe SDK, write custom endpoint wrappers, translate Stripe's complex nested object schemas (e.g. Customer, Subscription, Invoice) into simplified flat JSON structures, and then write explicit system instructions to teach the LLM when and how to invoke these functions.

This approach is highly labor-intensive, hard to maintain, and insecure.

But with the arrival of the Model Context Protocol (MCP) and wmcp.sh, you can build a highly secure, billing-fluent Claude agent in under 50 lines of Python.

By delegating the API-to-Tool mapping to a hosted edge gateway, your agent dynamically fetches the Stripe tool schemas on the fly and routes execution requests securely without exposing master keys to the LLM context.

Below, we will walk through a production-ready implementation of a Stripe-fluent Claude agent.


The Security Paradigm Shift

Before writing code, it is critical to address security.

Never store plain-text Stripe API keys inside your agent’s main configuration file or let the LLM see the raw credentials. If the agent is compromised by a prompt injection attack, the attacker can command the LLM to dump its environmental variables, leaking your keys.

To safeguard your financial data, we utilize PKCE Token Isolation Proxying at wmcp.sh.

Your agent server never holds the raw Stripe secret key. Instead, the keys are vaulted in a hardware-isolated credentials environment. The gateway proxy issues your local agent a temporary session token.

When the agent wants to perform an action (like list_invoices), the payload is signed and routed through the proxy, which executes the request and returns only the sanitized JSON data body back to the agent.


50 Lines of Stripe-Fluent Python

Below is the complete, runnable Python script that implements our Stripe-fluent Claude agent.

It imports the official Anthropic SDK, queries the hosted wmcp.sh Stripe adapter to fetch the clean MCP tools schema, binds the tools to Claude 3.5 Sonnet, and executes the transactional billing actions in a secure orchestration loop:

import json
import os
import requests
from anthropic import Anthropic

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

class StripeFluentAgent:
    def __init__(self, gateway_url: str = "https://wmcp.sh/api/v1"):
        self.gateway_url = gateway_url

    def fetch_stripe_tools(self) -> list:
        """Fetch standardized MCP schemas for Stripe dynamically from wmcp.sh."""
        r = requests.get(f"{self.gateway_url}/tools", params={"url": "https://wmcp.sh/integration/stripe"}, timeout=6)
        if r.status_code != 200:
            raise RuntimeError(f"Failed to fetch Stripe MCP tool schemas: {r.text}")
            
        # Translate to Anthropic tool definitions format
        raw_tools = r.json().get("tools", [])
        return [
            {
                "name": t["name"],
                "description": t["description"],
                "input_schema": t.get("inputSchema", {"type": "object", "properties": {}})
            } for t in raw_tools
        ]

    def query(self, prompt: str) -> str:
        """Run the Stripe-fluent orchestration loop."""
        stripe_tools = self.fetch_stripe_tools()
        
        # 1. Ask Claude to plan and pick the correct Stripe tool
        message = client.messages.create(
            model="claude-3-5-sonnet-20241022",
            max_tokens=800,
            temperature=0.0,
            tools=stripe_tools,
            messages=[{"role": "user", "content": prompt}]
        )

        # 2. Intercept Tool Use call
        if message.stop_reason == "tool_use":
            tool_use = message.content[-1]
            tool_name = tool_use.name
            tool_args = tool_use.input
            
            print(f"[Tool Execution] Model calling: {tool_name} with: {tool_args}")
            
            # Execute tool securely via our out-of-band proxy
            res = requests.post(
                f"{self.gateway_url}/tools/execute",
                json={"url": "https://wmcp.sh/integration/stripe", "tool": tool_name, "arguments": tool_args},
                headers={"Content-Type": "application/json"},
                timeout=10
            )
            
            if res.status_code == 200:
                # Return the clean API results back to Claude for final summarization
                summary_message = client.messages.create(
                    model="claude-3-5-sonnet-20241022",
                    max_tokens=800,
                    messages=[
                        {"role": "user", "content": prompt},
                        {"role": "assistant", "content": message.content},
                        {"role": "user", "content": f"Tool Result: {json.dumps(res.json())}"}
                    ]
                )
                return summary_message.content[0].text
            return f"Failed to execute tool: {res.text}"
            
        return message.content[0].text

# Local billing check
if __name__ == "__main__":
    agent = StripeFluentAgent()
    # Query Stripe dynamically using natural language
    print("Stripe-fluent Claude agent initialized. Querying invoices...")
    # response = agent.query("Show me the total billing volume for May 2026 and highlight unpaid invoices.")
    # print(response)

Under the Hood: The Schema Translation

When you query https://wmcp.sh/integration/stripe using the script above, the wmcp.sh Worker fetches Stripe's public OpenAPI specification and instantly generates standardized MCP tool schemas, exposing endpoints like:

Because the tool definitions are generated at the edge, your local agent code remains clean, short, and completely decoupled from Stripe's internal API libraries. If Stripe releases a new API version, wmcp.sh handles the schema update out-of-band without requiring a local code refactor.


Stop Writing Glue Code

Building internal tools shouldn't mean wasting weeks writing custom JSON translation wrappers and SDK handlers.

By leveraging the Model Context Protocol and hosted edge gateways like wmcp.sh, you can build billing-fluent, production-ready Claude assistants in minutes, keeping your code clean and your financial data completely secure.

Adopt the MCP standard, decouple your API configurations, and help build the future of frictionless, agentic automation today.

Want this implemented on your stack? Custom adapter + hosted MCP + verified directory listing. From $499 one-time setup.
See /managed → Submit (free)