from fastmcp import FastMCP
from fastmcp.server.middleware.error_handling import ErrorHandlingMiddleware
from fastmcp.utilities.types import Image
from mcp.types import Icon

from src.config import settings
from src.middleware import FinamCredentialsMiddleware
from src.servers.account import account_mcp
from src.servers.assets import assets_mcp
from src.servers.market_data import market_data_mcp
from src.servers.order import order_mcp

img = Image(path=settings.PROJECT_PATH / "assets/logo.svg")
icon = Icon(src=img.to_data_uri())

finam_mcp = FastMCP("FinamMCP", icons=[icon])

finam_mcp.mount(account_mcp, namespace="account")
finam_mcp.mount(market_data_mcp, namespace="market_data")
finam_mcp.mount(assets_mcp, namespace="assets")
finam_mcp.mount(order_mcp, namespace="order")

if settings.INCLUDE_SERVERS:
    finam_mcp.enable(tags=settings.INCLUDE_SERVERS, only=True)

finam_mcp.add_middleware(FinamCredentialsMiddleware())
finam_mcp.add_middleware(ErrorHandlingMiddleware())

if __name__ == "__main__":
    finam_mcp.run(transport="http", host="127.0.0.1", port=3000)
