Skip to main content

HttpConnector

Trait HttpConnector 

Source
pub trait HttpConnector:
    Send
    + Sync
    + 'static {
    // Required methods
    fn execute<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        operation: &'life1 Operation,
        args: &'life2 Value,
    ) -> Pin<Box<dyn Future<Output = Result<Value, HttpConnectorError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn base_url(&self) -> &str;

    // Provided methods
    fn execute_for_tool<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        tool: &'life1 str,
        operation: &'life2 Operation,
        args: &'life3 Value,
    ) -> Pin<Box<dyn Future<Output = Result<Value, HttpConnectorError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait { ... }
    fn has_request_policy(&self) -> bool { ... }
    fn governed(
        &self,
        policy: Arc<dyn RequestPolicy>,
    ) -> Option<Arc<dyn HttpConnector>> { ... }
}
Expand description

Backend-agnostic HTTP connector trait (OAPI-01).

The analog of crate::sql::SqlConnector for REST backends: an implementation executes an Operation against a configured base URL and returns the response body as JSON. base_url is the analog of SqlConnector::dialect() — a cheap accessor used by the synthesizer / prompt assembly.

§Example

A minimal connector. The example defines a LOCAL dummy struct so the doctest does not depend on any downstream crate (mirrors the SqlConnector doctest).

use pmcp_server_toolkit::http::{HttpConnector, HttpConnectorError, Operation};
use async_trait::async_trait;
use serde_json::Value;

struct Dummy;

#[async_trait]
impl HttpConnector for Dummy {
    fn base_url(&self) -> &str { "https://api.example.com/v1" }
    async fn execute(&self, _operation: &Operation, _args: &Value)
        -> Result<Value, HttpConnectorError> {
        Ok(Value::Null)
    }
}

Required Methods§

Source

fn execute<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, operation: &'life1 Operation, args: &'life2 Value, ) -> Pin<Box<dyn Future<Output = Result<Value, HttpConnectorError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Execute operation with the caller-supplied args (a JSON object whose keys map to path / query / header / body parameters) and return the response body as a serde_json::Value.

§Errors

Returns HttpConnectorError when the request fails at the transport layer (HttpConnectorError::Request), the backend returns a non-2xx status (HttpConnectorError::Status), authentication cannot be applied (HttpConnectorError::Auth), or a header is invalid (HttpConnectorError::InvalidHeader). Per the type-level Security note, no error message echoes a URL or credential.

Source

fn base_url(&self) -> &str

The configured base URL (analog of SqlConnector::dialect()).

Provided Methods§

Source

fn execute_for_tool<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, tool: &'life1 str, operation: &'life2 Operation, args: &'life3 Value, ) -> Pin<Box<dyn Future<Output = Result<Value, HttpConnectorError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Execute operation on behalf of the MCP tool named tool (Phase 128 E1).

The tool name is the one thing an Operation cannot carry — it describes an endpoint, not a tool — and an E1 crate::policy::RequestPolicy that keys on the tool needs it. The synthesized single-call handler calls THIS method; the default body delegates to execute, so an out-of-repo implementation compiles unchanged and simply reports no tool.

§Errors

As execute.

Source

fn has_request_policy(&self) -> bool

Whether this connector consults an E1 policy before sending (Phase 128).

Default false. Overridden by crate::http::HttpClient. It exists so a registered-but-unreached policy cannot look registered: the wiring that attaches one lives in a different crate (pmcp-openapi-server’s build_server) and the connector is an Arc<dyn HttpConnector> by then, so the only way to PROVE the attachment took is to ask through the trait.

Source

fn governed( &self, policy: Arc<dyn RequestPolicy>, ) -> Option<Arc<dyn HttpConnector>>

A clone of this connector that consults policy before every outbound request (Phase 128 E1), or None when the implementation cannot host one.

None is the default, and a caller that holds a policy MUST treat None as a hard problem rather than a silent no-op — a policy the operator registered and the connector never consults is precisely the present-but-inert defect this phase exists to close.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§