mcp_guard_core/
lib.rs

1// Copyright (c) 2025 Austin Green
2// SPDX-License-Identifier: AGPL-3.0
3//
4// This file is part of MCP-Guard.
5//
6// MCP-Guard is free software: you can redistribute it and/or modify
7// it under the terms of the GNU Affero General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10//
11// MCP-Guard is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU Affero General Public License for more details.
15//
16// You should have received a copy of the GNU Affero General Public License
17// along with MCP-Guard. If not, see <https://www.gnu.org/licenses/>.
18//! MCP Guard - A lightweight security gateway for MCP servers
19//!
20//! This crate provides authentication, authorization, rate limiting,
21//! and observability for Model Context Protocol (MCP) servers.
22
23pub mod audit;
24pub mod auth;
25pub mod authz;
26pub mod cli;
27pub mod config;
28pub mod guard_tools;
29pub mod mcp_server;
30pub mod observability;
31pub mod rate_limit;
32pub mod router;
33pub mod server;
34pub mod tier;
35pub mod transport;
36
37#[cfg(test)]
38pub mod mocks;
39
40pub use config::Config;
41
42/// Result type alias for mcp-guard operations
43pub type Result<T> = std::result::Result<T, Error>;
44
45/// Main error type for mcp-guard
46#[derive(Debug, thiserror::Error)]
47pub enum Error {
48    #[error("Configuration error: {0}")]
49    Config(#[from] config::ConfigError),
50
51    #[error("Authentication error: {0}")]
52    Auth(#[from] auth::AuthError),
53
54    #[error("Authorization denied: {0}")]
55    Authz(String),
56
57    #[error("Rate limit exceeded")]
58    RateLimited,
59
60    #[error("Transport error: {0}")]
61    Transport(#[from] transport::TransportError),
62
63    #[error("Router error: {0}")]
64    Router(#[from] router::RouterError),
65
66    #[error("Server error: {0}")]
67    Server(String),
68
69    #[error("IO error: {0}")]
70    Io(#[from] std::io::Error),
71
72    #[error("{0}")]
73    Other(String),
74}