Skip to content

Mcp app

mcp_app

AXM MCP Server — discovery shell with a compact facade.

Discovers all AXMTool entry points from installed packages (e.g. axm, axm-bib, axm-formal). By default it exposes them through a compact facade (axm_search / axm_describe / axm_call / axm_capabilities) plus a small hot path of tools that opt in via expose_directly = True — keeping the tools/list payload small.

Set AXM_MCP_FACADE=0 to fall back to the legacy behaviour (register every discovered tool directly), which makes the bascule reversible.

Imports from axm core are limited to axm.tools.base (shared types + tool_metadata) — no business-tool implementations are imported here.

bind_session_from_headers(headers)

Bind a declared write contract to its request session identity.

Source code in packages/axm-mcp/src/axm_mcp/mcp_app.py
Python
def bind_session_from_headers(headers: Mapping[str, str]) -> None:
    """Bind a declared write contract to its request session identity."""
    from axm_mcp.session_contracts import parse_write_contract_header

    session_id = session_id_from_headers(headers)
    raw_contract = _header_value(headers, _WRITE_CONTRACT_HEADER)
    if raw_contract is not None:
        normalized = WriteContract.from_json(raw_contract)
        normalized_header = json.dumps(
            {
                "execution_root": normalized.execution_root,
                "allowed_prefixes": normalized.allowed_prefixes,
                "markdown_only_prefixes": normalized.markdown_only_prefixes,
            }
        )
        session_contract_registry.bind(
            session_id,
            parse_write_contract_header(normalized_header),
        )

build_http_app()

Build the served HTTP app, binding contracts only in shared mode.

Source code in packages/axm-mcp/src/axm_mcp/mcp_app.py
Python
def build_http_app() -> ASGIApp:
    """Build the served HTTP app, binding contracts only in shared mode."""
    return mcp.streamable_http_app()

contract_for_session_id(session_id)

Resolve the write contract attached to one MCP session identity.

Source code in packages/axm-mcp/src/axm_mcp/mcp_app.py
Python
def contract_for_session_id(session_id: str) -> WriteContract:
    """Resolve the write contract attached to one MCP session identity."""
    return session_contract_registry.resolve(session_id)

current_session_id()

Return the identity of the in-flight MCP HTTP request.

Source code in packages/axm-mcp/src/axm_mcp/mcp_app.py
Python
def current_session_id() -> str:
    """Return the identity of the in-flight MCP HTTP request."""
    session_id = _current_session_id.get()
    if session_id is None:
        raise UnboundSessionError("no current MCP session identity")
    return session_id

session_id_from_headers(headers)

Return the MCP session identity carried by request headers.

Source code in packages/axm-mcp/src/axm_mcp/mcp_app.py
Python
def session_id_from_headers(headers: Mapping[str, str]) -> str:
    """Return the MCP session identity carried by request headers."""
    session_id = _header_value(headers, MCP_SESSION_ID_HEADER)
    if session_id is None:
        raise UnboundSessionError("no current MCP session identity")
    return session_id