589c5b06fe
- Auto-fixed 70 lint errors (import sorting, aliased errors, datetime.UTC)
- Fixed 85 remaining errors manually:
- E501: wrapped long lines in queen_profiles, catalog, routes_credentials
- F821: added missing TYPE_CHECKING imports for AgentHost, ToolRegistry,
HookContext, HookResult; added runtime imports where needed
- F811: removed duplicate method definitions in queen_lifecycle_tools
- F841/B007: removed unused variables in discovery.py
- W291: removed trailing whitespace in queen nodes
- E402: moved import to top of queen_memory_v2.py
- Fixed AgentRuntime -> AgentHost in example template type annotations
- Reformatted 343 files with ruff format
97 lines
2.6 KiB
Python
97 lines
2.6 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
File Tools MCP Server
|
|
|
|
Minimal FastMCP server exposing 6 file tools (read_file, write_file, edit_file,
|
|
list_directory, search_files, run_command) with no path sandboxing.
|
|
|
|
Usage:
|
|
# Run with STDIO transport (for agent integration)
|
|
python files_server.py --stdio
|
|
|
|
# Run with HTTP transport
|
|
python files_server.py --port 4003
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import logging
|
|
import os
|
|
import sys
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def setup_logger() -> None:
|
|
"""Configure logger for files server."""
|
|
if not logger.handlers:
|
|
stream = sys.stderr if "--stdio" in sys.argv else sys.stdout
|
|
handler = logging.StreamHandler(stream)
|
|
formatter = logging.Formatter("[FILES] %(message)s")
|
|
handler.setFormatter(formatter)
|
|
logger.addHandler(handler)
|
|
logger.setLevel(logging.INFO)
|
|
|
|
|
|
setup_logger()
|
|
|
|
# Suppress FastMCP banner in STDIO mode
|
|
if "--stdio" in sys.argv:
|
|
import rich.console
|
|
|
|
_original_console_init = rich.console.Console.__init__
|
|
|
|
def _patched_console_init(self, *args, **kwargs):
|
|
kwargs["file"] = sys.stderr
|
|
_original_console_init(self, *args, **kwargs)
|
|
|
|
rich.console.Console.__init__ = _patched_console_init
|
|
|
|
from fastmcp import FastMCP # noqa: E402
|
|
|
|
from aden_tools.file_ops import register_file_tools # noqa: E402
|
|
|
|
mcp = FastMCP("files-tools")
|
|
register_file_tools(mcp)
|
|
|
|
|
|
# ── Entry point ───────────────────────────────────────────────────────────
|
|
|
|
|
|
def main() -> None:
|
|
"""Entry point for the File Tools MCP server."""
|
|
parser = argparse.ArgumentParser(description="File Tools MCP Server")
|
|
parser.add_argument(
|
|
"--port",
|
|
type=int,
|
|
default=int(os.getenv("FILES_PORT", "4003")),
|
|
help="HTTP server port (default: 4003)",
|
|
)
|
|
parser.add_argument(
|
|
"--host",
|
|
default="0.0.0.0",
|
|
help="HTTP server host (default: 0.0.0.0)",
|
|
)
|
|
parser.add_argument(
|
|
"--stdio",
|
|
action="store_true",
|
|
help="Use STDIO transport instead of HTTP",
|
|
)
|
|
args = parser.parse_args()
|
|
|
|
if not args.stdio:
|
|
logger.info(
|
|
"Registered 6 file tools: read_file, write_file, edit_file, list_directory, search_files, run_command"
|
|
)
|
|
|
|
if args.stdio:
|
|
mcp.run(transport="stdio")
|
|
else:
|
|
logger.info(f"Starting File Tools server on {args.host}:{args.port}")
|
|
mcp.run(transport="http", host=args.host, port=args.port)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|