# Copyright (c) 2025 CoReason, Inc.
#
# This software is proprietary and dual-licensed.
# Licensed under the Prosperity Public License 3.0 (the "License").
# A copy of the license is available at https://prosperitylicense.com/versions/3.0.0
# For details, see the LICENSE file.
# Commercial use beyond a 30-day trial requires a separate license.
#
# Source Code: https://github.com/CoReason-AI/coreason_mcp

"""Type definitions for the CoReason MCP Gateway.

This module defines common type aliases used across the codebase for
better readability and type checking.
"""

from typing import Any, Dict, Optional, TypeAlias

from coreason_identity.models import UserContext
from mcp.types import CallToolResult
from pydantic import BaseModel, Field

__all__ = ["MCPRequest", "MCPResult", "ServerUrlMapping", "ToolMapping", "UserContext"]

# Defines the mapping structure for tools:
# {
#     "namespaced_tool_name": {
#         "server": "server_name",
#         "original_name": "original_tool_name",
#         "inputSchema": {...},
#         "sensitive": bool
#     }
# }
ToolMapping: TypeAlias = Dict[str, Dict[str, Any]]
"""Type alias for tool mapping structure.

Keys are namespaced tool names (e.g. 'brave_search').
Values are metadata dictionaries containing 'server', 'original_name', 'inputSchema', and 'sensitive'.
"""

# Mapping of server names to URLs or Command strings
ServerUrlMapping: TypeAlias = Dict[str, str]
"""Type alias for server URL mapping.

Keys are server names.
Values are descriptive strings (e.g. HTTP URL or Command string).
"""


class MCPRequest(BaseModel):
    """Standardized request structure for MCP tool execution."""

    tool_name: str = Field(..., description="The namespaced name of the tool to execute.")
    arguments: Dict[str, Any] = Field(default_factory=dict, description="Arguments for the tool.")
    user_context: Optional[UserContext] = Field(default=None, description="Canonical identity passport")


# Alias for result
MCPResult: TypeAlias = CallToolResult
