Skip to main content

SomaContext

Struct SomaContext 

Source
pub struct SomaContext {
    pub project_dir: PathBuf,
    pub kb: Box<dyn KnowledgeBase>,
    /* private fields */
}
Expand description

Server-side state for the Soma MCP server.

Fields§

§project_dir: PathBuf

Project directory (where user’s filter code lives).

§kb: Box<dyn KnowledgeBase>

Knowledge base for experiment tracking.

Implementations§

Source§

impl SomaContext

Source

pub fn new(project_dir: impl Into<PathBuf>) -> Self

Create a context with a persistent knowledge base when one is available: SOMA_KB_PATH if set, else the project’s .soma/experiments.jsonl when a .soma/ directory exists. Falls back to the in-memory KB otherwise (records are lost on server exit).

Source

pub fn with_env_override( project_dir: impl Into<PathBuf>, env_override: Option<String>, ) -> Self

Deterministic constructor: env_override plays the role of the SOMA_KB_PATH environment variable. Used by new() and by tests, which must never depend on (or leak through) the real process environment.

Source

pub fn refresh_kb(&mut self)

Pick up experiments another process appended since the last call. An MCP server outlives many training runs; without this it answers every question from the snapshot it loaded at startup.

Source

pub fn kb_location(&self) -> Option<String>

Human-readable location of the journal, when it has one.

Source

pub fn tracking_root(&self) -> PathBuf

The tracking root this project’s runs live under (.soma).

Source

pub fn list_filters(&self, params: &Value) -> ToolCallResult

list_filters: every .py/.rs file under path (default: the project directory), recursing but skipping hidden directories. Returns a JSON array of {"path": ...} objects.

Like every handler below, it takes the raw arguments object from tools/call and reports a missing or bad argument as a ToolCallResult::error — the model reads the message and can retry, which a protocol-level error would not allow.

Source

pub fn read_filter_source(&self, params: &Value) -> ToolCallResult

read_filter_source: the contents of file_path, resolved against the project directory when relative.

Source

pub fn write_filter_source(&self, params: &Value) -> ToolCallResult

write_filter_source: write content to file_path, creating parent directories as needed. An existing file is copied to a .bak sibling first — a model editing code deserves one level of undo.

Source

pub fn run_pipeline(&self, params: &Value) -> ToolCallResult

run_pipeline: build the graph the model described and run it.

The nodes name filters that live in the project — the same files list_filters lists and read_filter_source reads — so the loop a model works in is closed: read the code, write a variant, run it, read the result out of the experiment pool.

Tracked by default, so the run lands in .soma/experiments.jsonl with a lineage and kb_summarize_run can be pointed at it.

Source

pub fn run_study(&self, params: &Value) -> ToolCallResult

run_study: the same graph spec, searched.

The search space is not a second vocabulary — a node config value written as {"__search__": {...}} becomes a dimension, and graph.search_space() finds it. So the difference between running a graph once and searching it is which values were marked.

Source

pub fn record_experiment(&mut self, params: &Value) -> ToolCallResult

record_experiment: append an experiment to the knowledge base. id and name are required; hypothesis, research line, pipeline summary, parent, notes, tags, metrics and params are taken when present and silently skipped when absent or of the wrong JSON type — a partial record beats no record.

Source

pub fn query_knowledge_base(&self, params: &Value) -> ToolCallResult

query_knowledge_base: free-text search over recorded experiments (query, plus max_results, default 10). Returns a JSON array of experiment summaries — id, name, hypothesis, line, metrics, tags — enough to decide which one to ask more about.

Source

pub fn get_trajectory(&self, params: &Value) -> ToolCallResult

get_trajectory: the values of metric across the experiments of research_line, in recording order — how the line has been moving, as {experiment_id, value} pairs.

Source

pub fn get_change_points(&self, params: &Value) -> ToolCallResult

get_change_points: the experiments where metric jumped by more than threshold (default 0.05) within research_line — the moments worth reading closely, with before/after values and a description of each.

Source

pub fn list_research_lines(&self, _params: &Value) -> ToolCallResult

list_research_lines: every research line in the pool, with its trend, experiment count and best metric so far. Takes no arguments.

Source

pub fn promising_lines(&self, params: &Value) -> ToolCallResult

promising_lines: the research lines with an improving trend, or whose best result is on metric — where the next experiment is most likely to pay off.

Source

pub fn create_research_line(&mut self, params: &Value) -> ToolCallResult

create_research_line: start a named line by recording a <name>_init marker experiment carrying the description. Lines have no existence of their own in the pool — they are the set of experiments tagged with them, so creating one means recording one.

Source

pub fn generate_report(&self, params: &Value) -> ToolCallResult

generate_report: a Markdown report for research_line — the experiment table, the trajectory of its first metric, the significant changes, and the line’s trend. Markdown because the consumer is a model (or a human pasted the output): structure survives, no renderer needed.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> AsAny for T
where T: Any,

§

fn as_any(&self) -> &(dyn Any + 'static)

The receiver as &dyn Any, ready for downcast_ref.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more