View a markdown version of this page

通过网关进行 Coinbase 集市 AgentCore - Amazon Bedrock AgentCore
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)。

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

通过网关进行 Coinbase 集市 AgentCore

AgentCore 网关允许您连接到付费 MCP 服务器和 API 终端节点。你可以将Coinbase x402 Bazaar MCP服务器作为目标添加到网关中,以发现支持x402微交易的10,000多种现有付费MCP工具。

  • 服务器 URL — https://api.cdp.coinbase.com/platform/v2/x402/discovery/mcp

  • 接受出站身份验证类型-无授权(默认)

将 Coinbase x402 Bazaar MCP 服务器添加到网关

例
Console
  1. 导航到 “目标” 部分。

  2. (可选)更改生成的目标名称。

  3. (可选)提供目标描述。

  4. 对于目标类型,选择集成。

  5. 选择 Coinbase x402 Bazaar。

  6. 跳过出站身份验证配置。“无授权” 是唯一支持的选项,默认情况下处于选中状态。

AgentCore CLI
agentcore add gateway-target \ --name CoinbaseTarget \ --type mcp-server \ --endpoint https://api.cdp.coinbase.com/platform/v2/x402/discovery/mcp \ --gateway MyGateway agentcore deploy
Amazon SDK
import boto3 agentcore_client = boto3.client('bedrock-agentcore-control') target = agentcore_client.create_gateway_target( gatewayIdentifier="your-gateway-id", name="Coinbasex402BazaarTarget", description="Coinbase x402 Bazaar MCP server for paid API discovery", targetConfiguration={ "mcp": { "mcpServer": { "endpoint": "https://api.cdp.coinbase.com/platform/v2/x402/discovery/mcp" } } } )
Strands SDK

与您的代理一起使用 Coinbase x402 Bazaar Gateway Target:

from strands import Agent from strands.models import BedrockModel from strands.tools.mcp.mcp_client import MCPClient from mcp.client.streamable_http import streamablehttp_client from bedrock_agentcore.payments.integrations.config import AgentCorePaymentsPluginConfig from bedrock_agentcore.payments.integrations.strands.plugin import AgentCorePaymentsPlugin GATEWAY_URL = "https://<your-gateway-id>.gateway.bedrock-agentcore.<region>.amazonaws.com/mcp" ACCESS_TOKEN = "<your-inbound-auth-token>" mcp_client = MCPClient( lambda: streamablehttp_client(GATEWAY_URL, headers={"Authorization": f"Bearer {ACCESS_TOKEN}"}) ) # Configure the Payment plugin config = AgentCorePaymentsPluginConfig( payment_manager_arn="arn:aws:bedrock-agentcore:us-west-2:123456789012:payment-manager/pm-abc123", user_id="test-user-123", payment_instrument_id="payment-instrument-XJU4RSQP9VO0ler", payment_session_id="payment-session-xuzrnUCd7RT725G", region="us-west-2", ) # Create the plugin plugin = AgentCorePaymentsPlugin(config=config) with mcp_client: tools = mcp_client.list_tools_sync() agent = Agent( model=BedrockModel(inference_profile_id="us.anthropic.claude-sonnet-4-20250514-v1:0", streaming=True), tools=tools, plugins=[plugin], # enables automatic payments ) response = agent("Search for available x402 paid APIs related to weather data") print(response)
LangGraph

与您的代理一起使用 Coinbase x402 Bazaar Gateway Target: LangGraph

import asyncio from langchain.agents import create_agent from langchain_openai import ChatOpenAI from langchain_mcp_adapters.client import MultiServerMCPClient from bedrock_agentcore.payments.integrations.langgraph import ( AgentCorePaymentsConfig, AgentCorePaymentsMiddleware, ) GATEWAY_URL = "https://<your-gateway-id>.gateway.bedrock-agentcore.<region>.amazonaws.com/mcp" ACCESS_TOKEN = "<your-inbound-auth-token>" async def main(): client = MultiServerMCPClient({ "bazaar": { "transport": "streamable_http", "url": GATEWAY_URL, "headers": {"Authorization": f"Bearer {ACCESS_TOKEN}"}, } }) mcp_tools = await client.get_tools() config = AgentCorePaymentsConfig( payment_manager_arn="arn:aws:bedrock-agentcore:us-west-2:123456789012:payment-manager/pm-abc123", user_id="test-user-123", payment_instrument_id="payment-instrument-XJU4RSQP9VO0ler", region="us-west-2", auto_session=True, ) payments = AgentCorePaymentsMiddleware(config) agent = create_agent( model=ChatOpenAI(model="gpt-4o-mini"), tools=mcp_tools, middleware=[payments], ) result = await agent.ainvoke( {"messages": [{"role": "user", "content": "Search for available x402 paid APIs related to weather data"}]} ) print(result["messages"][-1].content) asyncio.run(main())

配置 Bazaar 目标后,您的代理可以通过网关发现并呼叫付费的 x402 终端节点。当终端节点返回 HTTP 402 时, AgentCore 如果您在代理中配置了支付插件 (Strands) 或中间件 (),则付款会自动处理付款流程。LangGraph要了解更多信息,请参阅框架集成。

要设置处理付款所需的付款管理器和连接器,请参阅创建付款管理器和连接器。