Skip to content

Mcp server

Bases: ToolServer

An MCPToolServer manages tools and handles MCP connections

Source code in blue/tools/servers/mcp_server.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
class MCPToolServer(ToolServer):
    """An MCPToolServer manages tools and handles MCP connections"""

    def __init__(self, name, properties={}):
        """Initialize an MCPToolServer instance.

        Parameters:
            name: Name of the tool server
            properties: Properties of the tool server
        """
        super().__init__(name, properties=properties)

    ###### initialization
    def _initialize_properties(self):
        """Initialize default properties for MCP tool server."""
        super()._initialize_properties()

        # server connection properties, host, protocol
        connection_properties = {}
        self.properties['connection'] = connection_properties
        connection_properties['protocol'] = "mcp"
        connection_properties['host'] = "0.0.0.0"
        connection_properties['port'] = 8123

    ##### connections
    def _connect(self, host="0.0.0.0", port=8123, protocol="mcp"):
        """Connect to MCP tool server.

        Parameters:
            host: Host address. Defaults to 0.0.0.0
            port: Port number. Defaults to 8123
            protocol: Protocol type. Defaults to "mcp"

        Returns:
            An MCP FastMCP server instance
        """
        return FastMCP(name=self.name, json_response=False, stateless_http=False)

    def _start_connection(self):
        """Start the MCP tool server connection."""
        connection = self.properties['connection']
        self.connection = self._connect(**connection)

    def start(self):
        """Start the MCP tool server."""
        uvicorn.run(self.connection.streamable_http_app, host=self.properties['connection']['host'], port=self.properties['connection']['port'])

    ##### tools
    # override
    def initialize_tools(self):
        """Initialize tools for MCP tool server. Override this method to add custom tools."""
        pass

    def add_tool(self, tool):
        """Add a tool to the MCP tool server.

        Parameters:
            tool: A Tool object
        """
        self.connection.add_tool(tool.function, tool.name, tool.description)

    def list_tools(self):
        """List available tools on the MCP tool server."""
        return asyncio.run(self.connection.list_tools())

__init__(name, properties={})

Initialize an MCPToolServer instance.

Parameters:

Name Type Description Default
name

Name of the tool server

required
properties

Properties of the tool server

{}
Source code in blue/tools/servers/mcp_server.py
25
26
27
28
29
30
31
32
def __init__(self, name, properties={}):
    """Initialize an MCPToolServer instance.

    Parameters:
        name: Name of the tool server
        properties: Properties of the tool server
    """
    super().__init__(name, properties=properties)

add_tool(tool)

Add a tool to the MCP tool server.

Parameters:

Name Type Description Default
tool

A Tool object

required
Source code in blue/tools/servers/mcp_server.py
75
76
77
78
79
80
81
def add_tool(self, tool):
    """Add a tool to the MCP tool server.

    Parameters:
        tool: A Tool object
    """
    self.connection.add_tool(tool.function, tool.name, tool.description)

initialize_tools()

Initialize tools for MCP tool server. Override this method to add custom tools.

Source code in blue/tools/servers/mcp_server.py
71
72
73
def initialize_tools(self):
    """Initialize tools for MCP tool server. Override this method to add custom tools."""
    pass

list_tools()

List available tools on the MCP tool server.

Source code in blue/tools/servers/mcp_server.py
83
84
85
def list_tools(self):
    """List available tools on the MCP tool server."""
    return asyncio.run(self.connection.list_tools())

start()

Start the MCP tool server.

Source code in blue/tools/servers/mcp_server.py
65
66
67
def start(self):
    """Start the MCP tool server."""
    uvicorn.run(self.connection.streamable_http_app, host=self.properties['connection']['host'], port=self.properties['connection']['port'])
Last update: 2025-10-07