fastware v0.1.0 /src.fastware.mcp
On this page

MCP (Model Context Protocol) server factory providing per-role agent tool provisioning, tool filtering, and stdio-based server lifecycle management.

#src.fastware.mcp

#src.fastware.mcp

MCP (Model Context Protocol) server factory providing per-role agent tool provisioning, tool filtering, and stdio-based server lifecycle management.

Provides role-based tool filtering and server creation for MCP agent processes. The mcp package is an optional dependency -- this module is importable without it, but create_mcp_server raises a clear error if the package is not installed.

Environment variables consumed by the default server: SA_ROLE -- agent role (implementor, auditor, reviewer, deployer) SA_TASK_ID -- unique task identifier SA_SESSION_ID -- parent session identifier SA_WORKTREE -- absolute path to the git worktree SA_PROJECT_ROOT -- absolute path to the project root SA_SERVER_URL -- server base URL (e.g. http://127.0.0.1:9100) SA_AUTH_TOKEN -- bearer token for server API calls

#register_tools_for_role

python
def register_tools_for_role(server: Any, role: str, tool_modules: list[ModuleType], *, roles: dict[str, dict[str, Any]] | None=None, default_role: str | None=None) -> dict[str, Callable[..., Any]]

Register only the tools allowed by role on server.

Each module in tool_modules must define a TOOLS dict mapping tool name to the callable. Only tools listed in the role's config are registered.

Args:

  • roles: Role definitions dict. If None, uses the module-level ROLES.
  • default_role: Fallback role when role is not found. If None, uses

the module-level DEFAULT_ROLE.

Returns the dict of registered tool name -> function.

#create_mcp_server

python
def create_mcp_server(name: str='fastware-agent', *, role: str | None=None, tool_modules: list[ModuleType] | None=None, roles: dict[str, dict[str, Any]] | None=None, default_role: str | None=None) -> Any

Create a FastMCP server with role-filtered tools.

Parameters


name: Server name passed to FastMCP. role: Agent role. If None, reads SA_ROLE from environment (falling back to default_role or DEFAULT_ROLE). tool_modules: List of modules that define a TOOLS dict. If None, no tools are registered (caller must register manually). roles: Role definitions dict. If None, uses the module-level ROLES. default_role: Fallback role. If None, uses the module-level DEFAULT_ROLE.

Returns


FastMCP The configured server instance.

Raises


RuntimeError If the mcp package is not installed.