pay_and_get_402_protected_url
Access HTTP 402 protected content by processing payments through your P-Link account to retrieve the requested URL data.
Instructions
Pay a HTTP 402 protected URL using your P-Link managed account, and returns the result
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | The 402 protected URL (can be any link complying to the x402 protocol) |
Implementation Reference
- src/tools/402client.ts:7-27 (handler)The main asynchronous handler function that implements the tool logic: extracts the URL from args, resolves the API key, sends a POST request to the backend to pay for the 402-protected resource, logs the response, parses it as JSON, and returns the result.export async function pay_and_get_402_protected_url(args: any) { const { url } = args; const { apiKey } = resolveAuth(undefined, undefined); var jsP = { myKey: apiKey, url } const fet = await fetch(BASE + '/api/pay402link', { method: 'POST', headers: { Accept: 'application.json', 'Content-Type': 'application/json' }, body: JSON.stringify(jsP) }); var dat = await fet.text(); process.stderr.write(`[caisse][info] dat2 ${dat}\n`); var result = JSON.parse(dat); return result; }
- src/tools/402client.ts:30-32 (schema)The Zod schema defining the input shape for the tool: requires a 'url' string with description.export const get402clientShape = { url: z.string().describe("The 402 protected URL (can be any link complying to the x402 protocol)") } ;
- src/solution.ts:80-85 (registration)The tool registration object in the tools array, which defines the name, description (from imported title), inputSchema (derived from get402clientShape), and annotations. This is returned by the ListToolsRequest handler.{ name: "pay_and_get_402_protected_url", description: auth402_title, inputSchema: jsonSchema(zodToJsonSchema(z.object(get402clientShape))).jsonSchema, annotations: { title: 'Pay 402 link', destructiveHint: true, openWorldHint: true } }
- src/solution.ts:152-154 (registration)The switch case in the CallToolRequest handler that routes calls to this tool name by invoking the imported handler function with the arguments.case "pay_and_get_402_protected_url": result = await pay_and_get_402_protected_url(args); break;
- src/tools/402client.ts:34-46 (helper)A helper function to register the tool on an MCP server using the standard SDK method, though not used in this codebase's main server setup.export function register402client(server: McpServer ) { server.registerTool( 'pay_and_get_402_protected_url', { title: auth402_title, description: auth402_title, inputSchema: get402clientShape, annotations: { title: auth402_title, destructiveHint: true, openWorldHint: true } }, async (e) => await wrapResult(pay_and_get_402_protected_url, e) ); }