Skip to content

Implement Rust SDK#1

Open
bettercallsaulj wants to merge 10 commits intomainfrom
dev_rust_sdk
Open

Implement Rust SDK#1
bettercallsaulj wants to merge 10 commits intomainfrom
dev_rust_sdk

Conversation

@bettercallsaulj
Copy link
Copy Markdown
Collaborator

No description provided.

RahulHere added 10 commits January 23, 2026 03:10
Remove C++ implementation files and update for Rust SDK:
- Remove CMakeLists.txt, Makefile, build.sh
- Remove cmake/, include/, src/, tests/, examples/ directories
- Remove .clang-format
- Update .gitignore for Rust (target/, Cargo.lock, native/)
- Replace gopher-mcp submodule with gopher-orch submodule
- Set gopher-orch to commit 6b45ffbb (MCP server connection fix)
Add build script that:
- Updates git submodules with SSH URL rewrite support
- Handles 'update = none' in gopher-orch/.gitmodules
- Builds gopher-orch native library with CMake
- Fixes macOS dylib install names for DYLD_LIBRARY_PATH
- Copies dependency libraries (gopher-mcp, fmt)
- Builds Rust SDK with Cargo
- Runs tests
Add Rust SDK with the following structure:
- Cargo.toml: Package configuration with libloading dependency
- src/lib.rs: Main library with init/shutdown functions
- src/ffi.rs: FFI bindings using libloading for dynamic loading
- src/agent.rs: GopherAgent implementation with create/run methods
- src/config.rs: ConfigBuilder for fluent configuration
- src/result.rs: AgentResult with status tracking
- src/error.rs: Error types (Library, Agent, Config, etc.)

Features:
- Dynamic library loading (no build-time linking required)
- Builder pattern for configuration
- Thread-safe agent implementation
- Automatic resource cleanup via Drop trait
- Comprehensive error handling with thiserror
Add example demonstrating the Rust SDK with local MCP servers:

examples/client_example_json.rs:
  - Creates GopherAgent with JSON server configuration
  - Connects to two local MCP servers (server3001, server3002)
  - Runs a query and prints the response

examples/client_example_json_run.sh:
  - Convenience script to run the example
  - Starts both MCP servers automatically
  - Sets up library paths for native library loading
  - Cleans up server processes on exit

examples/server3001/:
  - Weather MCP server (get-weather, get-forecast, get-alerts)
  - TypeScript implementation with HTTP/SSE transport

examples/server3002/:
  - Utility MCP server (get-time, generate-password)
  - TypeScript implementation with HTTP/SSE transport
Add integration tests to verify FFI bindings work correctly:

tests/ffi_tests.rs:
  - test_initialization: Verify library initializes without panic
  - test_create_agent_with_server_config: Test agent creation with JSON config
  - test_create_agent_with_helper_method: Test convenience method
  - test_create_agent_with_api_key: Test API key authentication
  - test_create_with_empty_config: Verify proper error for empty config
  - test_run_after_dispose: Verify disposal handling
  - test_run_detailed_returns_result: Test detailed result API
  - test_config_builder: Verify config builder with API key
  - test_config_builder_with_server_config: Verify config builder with server config

Tests gracefully skip if native library is not built.
Fix compatibility issues with older Rust versions:
- Remove thiserror dependency (requires rustc 1.68+)
- Remove serde/serde_json dependencies (not needed for core functionality)
- Use once_cell crate v1.17.0 instead of std::sync::OnceLock (unstable in 1.64)
- Pin libloading to v0.7 for older rustc compatibility
- Implement Error trait manually in error.rs
- Fix borrow checker issue in ffi.rs load_library function
- Fix test to not use unwrap_err() which requires Debug on Ok type
Add #[allow(dead_code)] to AgentResultBuilder struct and impl
to suppress warnings about unused builder pattern code.
The builder is part of the public API for future use.
Comprehensive documentation including:
- Features and architecture overview
- Quick start guide with code examples
- Building from source instructions
- Native library details and search order
- API documentation for GopherAgent and ConfigBuilder
- Error handling patterns
- Examples with local MCP servers
- Development workflow and project structure
- Troubleshooting guide for common issues
- Contributing guidelines
Run cargo fmt and address clippy linting:
- Format all Rust source files with rustfmt
- Fix collapsible_if warning in agent.rs dispose method

Changes:
- src/agent.rs: Format + collapse nested if statements
- src/ffi.rs: Format
- src/lib.rs: Format
- src/result.rs: Format
- tests/ffi_tests.rs: Format
Replace clang-format with rustfmt for checking code formatting in PRs.

Changes:
- Use dtolnay/rust-toolchain@stable with rustfmt component
- Check .rs files instead of C/C++ files
- Run cargo fmt --all -- --check for validation
- Disable submodule checkout to avoid inaccessible repo error
- Update PR comment with Rust-specific fix instructions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant