w3_open
Access content stored in IPFS using its CID and optional path, enabling direct retrieval and navigation within the mcp-ipfs server's network.
Instructions
Tool for w3_open operation.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cid | Yes | The CID of the content to open. | |
| path | No | Optional path within the content to append to the URL. |
Implementation Reference
- src/tool_handlers.ts:162-181 (handler)The main handler function for the 'w3_open' tool. It validates input arguments using W3OpenArgsSchema, constructs a gateway URL (https://w3s.link/ipfs/{cid}/{path?}), and returns a text content block with the URL for the user to open in their browser.const handleW3Open: ToolHandler = async (args) => { const parsed = Schemas.W3OpenArgsSchema.safeParse(args); if (!parsed.success) throw new Error(`Invalid arguments for w3_open: ${parsed.error.message}`); const { cid, path } = parsed.data; const baseUrl = "https://w3s.link/ipfs/"; const fullPath = path ? `${cid}/${path}` : cid; const url = `${baseUrl}${fullPath}`; return { content: [ { type: "text", text: JSON.stringify({ message: `To view the content, open this URL in your browser: ${url}`, url: url, }), }, ], }; };
- src/schemas.ts:68-74 (schema)Zod schema defining the input parameters for the 'w3_open' tool: 'cid' (string, required), 'path' (string, optional).export const W3OpenArgsSchema = z.object({ cid: z.string().describe("The CID of the content to open."), path: z .string() .optional() .describe("Optional path within the content to append to the URL."), });
- src/tool_handlers.ts:952-952 (registration)Maps the tool name 'w3_open' to its handler function 'handleW3Open' in the toolHandlers object exported from tool_handlers.ts, which is imported and used by the MCP server in index.ts to dispatch tool calls dynamically.w3_open: handleW3Open,