mcp_server_service.py


Overview

mcp_server_service.py defines the MCPServerService class, which is responsible for managing database operations related to MCP (Multi-Cloud Platform) servers within the InfiniFlow system. This service class extends a common base service (CommonService) to provide specialized methods for retrieving MCP server data based on tenant context, filtering criteria, and pagination requirements.

The primary functionality includes:

This service acts as the data access layer for MCP server entities, abstracting the database queries and providing a clear API for other parts of the system to interact with MCP server records.


Class: MCPServerService

class MCPServerService(CommonService):

Description

MCPServerService is a subclass of CommonService tailored to handle operations on the MCPServer database model. It centralizes MCP server-related queries and encapsulates the logic required to manipulate MCP server data.

Attributes


Methods


get_servers

@classmethod
@DB.connection_context()
def get_servers(cls, tenant_id: str, id_list: list[str] | None, page_number, items_per_page, orderby, desc, keywords)
Description

Fetches MCP server records for a given tenant, supporting optional filtering by server IDs and search keywords. Supports sorting by any specified field and pagination of results.

Parameters
Returns
Usage Example
servers = MCPServerService.get_servers(
    tenant_id="tenant_123",
    id_list=None,
    page_number=1,
    items_per_page=10,
    orderby="create_date",
    desc=True,
    keywords="prod"
)
if servers:
    for server in servers:
        print(server["name"], server["url"])
else:
    print("No MCP servers found.")
Implementation Details

get_by_name_and_tenant

@classmethod
@DB.connection_context()
def get_by_name_and_tenant(cls, name: str, tenant_id: str)
Description

Retrieves a single MCP server record by its name within a specific tenant context. Useful for checking existence or fetching the server details by name.

Parameters
Returns
Usage Example
exists, server = MCPServerService.get_by_name_and_tenant("server_01", "tenant_123")
if exists:
    print(f"Server found: {server.url}")
else:
    print("Server not found.")
Implementation Details

Important Implementation Details


Interaction with Other Parts of the System


Class Diagram

classDiagram
    class CommonService {
        <<abstract>>
        +query(...)
        +create(...)
        +update(...)
        +delete(...)
    }

    class MCPServerService {
        +model = MCPServer
        +get_servers(tenant_id: str, id_list: list[str] | None, page_number, items_per_page, orderby, desc, keywords)
        +get_by_name_and_tenant(name: str, tenant_id: str)
    }

    MCPServerService --|> CommonService
    MCPServerService ..> MCPServer : uses

Summary

mcp_server_service.py provides a focused service layer for MCP server entities in a multi-tenant environment. It abstracts direct database queries, supporting filtered retrieval, sorting, and pagination of MCP server records, along with existence checks by name and tenant. Its integration with the Peewee ORM and the common service base class enables consistent and efficient database operations for the MCP server domain within the InfiniFlow application.