Implemented all suggested polish improvements to enhance the WASM/WASI implementation based on the review feedback.
Before: All tool outputs returned as stringified JSON in Content::Text
After: Smart content detection:
- Plain strings return as direct text
- Objects return as pretty-printed JSON for readability
- Preserves structure for client-side parsing
let content = if let Some(text) = result_value.as_str() {
vec![Content::Text { text: text.to_string() }]
} else if result_value.is_object() {
vec![Content::Text {
text: serde_json::to_string_pretty(&result_value)
.unwrap_or_else(|_| "{}".to_string()),
}]
}Before: All errors mapped to INTERNAL_ERROR
After: Protocol errors preserve their specific codes:
Protocolerrors retain original error codes- Graceful fallback to
INTERNAL_ERRORfor other types
fn map_error_code(error: &Error) -> ErrorCode {
match error {
Error::Protocol { code, .. } => *code,
_ => ErrorCode::INTERNAL_ERROR,
}
}Before: Simple aggregation with no cursor support After: Smart cursor handling with provider namespacing:
- Cursor format:
"provider:cursor"for multi-provider pagination - Sequential provider querying for proper pagination
- Maintains cursor state across requests
// Parse cursor to determine which provider to query
let (provider_name, provider_cursor) = if let Some(cursor) = params.cursor {
if let Some((name, cur)) = cursor.split_once(':') {
(Some(name.to_string()), Some(cur.to_string()))
} else {
(None, Some(cursor))
}
}Before: Echo client version without validation After: Proper negotiation with fallback:
- Validates client version against
SUPPORTED_PROTOCOL_VERSIONS - Falls back to latest supported version if unknown
- Documents behavior in response
let negotiated_version = if SUPPORTED_PROTOCOL_VERSIONS.contains(&client_version.as_str()) {
client_version
} else {
SUPPORTED_PROTOCOL_VERSIONS[0].to_string()
};Created: Complete build automation with targets:
build- Build standalone Workerbuild-sdk- Build SDK-backed variantdeploy- Deploy to Cloudflaretest- Test deployed workerclean- Clean artifacts
Key feature: Clear separation between SDK and non-SDK variants with instructions.
Added: Comprehensive test suite covering:
- Initialize with supported/unsupported versions
- List tools functionality
- Call existing/nonexistent tools
- Invalid parameter handling
- Error code mapping
- Resource pagination
- Content format variations
Located in: src/server/wasm_server_tests.rs
| Test Case | Status | Purpose |
|---|---|---|
| Protocol negotiation | ✅ | Validates version handling |
| Tool discovery | ✅ | Ensures tools are listed correctly |
| Tool execution | ✅ | Tests successful tool calls |
| Error handling | ✅ | Validates error responses |
| Pagination | ✅ | Tests cursor-based resource listing |
| Content formats | ✅ | Validates different response types |
These improvements provide:
- Better Alignment with TypeScript SDK: Content format and error handling now match TS SDK patterns
- Production Readiness: Proper error codes, pagination, and version negotiation
- Developer Experience: Makefile automation and comprehensive tests
- Maintainability: Test coverage prevents regressions
src/server/wasm_server.rs- Core improvementssrc/server/wasm_server_tests.rs- Test suite (new)src/server/mod.rs- Test module registrationexamples/cloudflare-worker-rust/Makefile- Build automation (new)
While not blocking, consider:
- Adding integration tests with actual WASI runtimes
- Performance benchmarking across platforms
- Streaming support investigation for large responses
- Additional content types beyond Text (Image, Resource, etc.)
All suggested polish improvements have been successfully implemented, enhancing the robustness and production-readiness of the WASM/WASI implementation while maintaining the clean architecture and environment independence achieved in the main refactoring.