Skip to main content

describe

Function describe 

Source
pub fn describe(ctx: &Context, input: McpProjectionInput) -> McpProjection
Expand description

The projection as the capability answers it, for a caller inside this program that already holds the context: mcp --inspect prints the same value the tool, the resource and the route are asked for, and reading it cannot fail, because nothing in it is fetched — the registry, the peer board and the layer’s index are in the context, and a client configuration that cannot be read is one that is absent.

use majordomus_cli::capability::builtin::mcp::{describe, McpProjectionInput};
use majordomus_cli::capability::{builtin, CapabilityRegistry, Context, Effect};
use majordomus_cli::git::GitState;
use majordomus_cli::index::{Index, RepositoryInfo, State};
use std::sync::Arc;
// an index with no objects and no declared provider: the registry alone answers
let index = Index {
    repository: RepositoryInfo {
        root: "/tmp/doc".into(), layer_schema: "ai-repository/v1".into(),
        sections: Default::default(), git: GitState::Unavailable { reason: "doc".into() },
        discovery: "filesystem".into(), source_classes: vec![], kind_sources: vec![],
        scope_origin: majordomus_cli::scope::Origin::Distribution, scope_path: String::new(),
        observed: Default::default(),
    },
    objects: vec![], diagnostics: vec![], state: State::Ok, fingerprint: String::new(),
    scoped: Default::default(), distribution: None, providers: Default::default(),
    share: None,
};
let registry = CapabilityRegistry::builder().with_builtin(builtin::all()).with_index(&index).build().unwrap();
let ctx = Context::new(Arc::new(index), Arc::new(registry));

let all = describe(&ctx, McpProjectionInput::default());
assert_eq!(all.tools.len(), all.tool_count);
assert_eq!(all.effects.iter().map(|e| e.tools).sum::<usize>(), all.tool_count);
// no provider is declared, so there is no client and nothing to be done about one
assert!(all.clients.is_empty() && all.findings.is_empty());

// one effect narrows the tools listed and nothing else
let writers = describe(&ctx, McpProjectionInput { effect: Some(Effect::RepositoryMutation) });
assert_eq!(writers.tool_count, all.tool_count);
assert_eq!(writers.tools.len(), all.writers.len());
assert!(writers.tools.iter().all(|t| all.writers.contains(&t.name)));