Skip to main content

cortexai_mcp/
lib.rs

1//! # Model Context Protocol (MCP) Support
2//!
3//! Implementation of the Model Context Protocol for cortex.
4
5#![allow(clippy::type_complexity)]
6#![allow(clippy::await_holding_lock)]
7//! MCP provides a standardized way to connect AI agents to external tools and data sources.
8//!
9//! ## Features
10//!
11//! - **STDIO Transport**: Launch MCP servers as subprocesses
12//! - **SSE Transport**: Connect to HTTP-based MCP servers
13//! - **Tool Integration**: Automatic conversion between MCP tools and agent tools
14//!
15//! ## Example
16//!
17//! ```rust,ignore
18//! use cortexai_mcp::{McpClient, StdioTransport};
19//!
20//! // Connect to an MCP server via stdio
21//! let transport = StdioTransport::spawn("npx", &["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]).await?;
22//! let client = McpClient::new(transport).await?;
23//!
24//! // List available tools
25//! let tools = client.list_tools().await?;
26//!
27//! // Call a tool
28//! let result = client.call_tool("read_file", json!({"path": "/tmp/test.txt"})).await?;
29//! ```
30
31pub mod agent_handler;
32pub mod bridge;
33pub mod client;
34pub mod crew_handler;
35pub mod error;
36pub mod graph_handler;
37pub mod protocol;
38pub mod server;
39pub mod session_resources;
40pub mod http_server;
41pub mod sse_server;
42pub mod transport;
43
44#[cfg(feature = "engine")]
45pub mod tool_proxy_handler;
46#[cfg(feature = "engine")]
47pub mod engine_handler;
48#[cfg(feature = "engine")]
49pub mod crew_engine_handler;
50#[cfg(feature = "engine")]
51pub mod cortex_server;
52
53pub use agent_handler::{
54    simple_agent, AgentMcpConfig, AgentMcpHandler, AgentMcpHandlerBuilder, AgentMcpInput,
55    AgentMcpOutput,
56};
57pub use crew_handler::{
58    CrewMcpConfig, CrewMcpHandler, CrewMcpHandlerBuilder, CrewMcpInput, CrewMcpOutput, TaskResult,
59};
60pub use graph_handler::{
61    GraphMcpConfig, GraphMcpHandler, GraphMcpHandlerBuilder, GraphMcpInput, GraphMcpOutput,
62    NodeExecution,
63};
64pub use bridge::McpToolBridge;
65pub use client::McpClient;
66pub use error::McpError;
67pub use protocol::*;
68pub use server::{
69    AsyncFnTool, FnTool, McpServer, McpServerBuilder, PromptContent, PromptHandler, PromptMessage,
70    ResourceHandler, ServerConfig, ToolHandler,
71};
72pub use session_resources::{
73    MemorySessionStoreAdapter, MemoryTraceStoreAdapter, SessionMetadata, SessionResourceHandler,
74    SessionStoreRead, TraceMetadata, TraceResourceHandler, TraceStoreRead,
75};
76pub use http_server::HttpServerConfig;
77pub use sse_server::SseServerConfig;
78pub use transport::{McpTransport, SseTransport, StdioTransport};
79
80#[cfg(feature = "engine")]
81pub use engine_handler::{EngineHandler, RunAgentInput};
82#[cfg(feature = "engine")]
83pub use crew_engine_handler::{CrewEngineHandler, CrewTaskInput, RunCrewInput};
84#[cfg(feature = "engine")]
85pub use tool_proxy_handler::ToolProxyHandler;
86#[cfg(feature = "engine")]
87pub use cortex_server::{CortexMcpServer, CortexMcpServerBuilder};