-
Notifications
You must be signed in to change notification settings - Fork 618
[Docs] Add MCP tool filtering, agent examples, and available tools list #8188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,87 @@ | ||||||
| import { Tabs, TabsList, TabsTrigger, TabsContent } from "@/components/ui/tabs"; | ||||||
| import { OpenApiEndpoint } from "@doc"; | ||||||
|
|
||||||
| # Agents | ||||||
|
|
||||||
| Easily create AI agents that can pay for any x402-compatible API calls. | ||||||
|
|
||||||
| ## Using the MCP Server | ||||||
|
|
||||||
| The easiest way to equip your agents with the ability to pay for API calls is to use the [remote MCP server](/ai/mcp) and provide the tools to your agent. | ||||||
|
|
||||||
| The MCP server comes with all the tools by default, but you can filter the tools available by passing multiple `tool` query parameter. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix grammatical error in tool filtering explanation. Same issue as in the MCP documentation: "passing multiple Apply this diff to fix the grammar: -The MCP server comes with all the tools by default, but you can filter the tools available by passing multiple `tool` query parameter.
+The MCP server comes with all the tools by default, but you can filter the tools available by passing multiple `tool` query parameters.📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
|
|
||||||
| In this example, we create a ReAct agent using LangChain and filter the MCP tools to `fetchWithPayment` and `getWalletBalance` as the only 2 tools we give our agent. You can view the full list of available tools [here](/ai/mcp#available-tools). | ||||||
|
|
||||||
| <Tabs defaultValue="typescript"> | ||||||
|
|
||||||
| <TabsList> | ||||||
| <TabsTrigger value="typescript">TypeScript</TabsTrigger> | ||||||
| <TabsTrigger value="python">Python</TabsTrigger> | ||||||
| </TabsList> | ||||||
|
|
||||||
| <TabsContent value="typescript"> | ||||||
|
|
||||||
| ```typescript | ||||||
| import { createReactAgent } from "@langchain/langgraph/prebuilt"; | ||||||
| import { MultiServerMCPClient } from "@langchain/mcp-adapters"; | ||||||
| import { ChatOpenAI } from "@langchain/openai"; | ||||||
|
|
||||||
| const model = new ChatOpenAI({ | ||||||
| model: "gpt-4.1", | ||||||
| }); | ||||||
|
|
||||||
| const mcpServers = { | ||||||
| thirdweb: { | ||||||
| url: `https://api.thirdweb.com/mcp?secretKey=<your-project-secret-key>&tool=fetchWithPayment&tool=getWalletBalance` | ||||||
| } | ||||||
| }; | ||||||
|
|
||||||
| // Connect to MCP servers and get tools | ||||||
| const client = new MultiServerMCPClient(mcpServers); | ||||||
| const tools = await client.getTools(); | ||||||
|
|
||||||
| const agent = createReactAgent({ | ||||||
| llm: model, | ||||||
| tools: tools, | ||||||
| prompt: "Use the fetchWithPayment tool to fetch any endpoint. Always pay in {{tokenAddress}}. Your wallet address is {{walletAddress}}." | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clarify template placeholder usage in agent prompts. Both TypeScript and Python examples include prompt templates with Users may be confused about:
Consider adding a brief explanation before or after the code examples, such as: Replace the template placeholders in the prompt:
- `{{tokenAddress}}`: The ERC-20 token contract address to use for payments (e.g., USDC on Base)
- `{{walletAddress}}`: Your wallet address (from user wallets or server wallets)Or if these are meant to be dynamic runtime values, clarify how the agent should resolve them. Also applies to: 67-67 |
||||||
| }); | ||||||
| ``` | ||||||
|
|
||||||
| </TabsContent> | ||||||
|
|
||||||
| <TabsContent value="python"> | ||||||
|
|
||||||
| ```python | ||||||
| from langchain_mcp_adapters.client import MultiServerMCPClient | ||||||
| from langgraph.prebuilt import create_react_agent | ||||||
|
|
||||||
| client = MultiServerMCPClient( | ||||||
| { | ||||||
| "thirdweb": { | ||||||
| "url": "https://api.thirdweb.com/mcp?secretKey=<your-project-secret-key>&tool=fetchWithPayment&tool=getWalletBalance", | ||||||
| } | ||||||
| } | ||||||
| ) | ||||||
| tools = await client.get_tools() | ||||||
| agent = create_react_agent("openai:gpt-4.1", tools, prompt="Use the fetchWithPayment tool to fetch any endpoint. Always pay in {{tokenAddress}}. Your wallet address is {{walletAddress}}.") | ||||||
| ``` | ||||||
|
|
||||||
| </TabsContent> | ||||||
| </Tabs> | ||||||
|
|
||||||
| ## Using the API directly | ||||||
|
|
||||||
| You can also create your own MCP tool or wrap all external calls with the `/v1/x402/fetchWithPayment` endpoint to automatically handle payment flows when APIs return a `402 Payment Required` response. | ||||||
|
|
||||||
| Pass the target `url`, `method` and optional `from` wallet address to the endpoint that will complete the payment. The address should be one of your [user wallets](/wallets/users) or [server wallets](/wallets/server). | ||||||
|
|
||||||
| ```bash | ||||||
| curl -X POST https://api.thirdweb.com/v1/payments/x402/fetch?url=https://api.example.com/premium&method=GET&from=0x1234... \ | ||||||
| -H "Content-Type: application/json" \ | ||||||
| -H "x-secret-key: <your-project-secret-key>" \ | ||||||
| -d '{ ... }' # optional request body passed through to the url called. | ||||||
| ``` | ||||||
|
|
||||||
| <OpenApiEndpoint path="/v1/payments/x402/fetch" method="POST" /> | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix grammatical error in tool filtering explanation.
"passing multiple
toolquery parameter" should be "passing multipletoolquery parameters" (plural form).Apply this diff to fix the grammar:
📝 Committable suggestion
🤖 Prompt for AI Agents