Skip to main content

Crate subako_function_sdk

Crate subako_function_sdk 

Source
Expand description

The guest side of a Subako function: a WASI preview 1 program the worker runs with argv = [package] as an MCP server over MCP’s stdio transport, a JSON-RPC 2.0 message per line. It speaks the stateless MCP revision 2026-07-28, so every request carries its own _meta and there is no handshake.

On upload, core asks the module server/discover and tools/list; on a call, the worker sends one tools/call. Either way stdin closes once the last request is answered. The guest answers each request as it arrives and exits 0 when stdin ends.

A call’s result is MCP’s CallToolResult, with content the model reads, structuredContent beside it, and isError set on a failure the model should read. An image in the session volume travels as a resource_link to volume:///<path beneath /volume>, which core reads and shows the model. A JSON-RPC error, a line that is no message, or any other exit is a crash.

A package is written as typed functions. Each one’s name, doc comment, and input and output types become the tool tools/list names, and the program prints the package’s subako-package.json (its ABI, name, and description) when run with --subako-manifest:

use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use subako_function_sdk::{ToolError, function, package};

#[derive(Deserialize, JsonSchema)]
struct GreetInput {
    /// Who to greet.
    name: String,
}

#[derive(Serialize, JsonSchema)]
struct Greeting {
    message: String,
}

/// Greet someone by name.
#[function]
fn greet(input: GreetInput) -> Result<Greeting, ToolError> {
    Ok(Greeting { message: format!("Hello, {}!", input.name) })
}

package! {
    name: "hello",
    description: "Says hello.",
    functions: [greet],
}

The same crate built for the host prints the same manifest, so packaging needs no WebAssembly runtime: cargo run -- --subako-manifest.

A function that shows the model an image returns an Answer: its JSON, and the image after it.

#[derive(Serialize, JsonSchema)]
struct Plot {
    path: String,
}

/// Plot a chart and show it.
#[function]
fn plot(input: PlotInput) -> Result<Answer<Plot>, ToolError> {
    let path = "/volume/tmp/chart.png".to_string();
    // ... write the chart to `path` ...
    Ok(Answer::new(Plot { path: path.clone() }).with_image_file(path))
}

Modules§

http
HTTP from a guest. The worker makes the request on the guest’s behalf, under the invocation’s egress policy: which hosts it may reach and which credential headers ride along to which origins. A file body or a file response moves between the socket and the volume without passing through guest memory.

Macros§

package
Declares the package: pub fn package() building it and, unless main: false, the program’s main serving it.

Structs§

Answer
A function’s typed result with blocks after it: the model reads value as JSON text first, then each block in order. Its output schema is T’s.
Function
One function a package serves as a tool.
Input
A call’s input, held until the tool says which shape it takes.
Manifest
What subako-package.json holds: the ABI the module speaks, and the package’s name and description. Its tools are what tools/list answers.
Output
A call’s result: the blocks the model reads, and the JSON beside them.
Package
A package: its name, its description, and the functions it serves.
ServerInfo
Who answers: MCP’s serverInfo.
ToolError
A failure the model should read: the message is all it is told.

Enums§

Content
One block of a result the model reads.

Constants§

ABI
The function ABI this SDK’s guests speak: MCP 2026-07-28 over stdio.
MANIFEST_FLAG
The argument that prints the manifest instead of calling a function.

Traits§

Reply
What a function may return: a JSON value, or an Answer carrying blocks beside one.
Server
What a guest serves: who it is, its tools, and how to call one.

Functions§

execute
Every exchange as a pure function of stdin, so a host test drives exactly what the guest runs: the bytes are every line the guest writes.
run
The guest’s main: answers each line of stdin as it arrives, until stdin ends.

Attribute Macros§

function
Makes a function a tool: its name is the tool’s, its doc comment the description the model reads, and its one argument and Ok type the input and output schemas. The function itself is left as written.