nexus-5/core/mcp/base.py
2026-01-26 11:09:40 -05:00

40 lines
1.0 KiB
Python

"""
MCP Base Module - Shared instance and utilities.
This module creates the FastMCP instance that all tool modules use.
Import `mcp` from here to register tools.
"""
import json
import logging
import os
import sys
from typing import Any
# Add project root to path for Django imports
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
# Setup Django before any model imports
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
import django
django.setup()
from mcp.server.fastmcp import FastMCP
# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
# Create the shared MCP server instance
mcp = FastMCP(name="nexus")
def json_response(data: Any, indent: int = 2) -> str:
"""Convert data to JSON string for MCP response."""
return json.dumps(data, indent=indent, default=str)
def error_response(message: str) -> str:
"""Create an error response."""
return json.dumps({"error": message}, indent=2)