simple_modular_server.py•1.97 kB
from mcp.server.fastmcp import FastMCP
# Import tools directly - this ensures they're properly registered
from tools.search_note_tool import search_notes
from tools.weather_tool import get_weather
from tools.calculator_tool import calculate
from tools.time_tool import get_current_time
from tools.command_line_tool import run_shell_command
from tools.file_operations_tool import file_operations
from tools.note_tool import create_note
# Initialize MCP server
mcp = FastMCP("Modular MCP Server")
# Register tools explicitly with proper MCP decorators
@mcp.tool()
def say_hello(name: str):
"""Say hello to someone."""
return {"message": f"Hello, {name}!"}
@mcp.tool()
def get_weather_tool(city: str):
"""Get current weather for a city using Open-Meteo API (free, no API key required)."""
return get_weather(city)
@mcp.tool()
def calculate_tool(expression: str):
"""Safely evaluate mathematical expressions."""
return calculate(expression)
@mcp.tool()
def time_tool(timezone: str = "local"):
"""Get current time and date."""
return get_current_time(timezone)
@mcp.tool()
def command_line_tool(command: str, safe_mode: bool = True):
return run_shell_command(command, safe_mode)
@mcp.tool()
def file_operations_tool(action: str, path: str, content: str = ""):
return file_operations(action, path, content)
@mcp.tool()
def note_tool(title: str, content: str, category: str = "general"):
return create_note(title, content, category)
@mcp.tool()
def search_note_tool(query: str = "", category: str = ""):
return search_notes(query, category)
# Print registered tools
tools = [say_hello, get_weather_tool, time_tool, calculate_tool, command_line_tool, file_operations_tool, note_tool, search_note_tool]
for tool in tools:
print(f"🔧 Registered MCP tool: {tool.__name__.replace('_tool', '')}")
if __name__ == "__main__":
print(f"🚀 Starting modular MCP server with {len(tools)} tools...")
mcp.run()