w3_bridge_generate_tokens
Generate authentication tokens for the UCAN-HTTP bridge, enabling delegated capabilities and expiration settings for secure access to MCP IPFS server resources.
Instructions
Generates authentication tokens for using the UCAN-HTTP bridge.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| capabilities | Yes | One or more capabilities to delegate (e.g., ['space/info']). | |
| expiration | No | Unix timestamp (in seconds) for expiration. Zero means no expiration. | |
| json | No | Output JSON suitable for fetch headers (default: true). |
Implementation Reference
- src/tool_handlers.ts:430-485 (handler)The primary handler function for the 'w3_bridge_generate_tokens' tool. Validates input arguments using the corresponding Zod schema, constructs the 'w3 bridge generate-tokens' CLI command based on capabilities, expiration, and json flag, executes it via runW3Command utility, handles JSON parsing, and formats the response as MCP content.const handleW3BridgeGenerateTokens: ToolHandler = async (args) => { const parsed = Schemas.W3BridgeGenerateTokensArgsSchema.safeParse(args); if (!parsed.success) throw new Error( `Invalid arguments for w3_bridge_generate_tokens: ${parsed.error.message}` ); const { capabilities, expiration, json } = parsed.data; let command = "bridge generate-tokens"; capabilities.forEach((cap) => { command += ` --can '${cap}'`; }); if (expiration !== undefined) command += ` --expiration ${expiration}`; if (json) command += " --json"; const { stdout } = await runW3Command(command); if (json) { try { const tokenData = JSON.parse(stdout); return { content: [ { type: "text", text: JSON.stringify({ message: "Bridge tokens generated (JSON format).", tokenData, }), }, ], }; } catch (e) { logger.warn("Failed to parse bridge tokens JSON, returning raw."); return { content: [ { type: "text", text: JSON.stringify({ message: "Bridge tokens generated (raw output).", output: stdout.trim(), }), }, ], }; } } else { return { content: [ { type: "text", text: JSON.stringify({ message: "Bridge tokens generated (raw output).", output: stdout.trim(), }), }, ], }; } };
- src/schemas.ts:168-188 (schema)Zod schema defining the input parameters for the 'w3_bridge_generate_tokens' tool, including required capabilities array, optional expiration timestamp, and json output flag with descriptions.export const W3BridgeGenerateTokensArgsSchema = z .object({ capabilities: z .array(z.string()) .min(1) .describe("One or more capabilities to delegate (e.g., ['space/info'])."), expiration: z .number() .int() .positive() .optional() .describe( "Unix timestamp (in seconds) for expiration. Zero means no expiration." ), json: z .boolean() .optional() .default(true) .describe("Output JSON suitable for fetch headers (default: true)."), }) .describe("Generates authentication tokens for using the UCAN-HTTP bridge.");
- src/tool_handlers.ts:961-961 (registration)Maps the tool name 'w3_bridge_generate_tokens' to its handler function in the exported toolHandlers object, which is imported and used by the main MCP server in index.ts to dispatch tool calls.w3_bridge_generate_tokens: handleW3BridgeGenerateTokens,