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

# Quickstart: Maintain a Feed

> Subscription-based producer flow: derive a feed ID and submit a verified update on Solana Devnet.

This page shows the subscription-backed producer path. There is no create-feed transaction: derive `feedId`, request signed data, and the first successful submit creates the Solana `Feed` account lazily.

<CardGroup cols={3}>
  <Card title="AI Agents" icon="robot" href="/quickstarts/ai-agents">
    First verified request through MCP — then Delegate or x402 escrow.
  </Card>

  <Card title="Smart Contracts" icon="file-contract" href="/quickstarts/smart-contracts">
    Verify a Molpha payload inside your app.
  </Card>

  <Card title="Backends" icon="server" href="/quickstarts/backend">
    Request signed data with the TypeScript SDK.
  </Card>
</CardGroup>

Both legacy paths below reach the same outcome: a threshold-signed value verified on Solana Devnet. Pick the one that matches how you work.

## Prerequisites

* A Solana wallet with Devnet SOL
* Devnet USDC for the subscription — use [Circle's faucet](https://faucet.circle.com/) (select **USDC** on **Solana Devnet**)
* Node.js `>=20.19.0` for the SDK and `>=24.0.0` for the MCP server

<Warning>
  Current releases target Solana Devnet and Sepolia verifier networks. Write operations spend Devnet SOL and may consume subscription quota.
</Warning>

## MCP server

The [MCP server](/mcp/molpha-mcp) exposes typed tools for AI agents over stdio. Full tool reference, architecture, guardrails, and troubleshooting live on that page.

<Steps>
  <Step title="Clone, build, and configure">
    ```bash theme={null}
    git clone https://github.com/Molpha/mcp.git
    cd mcp
    npm ci
    cp .env.example .env
    npm run build
    ```

    For local development, set a memory signer and Solana RPC in `.env`:

    ```dotenv theme={null}
    SIGNER_BACKEND=memory
    OWNER_KEYPAIR=/absolute/path/to/owner-keypair.json
    SOLANA_RPC=https://api.devnet.solana.com
    GATEWAY_ENDPOINTS=
    ```

    Leave `GATEWAY_ENDPOINTS` empty to use the SDK default. The same wallet must subscribe, own feeds, and sign gateway auth messages. For Privy or Turnkey, see [signer configuration](/mcp/molpha-mcp#choose-a-signer).
  </Step>

  <Step title="Validate and subscribe">
    ```bash theme={null}
    npm run doctor
    npm run provision -- subscribe --plan Basic --max-price-usdc 20000000 --dry-run
    npm run provision -- subscribe --plan Basic --max-price-usdc 20000000
    ```

    `npm run doctor` prints MCP client snippets with resolved absolute paths. `20000000` is 20 USDC at 6 decimals — a safety cap that aborts if the on-chain price is higher.
  </Step>

  <Step title="Connect your MCP client">
    Add the compiled server to your client config, restart, and call `molpha_get_capabilities`. Use absolute paths — clients may start the server from a different working directory.

    <Tabs>
      <Tab title="Cursor / Claude Desktop">
        ```json theme={null}
        {
          "mcpServers": {
            "molpha": {
              "command": "node",
              "args": ["/absolute/path/to/mcp/dist/src/server.js"],
              "env": {
                "SIGNER_BACKEND": "memory",
                "OWNER_KEYPAIR": "/absolute/path/to/owner-keypair.json",
                "SOLANA_RPC": "https://api.devnet.solana.com"
              }
            }
          }
        }
        ```
      </Tab>

      <Tab title="Codex">
        ```toml theme={null}
        [mcp_servers.molpha]
        command = "node"
        args = ["/absolute/path/to/mcp/dist/src/server.js"]

        [mcp_servers.molpha.env]
        SIGNER_BACKEND = "memory"
        OWNER_KEYPAIR = "/absolute/path/to/owner-keypair.json"
        SOLANA_RPC = "https://api.devnet.solana.com"
        ```
      </Tab>
    </Tabs>
  </Step>

  <Step title="Try an agent prompt">
    Ask your client to inspect the network (read-only):

    > Use Molpha to inspect the current protocol capabilities. Summarize the registry version, node count, supported chains, and gateway endpoints. Do not make any writes.

    More example prompts are on the [MCP server](/mcp/molpha-mcp#example-prompts) page.
  </Step>
</Steps>

<Note>
  Subscription and extension operations stay in the provisioning CLI because they debit USDC. They are not exposed as MCP tools.
</Note>

## TypeScript SDK

Install [`@molpha/sdk`](https://www.npmjs.com/package/@molpha/sdk) v0.1.0 and wire the gateway and Solana clients behind one wallet. The [SDK overview](/sdk/overview) covers the full API surface.

<Steps>
  <Step title="Install">
    <Tabs>
      <Tab title="pnpm">
        ```bash theme={null}
        pnpm add @molpha/sdk @anchor-lang/core bn.js
        ```
      </Tab>

      <Tab title="npm">
        ```bash theme={null}
        npm install @molpha/sdk @anchor-lang/core bn.js
        ```
      </Tab>

      <Tab title="yarn">
        ```bash theme={null}
        yarn add @molpha/sdk @anchor-lang/core bn.js
        ```
      </Tab>
    </Tabs>
  </Step>

  <Step title="Initialize, subscribe, and derive a feed">
    ```ts theme={null}
    import { web3 } from "@anchor-lang/core";
    import {
      MolphaSDK,
      PlanType,
      deriveApiConfigHash,
      deriveFeedIdString,
    } from "@molpha/sdk";
    import { walletFromKeypairFile } from "@molpha/sdk/utils";

    const wallet = walletFromKeypairFile("~/.config/solana/id.json");
    const sdk = new MolphaSDK({
      connection: new web3.Connection("https://api.devnet.solana.com", "confirmed"),
      wallet,
    });

    const plan = await sdk.solana.getPlan(PlanType.Basic);
    await sdk.solana.subscribe(PlanType.Basic, {
      maxPriceUsdc: plan.subscriptionPrice,
    });

    const apiConfig = {
      url: "https://api.example.com/price",
      responseParser: "$.price",
    };

    const signaturesRequired = 3;
    const feedId = deriveFeedIdString(
      wallet.publicKey.toBytes(),
      deriveApiConfigHash(apiConfig),
      signaturesRequired,
    );
    ```
  </Step>

  <Step title="Request a signed result and submit">
    ```ts theme={null}
    const { result, signature } = await sdk.requestAndSubmit(feedId, {
      apiConfig,
      signaturesRequired,
    });
    console.log("Submitted:", signature);
    console.log("Gateway value:", result.value);

    const feed = await sdk.solana.readFeed(feedId);
    console.log("On-chain value bytes:", feed?.value);
    console.log("Timestamp:", feed?.canonicalTimestamp);
    ```
  </Step>
</Steps>

<Warning>
  Gateway execution requires a `signAuthMessage`-capable wallet. The gateway verifies a real Ed25519 `authSig` and rejects all-zero signatures.
</Warning>

## Next steps

<CardGroup cols={2}>
  <Card title="Maintain a feed" icon="bolt" href="/guides/create-and-update">
    Producer flow: subscriptions, feed constraints, and keeping feeds current.
  </Card>

  <Card title="Read and verify" icon="magnifying-glass" href="/guides/read-and-verify">
    Consumer flow: read cached feeds or verify fresh signed payloads.
  </Card>

  <Card title="MCP server reference" icon="robot" href="/mcp/molpha-mcp">
    Tool reference, architecture, guardrails, and troubleshooting.
  </Card>

  <Card title="SDK reference" icon="code" href="/sdk/reference">
    Types, methods, and EVM/Starknet argument builders.
  </Card>
</CardGroup>
