ares_mcp/lib.rs
1// ares/src/mcp/mod.rs
2// MCP module — exposes ARES as an MCP tool provider.
3//
4// Feature layout:
5// `mcp` — protocol glue, client, auth, extension, registry, tools.
6// Zero postgres dependency. Enables MCP *consumers*.
7// `mcp` + `postgres` — adds the MCP *server* (server.rs) and usage tracking
8// (usage.rs), which query tenant DB via sqlx::PgPool.
9//
10// This split exists so downstream library consumers can enable `mcp` for client
11// and registry code without being forced to pull sqlx + postgres into their
12// dependency graph.
13
14#[cfg(feature = "mcp")]
15pub mod extension;
16
17#[cfg(all(feature = "mcp", feature = "postgres"))]
18pub mod server;
19
20#[cfg(feature = "mcp")]
21pub mod tools;
22
23// auth.rs uses ares_store::tenants::TenantDb (postgres-only), so the whole
24// module is gated alongside the server. Its only consumer is mcp::server.
25#[cfg(feature = "mcp")]
26pub mod auth;
27
28#[cfg(all(feature = "mcp", feature = "postgres"))]
29pub mod usage;
30
31#[cfg(feature = "mcp")]
32pub mod client;
33
34#[cfg(feature = "mcp")]
35pub mod registry;
36
37#[cfg(all(feature = "mcp", feature = "postgres"))]
38pub use server::{start_mcp_server, AgentRunner};
39
40#[cfg(feature = "mcp")]
41pub use extension::{McpToolExtension, NoOpMcpExtension};
42
43#[cfg(feature = "mcp")]
44pub use registry::{
45 builtin_ares_tools, extension_dispatch, get_tool, list_tools, register_tool, McpRegistry,
46 RegistryError, ToolRegistered, ToolRegistry, ToolUnregistered,
47};
48
49/// Cordis Service for MCP availability — runtime check replaces `#[cfg(feature = "mcp")]` in handlers.
50///
51/// `check()` returns `cfg!(feature = "mcp")` so both builds compile; handlers branch via
52/// `McpService::check()` or `ctx.get::<McpService>().check()`. Keep Cargo.toml `mcp` feature for dep selection only.
53pub struct McpService;
54impl cordis::Service for McpService {
55 fn name(&self) -> &'static str {
56 "mcp"
57 }
58 fn check(&self) -> bool {
59 cfg!(feature = "mcp")
60 }
61}