Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 18 additions & 133 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,21 @@ path = "src/main.rs"

[dependencies]
anyhow = "1"
axum = { version = "0.8", features = ["http2", "ws"] }
clap = { version = "4.0", features = ["derive"] }
dirs = "6.0"
dotenvy = "0.15"
futures = "0.3.31"
http = "1.3.1"
http-body-util = "0.1.3"
hyper = { version = "1.7.0", features = ["http1", "server"] }
oci-distribution = "0.11"
rmcp = { version = "0.7.0", features = ["server", "transport-io", "transport-streamable-http-server"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_yaml = "0.9"
thiserror = "2.0"
tokio = { version = "1.0", features = ["full"] }
tower = { version = "0.5", features = ["full"] }
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] }
wasmtime = "37.0"
Expand Down
29 changes: 25 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::WasiMcpError;
use crate::error::Result;
use crate::WasmicError;
use crate::error::WasmicResult;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::path::PathBuf;
Expand All @@ -10,6 +10,10 @@ pub struct Config {
/// Components configuration
pub components: HashMap<String, ComponentConfig>,

/// Global authentication middleware name
#[serde(default, skip_serializing_if = "Option::is_none")]
pub auth: Option<MiddlewareConfig>,

/// Prompts configuration
#[serde(default, skip_serializing_if = "std::collections::HashMap::is_empty")]
pub prompts: HashMap<String, Prompt>,
Expand Down Expand Up @@ -42,6 +46,23 @@ pub struct VolumeMount {
pub read_only: bool,
}

/// Middleware configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MiddlewareConfig {
/// Path to the local WASM component file (mutually exclusive with oci)
#[serde(default, skip_serializing_if = "Option::is_none")]
pub path: Option<String>,
/// OCI reference for the WASM component (mutually exclusive with path)
#[serde(default, skip_serializing_if = "Option::is_none")]
pub oci: Option<String>,
/// Environment variables for the middleware
#[serde(default, skip_serializing_if = "std::collections::HashMap::is_empty")]
pub env: HashMap<String, String>,
/// Optional description of the middleware
#[serde(default, skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
}

/// Individual component configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ComponentConfig {
Expand Down Expand Up @@ -69,11 +90,11 @@ pub struct ComponentConfig {

impl Config {
/// Load configuration from a YAML file
pub fn from_file(path: &PathBuf) -> Result<Self> {
pub fn from_file(path: &PathBuf) -> WasmicResult<Self> {
let content = std::fs::read_to_string(path)?;

let config: Config = serde_yaml::from_str(&content).map_err(|e| {
WasiMcpError::InvalidArguments(format!("Invalid YAML configuration: {e}",))
WasmicError::InvalidArguments(format!("Invalid YAML configuration: {e}",))
})?;

tracing::debug!(
Expand Down
8 changes: 4 additions & 4 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use thiserror::Error;

pub type Result<T> = std::result::Result<T, WasiMcpError>;
pub type WasmicResult<T> = std::result::Result<T, WasmicError>;

#[derive(Error, Debug)]
pub enum WasiMcpError {
pub enum WasmicError {
#[error("WASM component error: {0}")]
Component(#[from] wasmtime::Error),

Expand Down Expand Up @@ -35,8 +35,8 @@ pub enum WasiMcpError {
UnexpectedExpected(String, String),
}

impl From<WasiMcpError> for rmcp::ErrorData {
fn from(err: WasiMcpError) -> Self {
impl From<WasmicError> for rmcp::ErrorData {
fn from(err: WasmicError) -> Self {
rmcp::ErrorData::internal_error(err.to_string(), None)
}
}
Loading
Loading