Developer integrations
Surfpool provides programmatic access to a Solana-compatible local runtime through a Rust SDK, a Node.js package, and an MCP server. These surfaces let tests, scripts, and model-context clients start or use a Surfnet, inspect it through normal Solana RPC, and apply controlled local state changes.
Integration model
Each integration surface reaches the same local Surfnet boundary. A Surfnet supplies HTTP RPC and WebSocket endpoints for normal Solana work. Surfpool-specific controls support test setup, time changes, program loading, account changes, and other local actions.
The following flow shows how a consumer selects an interface and reaches a Surfnet.
flowchart LR
A[Developer or model-context client] --> B{Integration surface}
B --> C[Rust SDK]
B --> D[Node.js SDK]
B --> E[MCP server]
C --> F[Embedded Surfnet]
D --> G[Embedded or attached Surfnet]
E --> H[Started or existing Surfnet]
F --> I[Solana RPC and Surfpool controls]
G --> I
H --> I
Consumer boundaries
The Rust and Node.js surfaces are client libraries for automated code. They make a local runtime available to a test or application and expose standard Solana access with Surfpool test controls. The MCP surface is an adapter for tools and resources that an MCP client can discover and call.
Choose the surface that matches the caller:
| Consumer | Main role | Runtime relationship |
|---|---|---|
| Rust integration test | Run Solana tests with local state control | Starts an embedded Surfnet |
| Node.js test or script | Use JavaScript or TypeScript with Solana Kit or direct helpers | Starts an embedded Surfnet or attaches to one already running |
| MCP-compatible IDE or agent | Ask for networks, state changes, RPC calls, and scenarios | Uses MCP tools to start or reach a Surfnet |
References: crates/…/lib.rs• L1-31 crates/…/package.json• L1-22 crates/…/mod.rs• L580-624
Runtime access patterns
Embedded access gives the caller ownership of the Surfnet lifetime. The caller receives local RPC addresses and a funded payer, then stops the runtime when its work ends. Attached access keeps runtime ownership outside the client and adds client controls to an existing Surfpool endpoint.
The distinction matters most in Node.js. Its base package starts a runtime directly. Its Kit plugin can either compose a fresh in-process runtime or connect to a running surfpool start instance. MCP clients can ask the server to start a Surfnet or use a port returned by an earlier tool call.
References: crates/…/surfnet.rs• L140-241 crates/…/surfpool.ts• L140-271 crates/…/mod.rs• L580-614
Rust integration
The Rust SDK at crates/sdk embeds a complete Surfpool instance for Rust integration tests. A test starts Surfnet with default or custom settings, creates a Solana RpcClient for the local endpoint, and uses cheatcodes when direct setup is more useful than a transaction.
The SDK covers the test lifecycle and the state needed before a test runs:
- Start and stop an isolated Surfnet.
- Use a pre-funded payer and local HTTP or WebSocket RPC.
- Fund SOL and token accounts or set account data directly.
- Move local time to an epoch, slot, or timestamp.
- Restore account state from an exported snapshot at startup.
- Deploy a local program and register its optional IDL.
- Observe runtime events or send runtime commands when a test needs them.
- Lock setup controls before giving the runtime to code that must use only normal validator RPC.
The Rust SDK and cheatcodes page explains this client surface in more detail.
Test state controls
Rust cheatcodes are setup controls that bypass normal transaction flow. They let a test establish balances, token accounts, arbitrary account state, program code, and clock position before it exercises the behavior under test. Normal Solana RPC remains the path for that behavior.
Cheatcodes also support a clear handoff from setup to execution. A test can lock all cheatcodes or a selected set after preparing state, and a full lock cannot be reversed through the RPC endpoint.
References: crates/…/mod.rs• L19-23 crates/…/mod.rs• L66-177 crates/…/mod.rs• L253-328 crates/…/mod.rs• L459-488 crates/…/cheatcode_lock.rs• L35-225
Snapshot restoration
Snapshot restoration lets an embedded Surfnet begin with account state exported from another Surfnet. The builder accepts account data directly or from a snapshot file, so offline tests can reproduce a known state without fetching each account again. Later snapshot entries replace earlier entries for the same account, and restored balances take priority over startup airdrops.
Snapshot data restores accounts, not the clock. When a test depends on the relationship between slot and Unix time, it can set both with the time-travel control after loading the snapshot.
References: crates/…/surfnet.rs• L61-65 crates/…/surfnet.rs• L208-231 crates/…/surfnet.rs• L250-269 crates/…/snapshot.rs• L22-205 crates/…/clock.rs• L8-39
Cheatcode access policy
The SDK can apply a one-way cheatcode lock at startup or after setup. A full lock blocks Surfpool controls and related administrative RPC actions while leaving standard Solana RPC available. A selective lock protects named controls while other local controls remain usable.
This boundary supports tests that prepare state with trusted code and then pass the endpoint to an agent or other untrusted code. Startup airdrops and SDK-owned shutdown remain available because they do not use the locked RPC methods.
References: crates/…/surfnet.rs• L176-205 crates/…/mod.rs• L459-488 crates/…/cheatcode_lock.rs• L35-225
Node.js integration
The Node.js package at crates/sdk-node exposes the Rust SDK to Node.js and TypeScript. Its direct Surfnet class gives scripts a local RPC endpoint, a WebSocket endpoint, a payer, lifecycle control, and helpers for account funding, time travel, and program deployment. The package supports Node.js 18 or newer and publishes a direct entry point plus a separate @solana/surfpool/kit entry point for Kit consumers.
The package also exposes @solana/surfpool/kit. This plugin fits Surfpool into the standard @solana/kit client model. In embedded mode it installs a payer and local RPC services around a new Surfnet. In attach mode it points those services at an existing endpoint and can fund selected addresses while the client is composed.
The Node.js SDK page covers the package API and its Kit integration.
Typed control surface
The Kit entry point combines ordinary Solana RPC with a typed Surfpool cheatcode RPC. Application code can use standard Kit planners and senders for transactions, then use named controls for account updates, time travel, program and network changes, profiling, snapshots, scenarios, IDLs, streamed accounts, and confidential-token balance access during local test setup. The confidential-token controls can derive account keys and return available and pending balances that the supplied keys can decrypt. The standalone cheatcodes client is also available when a full Kit client is not needed.
The typed surface keeps method names and request and result shapes aligned with the Surfpool RPC contract. It includes the full cheatcode method set through a composed API. A compile-time coverage check requires that API to match the generated cheatcode method manifest.
See shared contracts when a Rust RPC change must stay aligned with the Node.js types and other client surfaces.
References: crates/…/package.json• L1-22 crates/…/package.json• L54-95 crates/…/api.ts• L90-227 crates/…/api.ts• L229-240
MCP integration
The MCP server at crates/mcp presents Surfpool as tools and resources for MCP-compatible clients such as IDE agents. The server exposes tools for starting a Surfnet, preparing local state, calling Surfnet RPC, and creating scenarios. It also exposes small reference resources that help clients form valid calls.
MCP supports two ways to start and prepare a local network. A client can request a start command or ask the server to run Surfnet as a background process. It can then fund SOL or SPL token accounts for supplied owners, or receive generated wallet details when no owner is supplied. The combined start-and-fund operation reports successful account updates and any errors instead of dropping partial results.
The MCP server integration page explains the server tools, resources, and helper flows.
Tool and resource contract
MCP clients discover two kinds of capability. Tools perform actions and return structured text results. Resources provide reference data that helps a client form valid calls, such as the RPC method list and the override-template index used by scenario creation.
The str:///rpc_endpoints resource describes the methods available to the generic RPC tool. Scenario creation is not a generic RPC call. Clients use the dedicated scenario tools instead.
The template contract is split into small discovery steps. The index lists available templates without heavy fields. A client then requests one template's detail and searches its constants for a concrete value. Search results are bounded and report when more matches exist, so a client can refine its query instead of loading a large catalog into its context.
References: crates/…/mod.rs• L741-824 crates/…/mod.rs• L1238-1372 crates/…/mod.rs• L1415-1489
Scenario preparation
Scenario preparation turns model-selected account changes into a validated Surfpool scenario. A general scenario must use a template from the registry, provide values that match its properties, and use exact constant values before the server stages the scenario. Dynamic values must come from the tool named by the template. Dedicated Phoenix and Pump tools read the target Surfnet state and build protocol-specific preparation when the required state is present.
Use the following order for a template-based scenario:
- Read
str:///override_templatesor callget_override_templatesto choose a template ID. - Call
get_override_templatefor the selected template's account shape and property rules. - Call
search_constant_optionswhen a property needs a catalog value, then use the returned value. - Call
create_scenariowith native JSON values. The server checks the template and values before staging the scenario.
For a Pump graduation scenario, provide the token mint to the dedicated tool. The server checks the mint and related Surfnet accounts before it stages the preparation. For a Phoenix collateral scenario, provide the trader and target collateral. The server reads the trader from the Surfnet used by Studio and stages a state-preparation scenario rather than executing liquidation.
The generic RPC tool remains available for Surfnet RPC methods. Scenario creation uses the dedicated scenario tools instead of that generic path.
References: crates/…/mod.rs• L826-1103 crates/…/mod.rs• L1105-1186 crates/…/mod.rs• L1217-1372
Interface selection
The three surfaces differ in who owns the runtime and how the caller expresses work. Use a library surface when code controls the test directly. Use MCP when an IDE or model-context client must discover and invoke Surfpool actions through a protocol.
| Need | Recommended surface | Why |
|---|---|---|
| Rust-native integration tests | Rust SDK | Embeds the runtime and exposes Solana types directly |
| JavaScript or TypeScript tests | Node.js SDK | Provides direct helpers and a Kit-compatible client plugin |
| Agent-driven setup or exploration | MCP server | Exposes discoverable tools and reference resources |
| Shared client and RPC contract details | Shared contracts | Explains the data shapes that cross client boundaries |
| Several clients using one environment | Node.js attach mode or MCP RPC tools | Leaves runtime ownership with the running Surfpool |
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the Rust SDK's lifecycle, endpoint, and payer guarantees aligned with the Node.js
Surfnetwrapper. - Keep snapshot input, merge order, restored-account precedence, and clock-restoration guidance aligned across Rust and Node.js clients.
- Keep the Rust cheatcode lock filter, one-way behavior, startup behavior, and untrusted-client boundary aligned with any client that exposes setup controls.
- Keep the Node.js Kit plugin's embedded and attach-mode contracts aligned with the RPC and WebSocket ports exposed by Surfpool.
- Keep the generated cheatcode method manifest, typed request and result shapes, and composed Node.js API aligned when a Rust RPC method changes. Include confidential key inputs and balance outputs.
- Keep MCP tool descriptions, token-account result shapes, template indexes, template details, and constant search results aligned so clients can discover valid inputs and handle partial results.
- Keep general scenario validation aligned with template-derived addresses, exact constant values, and dynamic values returned by their source tools. Keep dedicated protocol scenario tools aligned with the Surfnet state they inspect.
- Keep the generic RPC endpoint resource aligned with the methods accepted by
call_surfnet_rpc, and keep scenario tools separate from that generic method list. - Keep the CLI
mcpcommand and the HTTP/mcpmount aligned when the MCP transport or server capabilities change.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| An embedded runtime is not stopped after a test or client scope ends | RPC sockets and ports can remain open or reset during process exit | Use stop() or the Node.js Kit disposable client lifecycle |
| Node.js attach mode receives no usable payer | The client can read the runtime but cannot sign transactions | Install a payer before composing the attach plugin |
| A snapshot file cannot be read or parsed | Surfnet startup fails instead of using partial state | Validate the exported snapshot file before starting the runtime |
| A snapshot restores accounts but the test assumes it restores the clock | Programs that compare slot and Unix time can see inconsistent state | Set both values with the time-travel control when the snapshot time matters |
| A full cheatcode lock is enabled before setup is complete | Cheatcodes and RPC airdrops are refused | Finish setup first or use startup airdrops and then lock the runtime |
| A lock names an unknown cheatcode | Surfnet startup fails rather than applying an incomplete policy | Use the supported cheatcode names |
| A token funding request uses an unknown symbol without a mint address | The MCP tool returns an error and does not set the balance | Use a verified symbol or provide the token mint address |
| A token funding request uses the wrong token program ID | The associated token account or RPC update can fail | Use the program that owns the mint and pass its valid address |
| A confidential-balance request omits one of the owner's keys | The matching available or pending balance is returned as null | Pass the AES key for available balance and the ElGamal secret key for pending balance |
| A client sends an unknown template ID, missing template property, or invalid constant value | Scenario staging returns an error instead of a usable Studio link | Read the template index and detail first, then resolve constants through search_constant_options |
| A client uses the generic RPC tool to create a scenario | The request does not follow the scenario validation and staging path | Use create_scenario or a dedicated protocol scenario tool |
| A template catalog query returns more than the result limit | The client sees only part of the catalog and may choose the wrong value | Check totalMatches and truncated, then refine the query |
| A Pump or Phoenix preparation request has invalid input or missing target state | No preparation scenario is staged | Use the dedicated discovery or validation flow with a running Surfnet that has the required accounts |
| An MCP client calls a Surfnet RPC port that is not running | The tool returns a failed RPC result | Start a Surfnet first and use the returned RPC address or port |
| A Rust or Node.js caller treats a setup cheatcode as a normal transaction | Test state may not match the intended precondition or response timing | Use standard RPC for behavior under test and cheatcodes only for deliberate local setup |
Key files
| File | Why to read it |
|---|---|
| crates/…/lib.rs | Public Rust SDK entrypoint and exported client types |
| crates/…/surfnet.rs | Rust runtime lifecycle, endpoints, payer, startup snapshots, and cheatcode policy |
| crates/…/mod.rs | Rust test-state controls, time alignment, program deployment, and cheatcode locking |
| crates/…/snapshot.rs | Account snapshot restoration and startup precedence guarantees |
| crates/…/clock.rs | Slot and Unix-time restoration behavior |
| crates/…/cheatcode_lock.rs | One-way setup-control locking and standard RPC access after the lock |
| crates/…/package.json | Node.js package entrypoints, runtime support, and Kit support |
| crates/…/index.ts | Direct TypeScript Surfnet client surface |
| crates/…/surfpool.ts | Embedded and attach-mode Kit integration |
| crates/…/cheatcodes.ts | Typed Surfpool cheatcodes RPC surface |
| crates/…/api.ts | Composed Kit API and typed method contracts |
| crates/…/methods.ts | Generated list of supported Surfpool cheatcode methods |
| crates/…/lib.rs | MCP server startup and standard-input/output transport |
| crates/…/mod.rs | MCP tools, resources, template discovery, scenario preparation, and the model-facing Surfpool contract |
| crates/…/set_token_account.rs | MCP SOL and token funding behavior, token lookup, generated owners, and result reporting |
| crates/…/mod.rs | HTTP-hosted /mcp integration point |