1212divide, get_history, clear_history) as MCP tools.
1313"""
1414
15- import sys
1615import logging
16+ import inspect
17+ import sys
1718from pathlib import Path
1819
1920# Add the src directory to the Python path
2021sys .path .insert (0 , str (Path (__file__ ).parent .parent / "src" ))
2122
22- from eaa .mcp import run_mcp_server_from_tools
23+ from eaa .core . mcp . server import run_mcp_server_from_tools
2324from eaa .tool .example_calculator import CalculatorTool
2425
2526# Configure logging
3132logger = logging .getLogger (__name__ )
3233
3334
34- def main ():
35+ def log_available_tools (calculator : CalculatorTool ) -> None :
36+ """Log the exposed calculator tool methods."""
37+ logger .info ("Created calculator tool with the following methods:" )
38+ for spec in calculator .exposed_tools :
39+ doc = inspect .getdoc (spec .function ) or "No description"
40+ logger .info (" - %s: %s" , spec .name , doc .split ("." )[0 ])
41+
42+
43+ def print_banner () -> None :
44+ """Print usage information without corrupting stdio MCP transport."""
45+ print (
46+ """
47+ Calculator MCP Server Example
48+ ============================
49+
50+ This server exposes calculator operations as MCP tools:
51+ - add(a, b): Add two numbers
52+ - subtract(a, b): Subtract two numbers
53+ - multiply(a, b): Multiply two numbers
54+ - divide(a, b): Divide two numbers
55+ - get_history(): Get calculation history
56+ - clear_history(): Clear calculation history
57+
58+ Connect this server to your MCP client (like Cursor) to use these tools
59+ in AI conversations.
60+
61+ Press Ctrl+C to stop the server.
62+ """ ,
63+ file = sys .stderr ,
64+ )
65+
66+
67+ def main () -> None :
3568 """Main function to run the MCP calculator server."""
3669 try :
3770 # Create the calculator tool
3871 calculator = CalculatorTool ()
39-
40- logger .info ("Created calculator tool with the following methods:" )
41- for tool_dict in calculator .exposed_tools :
42- logger .info (f" - { tool_dict ['name' ]} : { tool_dict ['function' ].__doc__ .split ('.' )[0 ] if tool_dict ['function' ].__doc__ else 'No description' } " )
43-
72+ log_available_tools (calculator )
73+
4474 # Create and run the MCP server
4575 logger .info ("Starting MCP server..." )
76+ # To expose this server over HTTP for remote clients instead of stdio, use:
77+ # run_mcp_server_from_tools(
78+ # tools=calculator,
79+ # server_name="Calculator MCP Server",
80+ # transport="http",
81+ # host="0.0.0.0",
82+ # port=8000,
83+ # path="/mcp",
84+ # )
4685 run_mcp_server_from_tools (
4786 tools = calculator ,
4887 server_name = "Calculator MCP Server" ,
@@ -56,22 +95,5 @@ def main():
5695
5796
5897if __name__ == "__main__" :
59- print ("""
60- Calculator MCP Server Example
61- ============================
62-
63- This server exposes calculator operations as MCP tools:
64- - add(a, b): Add two numbers
65- - subtract(a, b): Subtract two numbers
66- - multiply(a, b): Multiply two numbers
67- - divide(a, b): Divide two numbers
68- - get_history(): Get calculation history
69- - clear_history(): Clear calculation history
70-
71- Connect this server to your MCP client (like Cursor) to use these tools
72- in AI conversations.
73-
74- Press Ctrl+C to stop the server.
75- """ )
76-
77- main ()
98+ print_banner ()
99+ main ()
0 commit comments