1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// SPDX-License-Identifier: MIT OR Apache-2.0
//! Model Context Protocol (MCP) implementation.
//!
//! This module provides the core implementation of the Model Context Protocol, enabling
//! AI models and agents to interact with tools and services through a standardized
//! JSON-RPC interface. The MCP allows for dynamic tool discovery and invocation,
//! supporting both built-in and dynamically registered tools.
//!
//! # Architecture
//!
//! The MCP implementation is divided into main components:
//!
//! - **Tool Management**: The [`tools`] module provides tool registration, discovery,
//! and invocation capabilities
//! - **Dynamic Tools**: Internal tools provide runtime tool discovery, allowing agents
//! to discover tools added after initialization
//!
//! # Usage
//!
//! The MCP system supports two primary operations:
//!
//! 1. **Tool Discovery** (`tools/list`): Returns a list of available tools with their
//! schemas and descriptions
//! 2. **Tool Invocation** (`tools/call`): Executes a specific tool with provided parameters
//!
//! # Dynamic Tool Discovery
//!
//! The MCP includes special built-in tools for dynamic discovery:
//! - `latest_tools`: Lists all currently available tools, including those added at runtime
//! - `run_latest_tool`: Executes tools discovered through `latest_tools`
//!
//! This allows agents that cache tool lists at startup to discover and use tools that
//! were registered after initialization.
//!
//! # Examples
//!
//! ## Registering custom tools
//!
//! ```
//! use exfiltrate::mcp::tools::{Tool, InputSchema, Argument, ToolCallResponse, ToolCallError};
//! use std::collections::HashMap;
//!
//! struct MyCustomTool;
//!
//! impl Tool for MyCustomTool {
//! fn name(&self) -> &str {
//! "my_tool"
//! }
//!
//! fn description(&self) -> &str {
//! "A custom tool for demonstration"
//! }
//!
//! fn input_schema(&self) -> InputSchema {
//! InputSchema::new(vec![
//! Argument::new(
//! "input".to_string(),
//! "string".to_string(),
//! "Input text to process".to_string(),
//! true
//! ),
//! ])
//! }
//!
//! fn call(&self, params: HashMap<String, serde_json::Value>)
//! -> Result<ToolCallResponse, ToolCallError> {
//! // Tool implementation
//! Ok(ToolCallResponse::new(vec!["Result".into()]))
//! }
//! }
//!
//! // Register the tool
//! exfiltrate::mcp::tools::add_tool(Box::new(MyCustomTool));
//!
//! ```
use crate;
pub
/// Dispatches incoming JSON-RPC requests to appropriate handlers in the target application.
///
/// This is the main entry point for handling MCP protocol requests. It routes requests
/// based on their method name to the appropriate handler functions.
///
/// # Supported Methods
///
/// - `tools/list`: Returns a list of all available tools with their schemas
/// - `tools/call`: Invokes a specific tool with provided parameters
///
/// # Arguments
///
/// * `request` - The JSON-RPC request to process
///
/// # Returns
///
/// A JSON-RPC response containing either the result of the operation or an error
///
pub