server.py•1.74 kB
#!/usr/bin/env python3
"""
IntelliDiff MCP Server - Intelligent file and folder comparison
"""
import os
from fastmcp import FastMCP
# Import modules
from workspace_security import init_workspace_root
from tools import (
validate_workspace_path, get_file_hash, compare_files, read_file_lines,
batch_get_file_hashes, batch_compare_files, batch_compare_folders
)
from folder_operations import compare_folders, find_identical_files
# Create MCP server
mcp = FastMCP(
name="IntelliDiffServer",
instructions="""
Intelligent file and folder comparison server.
Use for comparing files, finding differences, detecting orphans, and identifying duplicates.
All file paths must be within the configured workspace root for security.
"""
)
# Register tools
mcp.tool(get_file_hash)
mcp.tool(compare_files)
mcp.tool(read_file_lines)
mcp.tool(compare_folders)
mcp.tool(find_identical_files)
# Register batch tools
mcp.tool(batch_get_file_hashes)
mcp.tool(batch_compare_files)
mcp.tool(batch_compare_folders)
def create_server(workspace_path: str = None):
"""Create and return the MCP server with initialized workspace."""
init_workspace_root(workspace_path)
return mcp
def main():
workspace_root = init_workspace_root()
print(f"IntelliDiff MCP Server starting with workspace root: {workspace_root}")
# Check for HTTP mode
mcp_host = os.getenv("HOST", "127.0.0.1")
mcp_port = os.getenv("PORT", None)
if mcp_port:
print(f"Running HTTP server on {mcp_host}:{mcp_port}")
mcp.run(port=int(mcp_port), host=mcp_host, transport="streamable-http")
else:
print("Running stdio server")
mcp.run()
if __name__ == "__main__":
main()