loopback_mcp_persona_guide
Loopback MCP and Tool Catalogue – Persona Guide
This guide explains how CRUDService exposes system commands and workflows as MCP tools in‑process ("loopback MCP"), how they are discovered/merged by the ToolCatalogue, and how clients (UIs and agents) consume them. It provides role‑specific instructions and references.
Architecture overview
Backend developers (CRUDService)
-
Source of truth
- System commands:
config/systems/<system>.yaml(objects.actions/commands) - Workflows:
config/workflows/*.yaml
- System commands:
-
Tool generation
- Class:
src/mcp/loopback/generator.py - Naming (deterministic):
- Default: namespaced
provider.instance.base(e.g.,entra.cont.account.get_by_id,ldap.av.account.get_by_dn). - Workflow →
workflow.<name>. - 50‑char cap with stable hash; fail‑fast on pre‑cap and final collisions.
- Optional Router surface (short names with
oneOf) disabled by default.
- Default: namespaced
- Input schema derivation:
- Commands: prefer
input_schema; else derive fromrequired_paramsand optionalinput_paramshints; fallback{ type: object, additionalProperties: true }. - Workflows: prefer top‑level
parametersJSON Schema; else fallback permissive object.
- Commands: prefer
- Class:
-
Loopback MCP endpoints (FastAPI)
GET /mcp/tools/list– returns[ { name, description, inputSchema, source, metadata, title, annotations } ]POST /mcp/jsonrpc– JSON‑RPC 2.0tools/list→{ result: { tools: [...] } }tools/invoke:- System tool → executes
CommandExecutor.execute_command_action - Workflow tool → validates arguments; by default returns
{ accepted: true }stub - Optional direct start behind flag
MCP_LOOPBACK_WORKFLOW_DIRECT_INVOKE=true(internal ASGI call to/workflow/start)
- System tool → executes
-
Security and scopes
- Discovery requires scope:
mcp.tools.discovery - Invoke requires scope:
mcp.tools.invoke - Both enforced in
src/api/mcp_loopback_routes.py
- Discovery requires scope:
-
ToolCatalogue merge
- Class:
src/services/tool_catalogue.py - Always loads built‑ins from
config/tools.yaml - Includes loopback MCP tools when
config_loaderis provided - External MCP endpoints (optional) from
config/mcp_endpoints.yaml - Name constraints:
ToolInfo.name≤ 64 chars; long names will be skipped and logged
- Class:
-
Observability
- Structured logs for
mcp_tools_list_*andmcp_jsonrpc_*events with correlation IDs and durations - OTEL can be disabled locally:
OTEL_DISABLED=true
- Structured logs for
-
Feature flags / env
MCP_LOOPBACK_WORKFLOW_DIRECT_INVOKE=true→ actually invoke/workflow/startinside tools/invokeOTEL_DISABLED=true(tests/local)
Frontend developers (Visual Designer and SDK)
-
Catalogue APIs
GET /api/crud/tools/list?type=builtin|mcp→ list tools (BFF proxies CRUDService/tools/list)GET /api/crud/tools/search?q=<query>&limit=<n>→ search tools (merged list)
-
Hooks and service (Visual Designer)
src/services/toolService.ts–listTools,searchToolsreturning{ name, type, description, func?, metadata }src/hooks/useTools.ts–useToolList(type?),useToolSearch(q, limit, includeEmpty?)
-
Tool Picker modal (large catalog ready)
- Component:
visual_designer/frontend/src/components/ToolPicker/index.tsx - Features: debounced search, segmented filter (All/Built‑in/MCP), endpoint column for MCP, paging (20/50/100), scroll; disables already selected.
- Usage: In your editor page, keep a Set of selected tool names, pass
alreadySelected, and handleonSelect(ToolInfo)
- Component:
<ToolPicker
open={isOpen}
onClose={() => setOpen(false)}
onSelect={(t) => addTool(t)}
alreadySelected={new Set(selected.map(s => s.name))}
/>
SRE / DevOps
-
BFF routing (proxy to CRUDService MCP)
- File:
ServiceConfigs/BFF/config/routes.yaml - Added:
GET /api/crud/mcp/tools/list→ CRUD/mcp/tools/listPOST /api/crud/mcp/jsonrpc→ CRUD/mcp/jsonrpcGET|POST /api/crud/mcp/*→ CRUD/mcp/{path}
- File:
-
Security middlewares
- CRUDService exempts
/mcp/*from CSRF/origin validation for server‑side clients; keep BFF session auth on/api/crud/*.
- CRUDService exempts
-
Env and resilience
- Disable OTEL locally/tests:
OTEL_DISABLED=true - Tests may bypass FIPS:
ALLOW_NONFIPS_FOR_TESTS=true - Naming/identity:
MCP_NAMING_STRATEGY=global_namespace(default). Fallback suffix when identity missing.MCP_DUPLICATE_POLICY=failenforces uniqueness (pre‑cap and final).MCP_MAX_TOOLScaps publication; list is deterministic and paginated.
- Disable OTEL locally/tests:
Security / Authorization
-
Scopes
mcp.tools.discovery– required for listing toolsmcp.tools.invoke– required for invoking tools- Accepts scopes in
user.scopeornormalized_permissions
-
PDP integration
- Standard
/api/crud/*routes continue to go through BFF with PDP guards by configuration. - Loopback MCP runs in CRUDService; use session → service token flow or rely on BFF proxy with session to enforce policy at the edge.
- Standard
QA / Testing
-
Unit tests
- MCP list:
tests/unit/api/test_mcp_loopback_list.py - MCP invoke:
tests/unit/api/test_mcp_loopback_invoke.py - ToolCatalogue merge:
tests/unit/services/test_tool_catalogue_mcp_merge.py
- MCP list:
-
Integration tests
- Tools routes:
tests/test_tool_routes.py - MCP endpoints:
tests/integration/test_mcp_endpoints.py
- Tools routes:
-
Useful env for tests
OTEL_DISABLED=trueALLOW_NONFIPS_FOR_TESTS=true
External agent integrators
-
Discovery (choose one)
- Direct to CRUDService:
GET /mcp/tools/list - Via BFF proxy:
GET /api/crud/mcp/tools/list(session‑protected)
- Direct to CRUDService:
-
Invocation (JSON‑RPC 2.0)
- Direct:
POST /mcp/jsonrpc - Via BFF:
POST /api/crud/mcp/jsonrpc
- Direct:
Example – list tools:
curl -s -H "Authorization: Bearer <token>" \
http://crud-service:8000/mcp/tools/list
Example – invoke a system tool:
curl -s -H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": "1",
"method": "tools/invoke",
"params": { "name": "svc_thing_do", "arguments": { "id": "123" } }
}' \
http://crud-service:8000/mcp/jsonrpc
Workflow invocation behavior:
- Validates arguments against the tool’s JSON Schema
- Default returns
{ accepted: true, workflow: "<name>", params: {...} } - To start immediately (test/dev), set
MCP_LOOPBACK_WORKFLOW_DIRECT_INVOKE=truein CRUDService and reuse the same JSON‑RPC call
Migration notes and limits
- Tool name length ≤ 64 (Pydantic validation in
ToolInfo); ultra‑long names are skipped with a warning. - Workflows missing full structure still emit tools (schema falls back); starting them may require proper definitions.
- Loopback MCP is always present; external MCP endpoints remain optional and are merged when configured.
See also
- Quickstart:
../../how-to/mcp-quickstart.md - API Reference:
./mcp_api_reference.md - Security & Governance:
./mcp_security_governance.md - Tool Catalogue & Naming:
../../explanation/mcp_tool_catalogue_naming.md - BFF MCP proxy routing:
../../../bff/devops/mcp_proxy_routing.md - Cursor integration:
../../how-to/mcp-cursor-integration.md - Visual Designer Tool Picker:
../../../visual-designer/frontend/tool-picker.md - Tutorials:
../tutorials/mcp-scenario-user-context.md