Skip to main content

AprMcpServer

Struct AprMcpServer 

Source
pub struct AprMcpServer { /* private fields */ }
Expand description

MCP server exposing the apr CLI as tools.

M1: initialize, tools/list, tools/call with apr.version. M3: notifications/cancelled routed to in-flight apr.run workers.

Implementations§

Source§

impl AprMcpServer

Source

pub fn new() -> Self

Construct a new server.

Source

pub fn handle_request(&mut self, request: &JsonRpcRequest) -> JsonRpcResponse

Dispatch a single JSON-RPC request synchronously.

This is the in-process test entry point. It does NOT exercise the threading / cancellation machinery — apr.run runs inline with a dummy never-firing cancel receiver and NO notification sink is attached, so apr.finetune silently falls back to its synchronous path even if the request carries params._meta.progressToken. Use Self::run_stdio for the full M3 dispatcher or Self::handle_request_with_sink to drive FALSIFY-MCP-PROGRESS-001 in tests.

The dispatcher enforces two protocol-level invariants before routing: FALSIFY-MCP-005 (jsonrpc must be exactly "2.0" or the response is -32600 Invalid Request) and FALSIFY-MCP-007 (an initialize whose params.protocolVersion mismatches ours returns -32602 Invalid Params instead of advancing to tools/list).

Source

pub fn handle_request_with_sink( &mut self, request: &JsonRpcRequest, sink: &NotificationSink, ) -> Option<JsonRpcResponse>

Dispatch one request with an explicit notification sink (test entry point for FALSIFY-MCP-PROGRESS-001).

The sink is only exercised for tools/call dispatches where (a) the client supplied params._meta.progressToken on the original request AND (b) the target tool supports progress streaming (currently apr.finetune and apr.run). Other methods ignore the sink.

handle_request_with_sink returns None for notifications (methods prefixed with notifications/) because notifications have no id and MUST NOT receive a response per JSON-RPC 2.0. All other methods return Some(response).

Source

pub fn tool_definitions(&self) -> Vec<ToolDefinition>

All tool definitions registered on this server.

Source

pub fn register_in_flight( in_flight: &Arc<Mutex<HashMap<Value, CancelHandle>>>, id: Value, ) -> Receiver<()>

Register a new in-flight request and return its cancel receiver.

Exposed for testing the cancellation routing without spawning a real worker. Production code calls this from Self::run_stdio.

Source

pub fn cancel_in_flight( in_flight: &Arc<Mutex<HashMap<Value, CancelHandle>>>, id: &Value, ) -> bool

Route a notifications/cancelled to the matching in-flight request.

Idempotent: repeated cancels for the same id after the first are silently dropped. References to completed / unknown ids are no-ops. Returns true iff a live handle was signalled.

Source

pub fn run_stdio(&mut self) -> Result<()>

Run the server over stdio (blocking).

Reads one JSON-RPC message per line from stdin. initialize, tools/list, and unknown methods dispatch inline. tools/call spawns a worker thread so a subsequent notifications/cancelled message can flow through the main loop and signal the worker’s cancel channel. Workers write their responses directly to stdout (guarded by a mutex) so the main loop never has to wait on them.

§Errors

Returns an error if stdin/stdout I/O fails.

Source

pub fn in_flight_handle(&self) -> Arc<Mutex<HashMap<Value, CancelHandle>>>

Handle for tests that want to inspect the in-flight registry.

Trait Implementations§

Source§

impl Debug for AprMcpServer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AprMcpServer

Source§

fn default() -> AprMcpServer

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.