Skip to content

Connect Razorpay to ChatGPT: Sync Payments, Invoices & Subscriptions

Learn how to build a managed MCP server for Razorpay to connect it natively to ChatGPT. Automate payments, issue invoices, and sync settlement data securely.

Uday Gajavalli Uday Gajavalli · · 10 min read
Connect Razorpay to ChatGPT: Sync Payments, Invoices & Subscriptions

If you need to connect Razorpay to ChatGPT to automate payment reconciliation, subscription management, or invoicing workflows, you need a Model Context Protocol (MCP) server. This server acts as the translation layer between ChatGPT's JSON-RPC tool calls and Razorpay's REST APIs. You can either spend weeks building, hosting, and maintaining a custom MCP server, or use a managed integration infrastructure to dynamically generate a secure, authenticated MCP server URL.

If your team uses Claude, check out our guide on connecting Razorpay to Claude or explore our broader architectural overview on connecting Razorpay to AI Agents.

Giving a Large Language Model (LLM) read and write access to a critical financial ecosystem like Razorpay is an engineering challenge. You have to handle API authentication, map massive JSON schemas to MCP tool definitions, deal with state machine transitions, and carefully manage rate limits to prevent hallucinations. Every time an endpoint updates, you have to update your server code, redeploy, and test the integration. This guide breaks down exactly how to use Truto to generate a secure, managed MCP server for Razorpay, connect it natively to ChatGPT, and execute complex workflows using natural language.

The Engineering Reality of the Razorpay API

A custom MCP server is a self-hosted integration layer. While the open MCP standard provides a predictable way for models to discover tools, the reality of implementing it against Razorpay's API is painful. If you decide to build a custom MCP server, you own the entire API lifecycle. Here are the specific integration challenges that break standard CRUD assumptions when working with Razorpay:

The Unix Timestamp Pagination Trap Unlike modern APIs that rely on opaque cursor strings or simple page limits, Razorpay relies heavily on UNIX epoch timestamps (from and to) for its list endpoints. If an LLM needs to fetch all payments from the last 30 days, it cannot just pass a natural language date string. It must generate accurate UNIX timestamps. If your MCP server does not expose these query schema requirements perfectly, the LLM will hallucinate invalid date formats, causing the API request to fail silently or return a 400 Bad Request.

Strict Entity State Machines Financial APIs do not operate like simple databases. You cannot simply "create" a payable invoice with a single request. Razorpay enforces strict state machines. An invoice is created in a draft state. Before a customer can pay it, a secondary POST request must be made to an /issue endpoint. Subscriptions follow a similar complex lifecycle (created, authenticated, active). An LLM needs explicit, distinct tools for each state transition, not just generic update methods.

Rate Limits and The 429 Reality Razorpay enforces strict limits based on concurrent connections and endpoint specific quotas. When an LLM aggressively loops through historical order or settlement data, it will hit rate limits. Truto does not retry, throttle, or apply backoff on rate limit errors. When the upstream API returns an HTTP 429, Truto passes that error directly to the caller. Truto normalizes upstream rate limit info into standardized headers (ratelimit-limit, ratelimit-remaining, ratelimit-reset) per the IETF specification. Your AI agent or client application is strictly responsible for reading these headers and executing its own retry and exponential backoff logic. If your system ignores these, the LLM will assume the tool call succeeded when it actually failed.

Generating the Managed MCP Server

Instead of building this infrastructure from scratch, Truto dynamically derives MCP tools from Razorpay's documentation records and endpoint definitions. Tools are only generated if they pass an internal quality gate - meaning only well-documented, schema-validated endpoints are exposed to the LLM.

You can generate an MCP server for Razorpay using either the Truto UI or the API.

Method 1: Via the Truto UI

For teams managing integrations manually, the UI provides a quick configuration path:

  1. Navigate to the Integrated Accounts page in your Truto dashboard and select your connected Razorpay account.
  2. Click the MCP Servers tab.
  3. Click Create MCP Server.
  4. Select your desired configuration. You can restrict the server to specific HTTP methods (e.g., only read operations) or apply tag filters to limit access to specific resources like invoices or payments.
  5. Click Save and copy the generated MCP server URL.

Method 2: Via the API

For engineering teams building programmatic, multi-tenant workflows, you can generate MCP servers programmatically. This validates that tools are available, generates a secure cryptographic token, stores the state in distributed KV storage, and returns a ready-to-use URL.

Make an authenticated POST request to the /integrated-account/:id/mcp endpoint:

curl -X POST https://api.truto.one/integrated-account/<razorpay_account_id>/mcp \
  -H "Authorization: Bearer <YOUR_TRUTO_API_TOKEN>" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Razorpay Finance Ops Agent",
    "config": {
      "methods": ["read", "write", "custom"]
    },
    "expires_at": "2026-12-31T23:59:59Z"
  }'

The API returns a payload containing the secure URL. This URL is self-contained and authenticates the downstream requests automatically:

{
  "id": "mcp_abc123",
  "name": "Razorpay Finance Ops Agent",
  "config": {
    "methods": ["read", "write", "custom"]
  },
  "expires_at": "2026-12-31T23:59:59Z",
  "url": "https://api.truto.one/mcp/a1b2c3d4e5f67890"
}

Connecting the MCP Server to ChatGPT

Once you have the Truto MCP URL, you need to register it as a tool server. Communication happens over HTTP POST using the JSON-RPC 2.0 specification.

Method A: Via the ChatGPT UI

If you are using ChatGPT Enterprise, Pro, or Team accounts, you can add the server directly via the interface:

  1. Open ChatGPT and navigate to Settings -> Apps -> Advanced settings.
  2. Enable Developer mode (MCP support is gated behind this setting).
  3. Under MCP servers / Custom connectors, click to add a new server.
  4. Name: Enter a descriptive label like "Razorpay Finance Hub".
  5. Server URL: Paste the https://api.truto.one/mcp/<token> URL you generated above.
  6. Click Save. ChatGPT will immediately perform the initialize handshake and ingest the Razorpay tools.

Method B: Via Manual Config File

If you are running local agents, desktop clients, or custom LangChain/LangGraph pipelines, you can connect the server via an SSE (Server-Sent Events) transport. You will use the official @modelcontextprotocol/server-sse package.

Create a configuration JSON file (e.g., mcp-config.json):

{
  "mcpServers": {
    "razorpay_truto": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-sse",
        "--url",
        "https://api.truto.one/mcp/<token>"
      ]
    }
  }
}

When your agent starts, it launches this process, connecting to the remote Truto infrastructure and automatically mapping the Razorpay endpoints into the local context.

Hero Tools for Razorpay

When the agent connects, the MCP router dynamically builds tool definitions derived from integration documentation. These tools abstract away URL parameters, query strings, and raw HTTP methods, presenting the LLM with a single flat input namespace.

Here are the highest-leverage tools available for Razorpay.

list_all_razorpay_payments

This tool retrieves a list of all payments. It supports crucial query schemas like from and to (UNIX timestamps), allowing the agent to filter transaction history. It returns the payment ID, amount, currency, status, method, and refund statuses.

Contextual note: An AI agent reconciling accounts will frequently use this tool. You must instruct the agent to utilize the cursor output (next_cursor) for pagination.

"Fetch all Razorpay payments from the last 7 days. Paginate through the results and calculate the total amount of successfully captured payments made via UPI."

get_single_razorpay_subscription_by_id

Retrieves detailed metrics for a specific subscription. It returns the plan ID, current status, billing cycle data, and remaining payment counts.

Contextual note: This is essential for SaaS account management workflows where an agent needs to determine if a user is in a suspended or halted state due to a failed charge.

"Look up the subscription details for sub_XYZ123. Tell me when the next charge is scheduled, how many payment attempts have failed, and what the current status is."

create_a_razorpay_order

Creates a new order in Razorpay. Every payment in Razorpay must be linked to an order. The tool accepts amount, currency, and receipt notes.

Contextual note: LLMs must pass the amount in the smallest currency sub-unit (e.g., paise for INR, meaning 100 INR is sent as 10000).

"Generate a new Razorpay order for customer email test@example.com for 5000 INR. Add a receipt note stating 'Annual License Renewal'. Return the created Order ID."

create_a_razorpay_invoice

Creates a draft invoice. It requires a customer_id and accepts nested line items, tax details, and currency configurations.

Contextual note: Creating an invoice does not send it. It strictly remains in a draft state. The agent must use the issue tool subsequently if the goal is to finalize the billing.

"Draft a new invoice for customer cust_ABC890. Add a line item for 'Consulting Hours' with a unit amount of 10000 INR and quantity of 5. Leave it in draft state for manual review."

razorpay_invoices_issue

Executes the state transition to finalize and issue a draft invoice to a customer. It requires the specific invoice ID.

Contextual note: This is a custom method in Truto's proxy API layer, mapping explicitly to Razorpay's /invoices/:id/issue endpoint.

"The sales manager approved the draft invoice inv_DEF456. Go ahead and execute the tool to issue this invoice to the customer so they can pay it."

create_a_razorpay_refund

Initiates a refund for a previously captured payment. Requires the payment_id and optionally accepts an amount (for partial refunds) and a speed preference (normal or optimum).

Contextual note: Customer support agents leverage this to execute refunds directly from natural language prompts without logging into the Razorpay dashboard.

"The customer for payment pay_LMN789 requested a cancellation. Process a full refund for this payment using the normal speed routing."

list_all_razorpay_settlement_recon

Fetches a detailed list of transactions settled to your bank account for a specific year, month, and day. It returns entity types, debits, credits, fees, taxes, and the settlement UTR.

Contextual note: This is the holy grail for autonomous finance operations, allowing agents to map individual payments and refunds to bulk bank deposits.

"Pull the settlement reconciliation report for October 15th, 2026. Identify any transactions where the fee percentage exceeded 2% and list the associated order IDs."

To view the complete JSON schemas, required properties, and the full list of available tools, refer to the Razorpay integration page.

Workflows in Action

Exposing individual endpoints is just the foundation. The real power of an MCP server is orchestrating multi-step workflows where the LLM passes state between different Razorpay tools.

Scenario 1: Autonomous Customer Support Refunds

Customer support platforms often lack direct billing access. When an enterprise customer asks for a partial refund, the AI agent can execute the investigation and the refund autonomously.

"A customer emailed complaining about order order_XYZ123. They were overcharged by 500 INR. Find the payment associated with this order and process a partial refund for 500 INR."

Execution flow:

  1. list_all_razorpay_order_payments: The agent passes the order ID to retrieve all payment attempts. It identifies the successful (captured: true) payment ID.
  2. create_a_razorpay_refund: The agent takes the extracted payment ID and executes a partial refund, explicitly passing 50000 (paise) into the amount field.
  3. Result: The agent replies to the user: "I located payment pay_ABC and successfully issued a partial refund of 500 INR. The refund ID is rfnd_DEF."

Scenario 2: B2B Invoicing Operations

Sales reps often close a deal but forget to issue the invoice, delaying revenue capture. An AI agent can monitor deal states and manage the invoice lifecycle end-to-end.

"We just closed a deal with customer ID cust_QWERTY for a 'Premium SaaS Tier' at 150000 INR. Create the invoice, add the line item, and immediately issue it so they receive the payment link."

Execution flow:

  1. create_a_razorpay_invoice: The agent constructs the complex JSON payload, passing the customer_id and nested line_items array. Razorpay returns an invoice ID in draft state.
  2. razorpay_invoices_issue: Recognizing that the prompt demanded immediate issuance, the agent calls the issue tool with the newly created invoice ID.
  3. Result: The agent returns the generated short_url (payment link) to the prompt interface, confirming the state transition was successful.

Security and Access Control

Granting an LLM write access to a financial system requires strict governance. Truto provides several architectural layers to secure your MCP server:

  • Method Filtering: When generating the server token, you can restrict operations by passing config.methods: ["read"]. This drops all create, update, delete, and custom tools, guaranteeing the AI agent can only query data (e.g., viewing payments) without mutating state.
  • Tag Filtering: You can scope the server to specific operational domains using config.tags: ["invoices"]. The server will dynamically prune any tools unrelated to invoicing, reducing the risk of the agent accidentally modifying QR codes or webhooks.
  • Secondary Authentication (require_api_token_auth): By default, possessing the MCP URL grants access. By setting require_api_token_auth: true, the MCP client must also pass a valid Truto API token in the Authorization header. This ensures that even if the URL leaks in application logs, it remains secure.
  • TTL Expiration (expires_at): You can generate ephemeral servers by setting an ISO datetime expiration. Once the time is reached, cloud infrastructure automatically schedules a cleanup alarm, purging the token from distributed KV storage and terminating server access immediately.

Architecting for Financial Scale

Connecting an AI agent to Razorpay via custom integration scripts inevitably leads to fragile code. Handling UNIX timestamp conversion, managing cursor pagination for large settlement reports, constructing nested invoice schemas, and writing explicit error handling for 429 rate limits drain engineering cycles.

Using a managed MCP layer shifts this burden to configuration. By deriving JSON-RPC tool definitions directly from standardized integration schemas, your agents get reliable, strictly typed access to Razorpay. You dictate the exact read/write scope via method filters, and the infrastructure ensures the agent speaks Razorpay's specific dialect of REST.

FAQ

How do I give ChatGPT access to my Razorpay account?
You can connect ChatGPT to Razorpay using a Model Context Protocol (MCP) server. Truto generates a secure, hosted MCP server URL that maps Razorpay's REST endpoints into AI-readable tools, which you add to ChatGPT as a custom connector.
Does Truto handle Razorpay API rate limit errors automatically?
No. When the Razorpay API returns an HTTP 429 Too Many Requests error, Truto passes that error directly back to the calling agent. Truto normalizes the upstream rate limit information into standard IETF headers (ratelimit-limit, ratelimit-remaining, ratelimit-reset). Your AI agent or client application is responsible for executing retry and exponential backoff logic.
Can I restrict what an AI agent can do in Razorpay?
Yes. When creating the MCP server, you can apply method filtering (e.g., restricting access to only 'read' operations) and tag filtering to scope access down to specific resources like payments or invoices.
How are complex API payloads handled when ChatGPT calls Razorpay tools?
The MCP server flattens the input namespace. ChatGPT passes a single flat arguments object, and the server dynamically splits these into query parameters and body payloads based on the underlying OpenAPI schemas derived from integration documentation.

More from our Blog