cxxmcp 1.1.6
C++ MCP SDK
Loading...
Searching...
No Matches
service.hpp File Reference

Service lifecycle boundary for role-aware MCP peers. More...

#include <condition_variable>
#include <memory>
#include <mutex>
#include <optional>
#include <thread>
#include <utility>
#include "cxxmcp/cancellation.hpp"
#include "cxxmcp/peer.hpp"

Go to the source code of this file.

Classes

struct  mcp::detail::ServiceLifecycleState
 
class  mcp::RunningService< RoleClient >
 Running client-side MCP service. More...
 
class  mcp::RunningService< RoleServer >
 Running server-side MCP service. More...
 
class  mcp::Service< RoleClient >
 Client-side MCP service ready to be served. More...
 
class  mcp::Service< RoleServer >
 Server-side MCP service ready to be served. More...
 

Functions

bool mcp::detail::service_running (const std::shared_ptr< ServiceLifecycleState > &state) noexcept
 
CancellationToken mcp::detail::service_cancellation_token (const std::shared_ptr< ServiceLifecycleState > &state) noexcept
 
template<class Stop >
core::Result< core::Unitmcp::detail::stop_service (const std::shared_ptr< ServiceLifecycleState > &state, Stop stop) noexcept
 
core::Result< core::Unitmcp::detail::wait_service (const std::shared_ptr< ServiceLifecycleState > &state) noexcept
 
void mcp::detail::finish_service (const std::shared_ptr< ServiceLifecycleState > &state, std::optional< core::Error > failure={}) noexcept
 
Service< RoleClientmcp::make_service (ClientPeer peer)
 Creates a client service from a role-aware peer.
 
Service< RoleServermcp::make_service (ServerPeer peer)
 Creates a server service from a role-aware peer.
 
Service< RoleServermcp::make_service (ServerPeer peer, std::unique_ptr< transport::ServerTransport > transport, server::SessionContext context={})
 Creates a server service that is driven by a role-generic transport.
 
core::Result< RunningService< RoleClient > > mcp::serve (ClientPeer peer)
 Starts a client service and returns its running handle.
 
core::Result< RunningService< RoleServer > > mcp::serve (ServerPeer peer)
 Starts a server service and returns its running handle.
 
core::Result< RunningService< RoleServer > > mcp::serve (ServerPeer peer, std::unique_ptr< transport::ServerTransport > transport, server::SessionContext context={})
 Starts a server service over a role-generic transport.
 

Detailed Description

Service lifecycle boundary for role-aware MCP peers.

This header provides a small synchronous lifecycle layer that mirrors RMCP's service-oriented public shape without introducing an async runtime yet.

Lifecycle contract:

  • serve(peer) transfers peer ownership into a RunningService.
  • Server services own a background service loop that calls ServerPeer::start(token), or ServerPeer::serve_transport() when constructed with a one-off role-generic server transport. Client services start the underlying receive side; role-generic client transports are driven by a single background receive loop, while concrete client transports use their own start() callback model.
  • close() and stop() are equivalent, idempotent, noexcept-safe shutdown entry points. They cancel the service token, stop the underlying peer, and unblock wait().
  • wait() blocks until close(), stop(), or destruction completes shutdown.
  • The destructor performs best-effort stop().
  • Moved-from RunningService objects are inert: running() is false and close(), stop(), and wait() return success without touching the moved-to peer.