Public declaration syntax from forge-rs/crates/forge-contracts/src/mcp.rs Original source SHA-256: 5dae19a0099171cb5a7b7817cb283b09820dc747ef813e373c21b34e9c83b62d Function bodies and constant values are omitted. This is not the complete implementation. Source line 45 pub const CONTRACT_VERSION: &str; Source line 49 #[derive(Debug, Clone, Serialize, Deserialize)] pub struct McpServerConfig { /// Unique name for this MCP server connection. pub server_name: String, /// The transport type for connecting to the server. pub transport: McpTransportType, /// Optional authentication configuration. pub auth: Option, /// Organization that owns this connection. pub org_id: String, /// Optional department scope (only agents in this department can use). pub department_id: Option } Source line 68 #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum McpTransportType { /// Standard I/O transport (subprocess). Stdio { /// Command to execute. command: String, /// Command arguments. args: Vec, }, /// Server-Sent Events over HTTP. Sse { /// The SSE endpoint URL. url: String, }, /// Streamable HTTP transport. Http { /// The HTTP endpoint URL. url: String, }, } Source line 90 #[derive(Debug, Clone, Serialize, Deserialize)] pub struct McpAuthConfig { /// The authentication method. pub method: McpAuthMethod } Source line 97 #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum McpAuthMethod { /// No authentication. None, /// API key authentication. ApiKey { /// Header name for the API key. header: String, }, /// OAuth 2.0 with PKCE. OAuth { /// Authorization endpoint URL. auth_url: String, /// Token endpoint URL. token_url: String, /// Client ID. client_id: String, /// Scopes to request. scopes: Vec, }, } Source line 120 #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct McpServerHandle { /// Unique connection identifier. pub connection_id: String, /// The server name. pub server_name: String, /// Whether the connection is currently alive. pub connected: bool, /// Number of tools available from this server. pub tool_count: u32, /// Number of resources available from this server. pub resource_count: u32 } Source line 139 #[derive(Debug, Clone, Serialize, Deserialize)] pub struct McpToolDescriptor { /// The tool name. pub name: String, /// Human-readable description. pub description: String, /// JSON Schema for the tool's input parameters. pub input_schema: serde_json::Value, /// The MCP server that provides this tool. pub server_name: String } Source line 155 #[derive(Debug, Clone, Serialize, Deserialize)] pub struct McpResourceDescriptor { /// The resource URI. pub uri: String, /// Human-readable name. pub name: String, /// Resource description. pub description: Option, /// MIME type of the resource. pub mime_type: Option, /// The MCP server that provides this resource. pub server_name: String } Source line 190 #[async_trait] pub trait McpContract: Send + Sync { /// Connects to an external MCP server. /// /// # Arguments /// /// * `config` - The server connection configuration. /// /// # Returns /// /// A handle to the connected server. /// /// # Errors /// /// - `ContractError::McpError` if the connection or handshake fails. async fn connect_server(&self, config: McpServerConfig) -> ContractResult; /// Disconnects from an MCP server. /// /// # Arguments /// /// * `connection_id` - The connection to close. async fn disconnect_server(&self, connection_id: &str) -> ContractResult<()>; /// Discovers all tools available from a connected server. /// /// # Arguments /// /// * `connection_id` - The server to query. /// /// # Returns /// /// Tool descriptors from the server. async fn discover_tools(&self, connection_id: &str) -> ContractResult>; /// Discovers all resources available from a connected server. /// /// # Arguments /// /// * `connection_id` - The server to query. /// /// # Returns /// /// Resource descriptors from the server. async fn discover_resources( &self, connection_id: &str, ) -> ContractResult>; /// Invokes a tool on a connected MCP server. /// /// # Arguments /// /// * `connection_id` - The server hosting the tool. /// * `tool_name` - The tool to invoke. /// * `arguments` - The tool's input arguments as JSON. /// * `agent_did` - The agent invoking the tool (for ACT checks). /// /// # Returns /// /// The tool's output as JSON. /// /// # Errors /// /// - `ContractError::McpError` if the tool invocation fails. /// - `ContractError::AuthorizationDenied` if the agent lacks the /// required tool scope. async fn invoke_tool( &self, connection_id: &str, tool_name: &str, arguments: serde_json::Value, agent_did: &str, ) -> ContractResult; /// Reads a resource from a connected MCP server. /// /// # Arguments /// /// * `connection_id` - The server hosting the resource. /// * `uri` - The resource URI. /// /// # Returns /// /// The resource content as JSON. async fn read_resource( &self, connection_id: &str, uri: &str, ) -> ContractResult; /// Lists all connected MCP servers for an organization. /// /// # Arguments /// /// * `org_id` - The organization to query. async fn list_servers(&self, org_id: &str) -> ContractResult>; }