Skip to content

Phase 4: Implement Advanced Features (Multi-tenancy & UI) #281

@AlexMikhalev

Description

@AlexMikhalev

Goal

Enterprise features and management UI

Tasks

Backend Implementation ✅ COMPLETE

  • Add user_id to all MCP resources
  • Implement public/private namespace scoping
  • Audit trail for tool invocations
  • Add health endpoint (GET /metamcp/health)
  • Add audit listing endpoint (GET /metamcp/audits)
  • AuditMiddleware for automatic tool call logging
  • REST wrapper for MCP tools
  • OpenAPI spec generation at /metamcp/openapi.json

In Progress / Planned

  • Role-based access control for endpoints (future enhancement)
  • Auto-generate OpenAPI specs from MCP tools (manual for now)
  • Swagger UI integration (OpenAPI JSON available for external viewers)

Frontend (Deferred to Phase 5)

  • Extend Svelte frontend with MCP management views
  • Namespace CRUD operations UI
  • Tool enable/disable toggles
  • Endpoint management dashboard
  • Real-time server status display

Completed Features

Phase 4A - Multi-Tenancy & Compliance

Commit: 6ce6d3a

Persistence Layer

  • McpAuditRecord for tool invocation tracking
  • NamespaceVisibility enum (Public/Private) with Private default
  • Audit trail methods: save_audit, get_audit, list_audits, delete_audit
  • list_namespaces_with_visibility for multi-tenancy support
  • OpenDAL-based audit storage

Middleware

  • AuditMiddleware for automatic tool call logging
  • Feature-gated with 'audit' feature flag
  • Tracks: tool name, arguments, response, errors, latency

API Layer

  • get_mcp_health endpoint with namespace/endpoint counts
  • list_audits endpoint (limit 100 recent records)
  • Visibility field in CreateNamespaceRequest

Routes

  • GET /metamcp/health - Server health with counts
  • GET /metamcp/audits - Recent audit trail

Phase 4B - REST API Wrapper

Commit: 3d5a1c3

API Module (terraphim_server/src/api_mcp_tools.rs)

  • list_tools_for_endpoint: Lists all tools for an endpoint
  • execute_tool: Executes tool with JSON arguments
  • create_proxy_from_namespace: Initializes McpProxy from config
  • Error handling for missing endpoints/namespaces

Routes

  • GET /metamcp/endpoints/{endpoint_uuid}/tools
  • POST /metamcp/endpoints/{endpoint_uuid}/tools/{tool_name}

Integration

  • Leverages terraphim_mcp_proxy for routing
  • Uses MCP persistence for lookups
  • Supports all transports (STDIO, SSE, HTTP, OAuth)

Phase 4C - OpenAPI Documentation

Commit: 318f113

API Specification

  • Complete OpenAPI 3.0 spec at GET /metamcp/openapi.json
  • Documented paths, parameters, request/response schemas
  • Ready for Postman/Insomnia/Swagger UI import

Type System

  • McpTool: OpenAPI-compatible tool wrapper
  • McpContentItem: Response content enum
  • ToolListResponse, ToolCallRequestPayload, ToolCallResponsePayload
  • All types implement ToSchema for documentation

Test Coverage

  • Persistence: 6/6 tests passing (audit, visibility)
  • MCP Proxy: 19/19 tests passing
  • MCP Tools API: 7/7 tests passing
  • Total: 32 tests passing ✅

Success Criteria

  • Multi-user support with proper isolation (namespace visibility)
  • Audit trail for compliance
  • REST API for tool execution
  • OpenAPI documentation
  • High test coverage (32 tests)
  • Web UI for managing MCP configuration (deferred to Phase 5)

Usage Examples

# List tools
curl http://localhost:8080/metamcp/endpoints/{uuid}/tools

# Execute tool
curl -X POST http://localhost:8080/metamcp/endpoints/{uuid}/tools/filesystem__read_file \
  -H "Content-Type: application/json" \
  -d '{"arguments": {"path": "/path/to/file"}}'

# Get OpenAPI spec
curl http://localhost:8080/metamcp/openapi.json > mcp-api.json

# Health check
curl http://localhost:8080/metamcp/health

# Audit trail
curl http://localhost:8080/metamcp/audits

Timeline

Week 7-8 (Backend completed ahead of schedule ✅)

Phase 4 COMPLETE - All backend features implemented with full test coverage.

Depends on: Phase 3 ✅

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions