sioul/mcp.rs
1// SPDX-License-Identifier: GPL-3.0-or-later
2// Copyright © 2026 Aurélien Pierre
3
4//! `sioul mcp`: what Sioul keeps on this computer, served to AI agents over
5//! the Model Context Protocol (<https://modelcontextprotocol.io>, revision
6//! 2025-06-18), on standard input and output, as Claude Code and Claude
7//! Desktop start it (docs/mcp.md).
8//!
9//! The pieces stay apart, so that each can be reused:
10//! - `transport`: how messages travel. Standard input and output now, one
11//! JSON-RPC message per line; Streamable HTTP, for ChatGPT and remote
12//! clients, comes as another transport over the same server.
13//! - `protocol`: JSON-RPC 2.0 and the parts of MCP Sioul answers: the
14//! handshake, ping, tools, resources.
15//! - `tools`: the registry, as plain data (a name, a description, a JSON
16//! schema, a function), which another agent protocol can serve as it is.
17//! - `read` and `write`: the tools themselves, on the core's public
18//! functions, as the command line uses them; `phone` (the phone's
19//! messages, calls) and `records` (papers, contracts, letters, time,
20//! invoices, reminders, the moment now) read the rest, read-only.
21//! - `spam`: the spam filter's tools (computers only), on `sioul spam`'s
22//! own reports; `[mcp] spam = false` keeps them from agents.
23//! - `access`: consent per project: every project closed to agents until
24//! the person opens it, things in no project as `[mcp] outside_projects`
25//! says (`sioul_core::consent`); every tool keeps to it.
26//! - `mask`: what is never handed to an agent as it is (docs/ai.md); the
27//! command line's `sioul spam` lists masks the same way.
28//! - `log`: what each agent asked, and what it was given.
29//!
30//! Every tool works on this computer's files only: nothing is sent, no
31//! password or key is read, nothing is deleted. The tools that write add a
32//! task, an event, a note, a draft, a tie or a spam label, or mark a task
33//! done; the next sync sends a task or an event to its server, as it does
34//! for what you change in the window. A draft waits in Sioul's Drafts: only
35//! you send it. Two spam tools start a job apart that reads your mail
36//! servers (the training corpus, read-only) or trains; none moves mail.
37
38mod access;
39mod log;
40pub(crate) mod mask;
41mod phone;
42mod protocol;
43pub(crate) mod read;
44mod records;
45#[cfg(not(target_os = "android"))]
46mod spam;
47mod tools;
48mod transport;
49mod write;
50
51#[cfg(test)]
52mod tests;
53
54use crate::Session;
55
56/// Serves MCP on standard input and output until the client closes them.
57/// Standard output carries the protocol alone: nothing else may print there.
58pub(crate) fn run(s: &Session) -> Result<(), String> {
59 let mut server = protocol::Server::new(&s.config_path, s.tr.language());
60 transport::serve(&mut server, &mut transport::Stdio::new())
61}