> ## Documentation Index
> Fetch the complete documentation index at: https://docs.atxp.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Filestore

> Store and retrieve files

## Overview

Use the Filestore MCP server from your ATXP-powered agent to store, retrieve, and delete files.

## Example prompts

* "Upload the file `example.txt` to the filestore."
* "Download the file `example.txt` from the filestore."
* "Delete the file `example.txt` from the filestore."

## Tools

<AccordionGroup>
  <Accordion title="filestore_write">
    Takes file data and saves it to the file store. For example, if you need to save a file between conversations, you can use this tool.

    ### Arguments

    Accepts a JSON object with the following properties:

    <ParamField body="base64Content" type="string">
      The base64 encoded content of the file to save.
    </ParamField>

    <ParamField body="sourceUrl" type="string">
      The URL of a file to copy contents from.
    </ParamField>

    <ParamField body="contentType" type="string">
      The content type of the file to save
    </ParamField>

    <ParamField body="fileExtension" type="string">
      The file extension of the file to save
    </ParamField>

    <ParamField body="makePublic" type="boolean">
      Whether to make the file public.
    </ParamField>

    ### Response

    Returns a JSON object with the following properties:

    <ResponseField name="status" type="string">
      The status of the save file operation. The `status` key will have the value "success" when the file is saved successfully.
    </ResponseField>

    <ResponseField name="filename" type="string">
      The name of the file that was saved.
    </ResponseField>

    <ResponseField name="url" type="string">
      The URL that the file is accessible at.
    </ResponseField>
  </Accordion>

  <Accordion title="filestore_read">
    Returns the contents of a file from the file store. For example, if you need to read a file between conversations, you can use this tool.

    ### Arguments

    Accepts a JSON object with the following properties:

    <ParamField body="fileId" type="string" required>
      The ID of the file to read.
    </ParamField>

    ### Response

    Returns a JSON object with the following properties:

    <ResponseField name="status" type="string">
      The status of the read file operation. The `status` key will have the value "success" when the file is read successfully.
    </ResponseField>

    <ResponseField name="filename" type="string">
      The name of the file that was read.
    </ResponseField>

    <ResponseField name="base64Content" type="string">
      The base64 encoded content of the file that was read.
    </ResponseField>
  </Accordion>

  <Accordion title="filestore_delete">
    Deletes a file from the file store. For example, if you need to delete a file between conversations, you can use this tool.

    ### Arguments

    Accepts a JSON object with the following properties:

    <ParamField body="filename" type="string" required>
      The name of the file to delete.
    </ParamField>

    ### Response

    Returns a JSON object with the following properties:

    <ResponseField name="status" type="string">
      The status of the delete file operation. The `status` key will have the value "success" when the file is deleted successfully.
    </ResponseField>

    <ResponseField name="filename" type="string">
      The name of the file that was deleted.
    </ResponseField>
  </Accordion>
</AccordionGroup>

## Usage

<Steps>
  <Step title="Define the Filestore service">
    Create a reusable service configuration that points to the MCP server and standardizes how you pass arguments and read results. This lets your agent easily interact with the Filestore tools in a consistent manner.

    ```typescript theme={null}
    const filestoreService = {
        mcpServer: 'https://filestore.mcp.atxp.ai/',
        writeFileToolName: 'filestore_write',
        description: 'ATXP Filestore MCP server',
        getArguments: (sourceURL: string) => ({ sourceURL }),
        getResult: (result: any) => {
          const jsonResult = result.content[0].text
          return JSON.parse(jsonResult);
        }
      };
    ```
  </Step>

  <Step title="Create an ATXP client">
    <Tabs>
      <Tab title="Using an ATXP account">
        Create a client using an <a href="/developers/build-agents/create-account" target="_blank">ATXP account</a> by importing the ATXP client SDK and other dependencies.

        ```typescript theme={null}
        // Import the ATXP client SDK
        import { atxpClient, ATXPAccount } from '@atxp/client';

        // Read the ATXP account details from environment variables
        const atxpConnectionString = process.env.ATXP_CONNECTION;

        // Create a client using the `atxpClient` function
        const client = await atxpClient({
          mcpServer: filestoreService.mcpServer,
          account: new ATXPAccount(atxpConnectionString),
        });
        ```
      </Tab>

      <Tab title="Using a Base account">
        Create a client using a Base account by importing the ATXP client SDK and other dependencies.

        ```typescript theme={null}
        // Import the ATXP client SDK and Base account
        import { atxpClient } from '@atxp/client';
        import { BaseAccount } from '@atxp/base';

        // Read the Base account details from the environment variables
        const baseRpcUrl = process.env.BASE_RPC_URL;
        const basePrivateKey = process.env.BASE_PRIVATE_KEY;

        // Create a client using the `atxpClient` function
        const client = await atxpClient({
          mcpServer: filestoreService.mcpServer,
          account: new BaseAccount(baseRpcUrl, basePrivateKey),
        });
        ```
      </Tab>

      <Tab title="Using a Solana account">
        Create a client using a Solana account by importing the ATXP client SDK and other dependencies.

        ```typescript theme={null}
        // Import the ATXP client SDK and Solana account
        import { atxpClient } from '@atxp/client';
        import { SolanaAccount } from '@atxp/solana';

        // Read the Solana account details from the environment variables
        const solanaRpcUrl = process.env.SOLANA_RPC_URL;
        const solanaPrivateKey = process.env.SOLANA_PRIVATE_KEY;

        // Create a client using the `atxpClient` function
        const client = await atxpClient({
          mcpServer: filestoreService.mcpServer,
          account: new SolanaAccount(solanaRpcUrl, solanaPrivateKey),
        });
        ```
      </Tab>

      <Tab title="Using a Worldchain account">
        Create a client using a Worldchain account with MiniKit integration.

        ```typescript theme={null}
        // Import the ATXP client SDK and Worldchain account creator
        import { atxpClient } from '@atxp/client';
        import { createMiniKitWorldchainAccount } from '@atxp/worldchain';
        import { MiniKit } from '@worldcoin/minikit-js';

        // Create a Worldchain account using MiniKit
        const account = await createMiniKitWorldchainAccount({
          walletAddress: '0x1234...', // User's wallet address
          miniKit: MiniKit
        });

        // Create a client using the `atxpClient` function
        const client = await atxpClient({
          mcpServer: filestoreService.mcpServer,
          account,
        });
        ```
      </Tab>

      <Tab title="Using a Polygon account">
        **Browser applications:**

        ```typescript theme={null}
        // Import the ATXP client SDK and Polygon browser account
        import { atxpClient } from '@atxp/client';
        import { PolygonBrowserAccount } from '@atxp/polygon';

        // Initialize the Polygon browser account with wallet provider
        const account = await PolygonBrowserAccount.initialize({
          provider: window.ethereum, // or any EIP-1193 provider
          walletAddress: '0x1234...', // User's wallet address
        });

        // Create a client using the `atxpClient` function
        const client = await atxpClient({
          mcpServer: filestoreService.mcpServer,
          account,
        });
        ```

        **Server/CLI applications:**

        ```typescript theme={null}
        // Import the ATXP client SDK and Polygon server account
        import { atxpClient } from '@atxp/client';
        import { PolygonServerAccount } from '@atxp/polygon';

        // Read the Polygon account details from the environment variables
        const polygonRpcUrl = process.env.POLYGON_RPC_URL;
        const polygonPrivateKey = process.env.POLYGON_PRIVATE_KEY;

        // Create a Polygon server account
        const account = new PolygonServerAccount(
          polygonRpcUrl,
          polygonPrivateKey,
          137 // Chain ID: 137 = Polygon mainnet, 80002 = Amoy testnet
        );

        // Create a client using the `atxpClient` function
        const client = await atxpClient({
          mcpServer: filestoreService.mcpServer,
          account,
        });
        ```
      </Tab>
    </Tabs>
  </Step>

  <Step title="Use the Filestore service in your agent">
    Call the Filestore tool by passing your natural-language instruction as the argument the `getArguments` method.

    Read the response using the `getResult` method.

    ```typescript theme={null}
    const sourceURL = "https://media2.giphy.com/media/v1.Y2lkPTc5MGI3NjExN3FycXEzcnVpeDJiZnZlMThoc3R2aDdnM2NrY2hxY3J3eHFqaG92cyZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/DYH297XiCS2Ck/giphy.gif"

    try {
      const writeResult = await client.callTool({
          name: filestoreService.writeFileToolName,
          arguments: filestoreService.getArguments(sourceURL),
      });
      const writeResult = filestoreService.getResult(writeResult);
      console.log('Status:', writeResult.status);
      console.log('Filename:', writeResult.filename);
      console.log('URL:', writeResult.url);
    } catch (error) {
      console.error(`Error with ${filestoreService.description}:`, error);
      process.exit(1);
    }
    ```

    <Check>
      You should see the result of the filestore operation printed in your console.
    </Check>
  </Step>
</Steps>
