libmuscle.mcp.transport_server module

class libmuscle.mcp.transport_server.RequestHandler[source]

Bases: object

Handles requests sent to a TransportServer.

TransportServers operate in terms of chunks of bytes received and sent in return. RequestHandlers interpret received chunks of bytes, handle the request, and return a chunk of bytes containing an encoded response.

handle_request(request: bytes) bytes[source]

Handle a request.

Parameters

request – A received request

Returns

An encoded response

exception libmuscle.mcp.transport_server.ServerNotSupported[source]

Bases: RuntimeError

class libmuscle.mcp.transport_server.TransportServer(handler: libmuscle.mcp.transport_server.RequestHandler)[source]

Bases: object

A server that accepts MCP connections.

This is a base class for MCP Servers. An MCP Server accepts connections over some lower-level communication protocol, receives requests and returns responses from a RequestHandler.

Create a TransportServer.

Parameters

handler – A handler to handle requests.

close() None[source]

Closes this server.

Stops the server listening, waits for existing clients to disconnect, then frees any other resources.

get_location() str[source]

Returns the location this server listens on.

Returns

A string containing the location.