Connect with an MCP SDK

Talk to Swiggy MCP directly from a raw MCP client - open a Streamable HTTP session, list tools, call a tool, and read a widget - in TypeScript or Python.

If you're not using an agent framework, connect to Swiggy with a raw MCP client SDK. You open a Streamable HTTP session to a server endpoint, authenticate with OAuth 2.1, then call tools over standard JSON-RPC. For the framework route (OpenAI Agents, Vercel AI SDK, Mastra, and others), see Build an agent.

Pick a client SDK

Any conformant MCP client works - the protocol is interoperable across SDK versions over the wire, so you don't have to match the server's SDK. Common choices:

The snippets below assume you've wired the Authenticate flow and have one of:

  • swiggyOAuthProvider - your implementation of the MCP SDK's OAuthClientProvider interface (the SDK runs PKCE for you against Swiggy's discovery documents). On the first run there is no stored token, so connect() redirects to authorization and throws UnauthorizedError; catch it, call transport.finishAuth(code) with the code from your redirect URI, then build a new transport with the same provider (it now holds the tokens) and connect() that one - a transport can't be reused once it has started. See Authenticate. Or:
  • getSwiggyAccessToken() - a helper that returns a fresh Bearer token. A Bearer header passed this way is captured when the transport is created, so on a 401 fetch a new token and build a fresh transport (the authProvider option above avoids this - the SDK reads the token from your provider on each request and re-authorizes on a 401).

Open a session and call a tool

import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
import { swiggyOAuthProvider } from "./swiggy-oauth"; // implements OAuthClientProvider
 
// One session per server. Swap /food for /im, /dineout, or /scenes.
const transport = new StreamableHTTPClientTransport(
  new URL("https://mcp.swiggy.com/food"),
  { authProvider: swiggyOAuthProvider },
);
 
const client = new Client({ name: "my-agent", version: "1.0.0" });
await client.connect(transport); // runs initialize; first run: catch UnauthorizedError -> transport.finishAuth(code) -> connect() a fresh transport (same provider)
 
// Discover the tools available to the signed-in user.
const { tools } = await client.listTools();
 
// Call a tool. Arguments follow the tool's inputSchema (see the Reference).
const result = await client.callTool({
  name: "search_restaurants",
  arguments: { query: "biryani", addressId: "addr_01HXYZ" },
});

If your client can't use an authProvider, pass a Bearer token on the transport instead:

// This Authorization header is captured once, when the transport is created.
// On a 401, fetch a new token and build a new transport - re-running the helper
// alone won't update a transport that already has the old header.
const transport = new StreamableHTTPClientTransport(
  new URL("https://mcp.swiggy.com/food"),
  { requestInit: { headers: { Authorization: `Bearer ${await getSwiggyAccessToken()}` } } },
);

Read the result

Tool results arrive as MCP content. Read the structured payload from structuredContent, falling back to the JSON envelope in the first content block when that's missing or empty. The shape is tool-specific - see Read tool results and the per-tool Reference pages.

Widgets (optional)

Some tools reference a render-ready UI widget via _meta.ui.resourceUri (a ui://widget/... URI). Fetch the widget's HTML over the same session with the MCP resource methods:

const { resources } = await client.listResources();
// Read a widget from the SAME server its tool came from - here /food's get_food_cart.
const widget = await client.readResource({ uri: "ui://widget/food-cart.html" });

Widgets are registered per server, so a widget can only be read from the server whose tool returned its resourceUri. Reading a /food widget URI on an Instamart session (or vice versa) returns Unknown resource URI.

Clients that don't render widgets simply ignore _meta.ui and build their own UI from the tool's data. See Widgets for details.

Next