aprender_mcp/lib.rs
1//! Model Context Protocol (MCP) server for aprender.
2//!
3//! Exposes the `apr` CLI as MCP tools for Claude Code, Cursor, Cline, and
4//! other MCP clients over JSON-RPC 2.0 stdio transport.
5//!
6//! Spec: `docs/specifications/apr-mcp-server-spec.md`.
7//! Protocol: MCP v2024-11-05 (<https://spec.modelcontextprotocol.io>).
8//!
9//! # Example
10//!
11//! ```no_run
12//! # #[cfg(feature = "native")]
13//! # fn main() -> anyhow::Result<()> {
14//! let mut server = aprender_mcp::AprMcpServer::new();
15//! server.run_stdio()?;
16//! # Ok(())
17//! # }
18//! # #[cfg(not(feature = "native"))]
19//! # fn main() {}
20//! ```
21//!
22//! # Scope (M1–M3 shipped)
23//!
24//! - M1: `initialize` + `tools/list` + the `apr.version` stub.
25//! - M2: 7 subprocess wrappers (`apr.validate`, `apr.tensors`, `apr.bench`,
26//! `apr.qa`, `apr.trace`, `apr.run`, `apr.serve`) + FALSIFY-MCP-005/-007
27//! dispatcher gates + Draft-7 schema meta-validation.
28//! - M3: `apr.finetune` (8th Phase-1 tool), `notifications/cancelled` →
29//! SIGTERM→SIGKILL for `apr.run`, `build.rs` codegen from
30//! `contracts/apr-mcp-tool-schemas-v1.yaml` for both `inputSchema`
31//! (`schemas::APR_<TOOL>_SCHEMA`) and tool-level `description`
32//! (`schemas::APR_<TOOL>_DESCRIPTION`, PMAT-514), and opt-in per-line
33//! `notifications/progress` for `apr.finetune` via
34//! `params._meta.progressToken` (FALSIFY-MCP-PROGRESS-001).
35//!
36//! M4 (in progress) promotes FALSIFY-MCP-003/-004 from surface tests to
37//! real-model end-to-end; M5 ports the dispatcher to `pmcp = "2.3"` and
38//! extends cancellation to `apr.serve`.
39
40pub mod server;
41pub mod tools;
42pub mod types;
43
44/// FALSIFY-MCP-008: per-tool JSON Schema + description constants codegen'd
45/// at build time from `contracts/apr-mcp-tool-schemas-v1.yaml` by `build.rs`.
46///
47/// For each tool, `build.rs` emits two constants:
48/// * `APR_<TOOL>_SCHEMA: &str` — a JSON string whose parsed body is the
49/// tool's MCP `inputSchema`. Consume via `serde_json::from_str`.
50/// * `APR_<TOOL>_DESCRIPTION: &str` — the tool-level description.
51/// Consume via `.to_string()`.
52///
53/// Tools MUST source both fields from this module — hand-coding either in
54/// the tool's source file is caught by `tests/falsify_mcp_008.rs`
55/// (PMAT-514, 2026-04-18).
56pub mod schemas {
57 include!(concat!(env!("OUT_DIR"), "/schemas.rs"));
58}
59
60pub use server::{AprMcpServer, NotificationSink};
61pub use types::{
62 ContentBlock, InputSchema, JsonRpcError, JsonRpcNotification, JsonRpcRequest, JsonRpcResponse,
63 PropertySchema, ServerCapabilities, ToolCallResult, ToolDefinition, ToolsCapability,
64};
65
66/// MCP protocol version this server implements.
67pub const PROTOCOL_VERSION: &str = "2024-11-05";
68
69/// Server identity reported in `initialize` response.
70pub const SERVER_NAME: &str = "aprender-mcp";