Files
solidcraft/crates/mcp/src/skill_reference.rs
T
raykholo 36a354e3a7 Agent chat: serve the bundled skills' reference through an MCP tool (#4966) (#4970)
* claim: #4966

* Agent chat: serve the bundled skills' reference through an MCP tool (#4966)

The bundled skills start with "read reference.md", but SolidCraft's own
chat turns the agent's file tools off, so its agent could not follow them.

The MCP server gains a read-only `skill_reference` tool that returns a
skill's documents from copies built into the binary. It takes a skill
name and a file name from a fixed list, never a path, and refuses an
unknown skill or file with the available ones. The skills point to it,
and docs/mcp.md and skills/README.md describe it.
2026-10-23 13:43:54 +00:00

51 lines
2.1 KiB
Rust

//! Read-only access to the skill documents shipped with SolidCraft.
use serde_json::{Map, Value};
struct Skill {
name: &'static str,
files: &'static [(&'static str, &'static str)],
}
// Exact names only: these are embedded documents, never filesystem paths to open.
const SKILLS: &[Skill] = &[
Skill {
name: "solidcraft-checking",
files: &[
("SKILL.md", include_str!("../../../skills/solidcraft-checking/SKILL.md")),
("reference/porting.md", include_str!("../../../skills/solidcraft-checking/reference/porting.md")),
],
},
Skill { name: "solidcraft-editing", files: &[("SKILL.md", include_str!("../../../skills/solidcraft-editing/SKILL.md"))] },
Skill {
name: "solidcraft-mechanisms",
files: &[
("SKILL.md", include_str!("../../../skills/solidcraft-mechanisms/SKILL.md")),
("reference.md", include_str!("../../../skills/solidcraft-mechanisms/reference.md")),
],
},
Skill {
name: "solidcraft-modeling",
files: &[
("SKILL.md", include_str!("../../../skills/solidcraft-modeling/SKILL.md")),
("reference.md", include_str!("../../../skills/solidcraft-modeling/reference.md")),
],
},
];
pub(crate) fn read(args: &Map<String, Value>) -> Result<Value, String> {
let name = args.get("skill").and_then(Value::as_str).ok_or("`skill` is required and must be a string")?;
let skill = SKILLS
.iter()
.find(|s| s.name == name)
.ok_or_else(|| format!("Unknown skill. Available skills: {}", SKILLS.iter().map(|s| s.name).collect::<Vec<_>>().join(", ")))?;
let file = match args.get("file") {
None | Some(Value::Null) => "reference.md",
Some(Value::String(file)) => file,
Some(_) => return Err("`file` must be a string".into()),
};
skill.files.iter().find(|(name, _)| *name == file).map(|(_, text)| Value::String((*text).into())).ok_or_else(|| {
format!("Unknown file for {}. Available files: {}", skill.name, skill.files.iter().map(|(name, _)| *name).collect::<Vec<_>>().join(", "))
})
}