Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions apps/dashboard/src/app/pay/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from "@/constants/server-envs";
import { getConfiguredThirdwebClient } from "@/constants/thirdweb.server";
import { PayPageWidget } from "../components/client/PayPageWidget.client";
import { onlyUrl } from "../url-validation";
import { PayIdPageHeader } from "./header";

const title = "thirdweb Pay";
Expand All @@ -29,10 +30,16 @@ export default async function PayPage({
searchParams,
}: {
params: Promise<{ id: string }>;
searchParams: Promise<{ redirectUri?: string; theme?: "light" | "dark" }>;
searchParams: Promise<{
redirectUri?: string | string[];
theme?: "light" | "dark";
}>;
}) {
const { id } = await params;
const { redirectUri, theme } = await searchParams;
const { redirectUri: rawRedirectUri, theme } = await searchParams;
// only http(s) URLs with a hostname; anything else (javascript:, data:, relative, repeated param) is dropped
const redirectUri =
typeof rawRedirectUri === "string" ? onlyUrl(rawRedirectUri) : undefined;

const paymentLink = await getPaymentLink({
paymentId: id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ export function PayPageWidget({

if (!redirectUri) return;
const url = new URL(redirectUri);
return window.open(url.toString());
if (url.protocol !== "http:" && url.protocol !== "https:") return;
return window.open(url.toString(), "_blank", "noopener,noreferrer");
}}
onError={(error) => {
reportPaymentLinkBuyFailed({
Expand Down
25 changes: 1 addition & 24 deletions apps/dashboard/src/app/pay/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ThemeProvider } from "next-themes";
import { defineChain, isAddress } from "thirdweb";
import { PayLandingHeader } from "./landing/header";
import { StyledBuyWidget } from "./landing/styled-buy-widget";
import { onlyUrl } from "./url-validation";

const title = "thirdweb Payments";
const description = "Fast, secure, and simple payments.";
Expand All @@ -25,30 +26,6 @@ const onlyAddress = (v: string) => (isAddress(v) ? v : undefined);
const onlyNumber = (v: string) =>
Number.isNaN(Number(v)) ? undefined : Number(v);

/**
* Validates and normalizes a URL string.
* Only allows http: and https: protocols with a valid hostname.
* @returns normalized URL string on success, undefined on failure
*/
const onlyUrl = (v: string): string | undefined => {
try {
const url = new URL(v);
// Only allow http or https protocols
if (url.protocol !== "http:" && url.protocol !== "https:") {
return undefined;
}
// Ensure hostname is non-empty
if (!url.hostname) {
return undefined;
}
// Return normalized URL
return url.toString();
} catch {
// Invalid URL format
return undefined;
}
};

export default async function PayPage(props: {
searchParams: Promise<SearchParams>;
}) {
Expand Down
23 changes: 23 additions & 0 deletions apps/dashboard/src/app/pay/url-validation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Validates and normalizes a URL string.
* Only allows http: and https: protocols with a valid hostname.
* @returns normalized URL string on success, undefined on failure
*/
export const onlyUrl = (v: string): string | undefined => {
try {
const url = new URL(v);
// Only allow http or https protocols
if (url.protocol !== "http:" && url.protocol !== "https:") {
return undefined;
}
// Ensure hostname is non-empty
if (!url.hostname) {
return undefined;
}
// Return normalized URL
return url.toString();
} catch {
// Invalid URL format
return undefined;
}
};
47 changes: 34 additions & 13 deletions apps/portal/src/app/ai/mcp/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@ You can use the thirdweb MCP server to interact with the thirdweb API from your

## Remote MCP endpoint

You can access the MCP server at the following url, with your project secret key.
You can access the MCP server at the following url. Send your project secret key in the `x-secret-key` header.

```http
https://api.thirdweb.com/mcp?secretKey=<your-project-secret-key>
https://api.thirdweb.com/mcp
x-secret-key: <your-project-secret-key>
```

Make sure to keep your secret key safe and never share it with anyone.

If your client cannot send custom headers, you can pass the key as a query parameter instead: `https://api.thirdweb.com/mcp?secretKey=<your-project-secret-key>`. Prefer the header where you can: a key in a URL can end up in logs, browser history and config files.

By default, all tools are available. You can filter the tools available by passing a comma-separated list of tools as a query parameter.

```http
https://api.thirdweb.com/mcp?secretKey=<your-project-secret-key>&tools=fetchWithPayment,getWalletBalance
https://api.thirdweb.com/mcp?tools=fetchWithPayment,getWalletBalance
x-secret-key: <your-project-secret-key>
```

You can find all available tools at the bottom of this page.
Expand All @@ -46,7 +50,10 @@ import { MultiServerMCPClient } from "@langchain/mcp-adapters";

const mcpServers = {
thirdweb: {
url: `https://api.thirdweb.com/mcp?secretKey=<your-project-secret-key>`
url: "https://api.thirdweb.com/mcp",
headers: {
"x-secret-key": "<your-project-secret-key>",
},
}
};

Expand All @@ -72,7 +79,11 @@ from langgraph.prebuilt import create_react_agent
client = MultiServerMCPClient(
{
"thirdweb": {
"url": "https://api.thirdweb.com/mcp?secretKey=<your-project-secret-key>",
"transport": "http",
"url": "https://api.thirdweb.com/mcp",
"headers": {
"x-secret-key": "<your-project-secret-key>",
},
}
}
)
Expand Down Expand Up @@ -107,7 +118,7 @@ You can also use the MCP server on your own LLM client, like cursor, claude code
className="flex items-center gap-3 bg-card mb-4 justify-start w-fit shadow-md hover:shadow-lg transition-shadow border-2"
variant="outline"
>
<Link href="cursor://anysphere.cursor-deeplink/mcp/install?name=thirdweb-api&config=eyJ1cmwiOiJodHRwczovL2FwaS50aGlyZHdlYi5jb20vbWNwP3NlY3JldEtleT1ZT1VSX1NFQ1JFVF9LRVlfSEVSRSJ9" className="flex items-center gap-3">
<Link href="cursor://anysphere.cursor-deeplink/mcp/install?name=thirdweb-api&config=eyJ1cmwiOiJodHRwczovL2FwaS50aGlyZHdlYi5jb20vbWNwIiwiaGVhZGVycyI6eyJ4LXNlY3JldC1rZXkiOiJZT1VSX1NFQ1JFVF9LRVlfSEVSRSJ9fQ==" className="flex items-center gap-3">
<ArrowDownIcon className="size-4 flex-shrink-0" />
<span>Install into Cursor</span>
</Link>
Expand All @@ -119,7 +130,10 @@ Add the following to your `.cursor/mcp.json` file (replace `YOUR_SECRET_KEY_HERE
{
"mcpServers": {
"thirdweb-api": {
"url": "https://api.thirdweb.com/mcp?secretKey=YOUR_SECRET_KEY_HERE"
"url": "https://api.thirdweb.com/mcp",
"headers": {
"x-secret-key": "YOUR_SECRET_KEY_HERE"
}
}
}
}
Expand All @@ -129,13 +143,16 @@ Add the following to your `.cursor/mcp.json` file (replace `YOUR_SECRET_KEY_HERE

<TabsContent value="windsurf">

Add the following to your `~/.codeium/windsurf/mcp_config.json` file:
Add the following to your `~/.codeium/windsurf/mcp_config.json` file (replace `YOUR_SECRET_KEY_HERE` with your thirdweb secret key):

```json
{
"mcpServers": {
"thirdweb-api": {
"url": "https://api.thirdweb.com/mcp?secretKey=YOUR_SECRET_KEY_HERE"
"serverUrl": "https://api.thirdweb.com/mcp",
"headers": {
"x-secret-key": "YOUR_SECRET_KEY_HERE"
}
}
}
}
Expand All @@ -150,7 +167,7 @@ Add the following to your `~/.codeium/windsurf/mcp_config.json` file:
className="flex items-center gap-3 bg-card mb-4 justify-start w-fit shadow-md hover:shadow-lg transition-shadow border-2"
variant="outline"
>
<Link href="https://vscode.dev/redirect/mcp/install?name=thirdweb-api&config=%7B%22type%22%3A%22http%22%2C%22url%22%3A%22https%3A%2F%2Fapi.thirdweb.com%2Fmcp%22%2C%22secret%22%3A%22YOUR_SECRET%22%7D" className="flex items-center gap-3" target="_blank" rel="noopener noreferrer">
<Link href="https://vscode.dev/redirect/mcp/install?name=thirdweb-api&config=%7B%22type%22%3A%22http%22%2C%22url%22%3A%22https%3A%2F%2Fapi.thirdweb.com%2Fmcp%22%2C%22headers%22%3A%7B%22x-secret-key%22%3A%22YOUR_SECRET_KEY_HERE%22%7D%7D" className="flex items-center gap-3" target="_blank" rel="noopener noreferrer">
<ArrowDownIcon className="size-4 flex-shrink-0" />
<span>Install into VS Code</span>
</Link>
Expand All @@ -160,9 +177,13 @@ Add the following to your VS Code `.vscode/mcp.json` file (replace `YOUR_SECRET_

```json
{
"mcp.servers": {
"servers": {
"thirdweb-api": {
"url": "https://api.thirdweb.com/mcp?secretKey=YOUR_SECRET_KEY_HERE"
"type": "http",
"url": "https://api.thirdweb.com/mcp",
"headers": {
"x-secret-key": "YOUR_SECRET_KEY_HERE"
}
}
}
}
Expand All @@ -175,7 +196,7 @@ Add the following to your VS Code `.vscode/mcp.json` file (replace `YOUR_SECRET_
Run the following command to add the MCP server to your Claude Code configuration (replace `YOUR_SECRET_KEY_HERE` with your thirdweb secret key):

```bash
claude mcp add --transport http "thirdweb-api" "https://api.thirdweb.com/mcp?secretKey=YOUR_SECRET_KEY_HERE"
claude mcp add --transport http "thirdweb-api" "https://api.thirdweb.com/mcp" --header "x-secret-key: YOUR_SECRET_KEY_HERE"
```

</TabsContent>
Expand Down
13 changes: 11 additions & 2 deletions apps/portal/src/app/x402/agents/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ The MCP server comes with all the tools by default, but you can filter the tools

In this example, we create a ReAct agent using LangChain and filter the MCP tools to `fetchWithPayment` and `listPayableServices` as the only 2 tools we give our agent. You can view the full list of available tools [here](/ai/mcp#available-tools).

Your project secret key goes in the `x-secret-key` header. Only if your client cannot send custom headers, pass it as a `secretKey` query parameter instead; a key in a URL can end up in logs and config files.

<Tabs defaultValue="typescript">

<TabsList>
Expand All @@ -42,7 +44,10 @@ const model = new ChatOpenAI({

const mcpServers = {
thirdweb: {
url: `https://api.thirdweb.com/mcp?secretKey=<your-project-secret-key>&tools=fetchWithPayment,listPayableServices`
url: "https://api.thirdweb.com/mcp?tools=fetchWithPayment,listPayableServices",
headers: {
"x-secret-key": "<your-project-secret-key>",
},
}
};

Expand All @@ -68,7 +73,11 @@ from langgraph.prebuilt import create_react_agent
client = MultiServerMCPClient(
{
"thirdweb": {
"url": "https://api.thirdweb.com/mcp?secretKey=<your-project-secret-key>&tools=fetchWithPayment,listPayableServices",
"transport": "http",
"url": "https://api.thirdweb.com/mcp?tools=fetchWithPayment,listPayableServices",
"headers": {
"x-secret-key": "<your-project-secret-key>",
},
}
}
)
Expand Down
Loading