-
Notifications
You must be signed in to change notification settings - Fork 58
Open
Labels
enhancementNew feature or requestNew feature or requestrustPull requests that update rust codePull requests that update rust code
Description
Problem
Currently, component2json does not support WIT resource types through MCP:
- Outputs: Resources serialize to debug strings (
"resource: {res:?}") — not usable handles - Inputs: Explicitly rejected with
Err(ValError::ResourceError)
This prevents components from exposing interfaces like wasi:filesystem where operations return and accept descriptor resources.
Use Case
We want to build a storage component that exports wasi:filesystem so agents can:
open("/data/file.txt") -> descriptor(3)
read(descriptor(3), 1024) -> bytes
close(descriptor(3))
Without resource support, we must define custom wrapper interfaces that avoid resources entirely — defeating the goal of reusing standard WASI interfaces.
Proposed Solution
Serialize resources as integer handles that remain valid within a session:
Schema generation:
Type::Own(r) | Type::Borrow(r) => json!({
"type": "integer",
"description": format!("Handle to resource: {}", resource_name(r))
})Output conversion:
// When component returns a resource, allocate a handle ID
Val::Resource(res) => {
let handle_id = resource_table.insert(res);
json!(handle_id)
}Input conversion:
// When MCP passes an integer for a resource param, look up the handle
(Type::Own(_) | Type::Borrow(_), Value::Number(n)) => {
let handle_id = n.as_u64().ok_or(ValError::InvalidHandle)?;
let res = resource_table.get(handle_id).ok_or(ValError::HandleNotFound)?;
Ok(Val::Resource(res))
}Resource Lifecycle
- Handles are scoped to the component instance (each agent session has isolated handles)
dropresource calls remove from table- Optional: auto-cleanup on session end
Alternatives Considered
- Custom wrapper interfaces — Works but forces every component to reimplement path-based wrappers instead of using standard WASI interfaces
- String-encoded handles — Possible but integers are cleaner and match how file descriptors work
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestrustPull requests that update rust codePull requests that update rust code