deepak191z commited on
Commit
6dae3a1
·
verified ·
1 Parent(s): 919decd

Update calculator_server.py

Browse files
Files changed (1) hide show
  1. calculator_server.py +16 -4
calculator_server.py CHANGED
@@ -1,17 +1,26 @@
1
  from fastmcp import FastMCP
2
  from fastmcp.exceptions import ToolError
 
 
3
 
4
- # Create server with explicit configuration
 
 
 
 
5
  mcp = FastMCP(name="Calculator 🧮")
6
 
 
7
  @mcp.tool
8
  def add(a: float, b: float) -> float:
9
  """Adds two numbers together."""
 
10
  return a + b
11
 
12
  @mcp.tool
13
  def multiply(a: float, b: float) -> float:
14
  """Multiplies two numbers."""
 
15
  return a * b
16
 
17
  @mcp.tool
@@ -20,12 +29,15 @@ def divide(a: float, b: float) -> float:
20
  Divides the first number by the second.
21
  Raises an error if the second number is zero.
22
  """
 
23
  if b == 0:
24
  raise ToolError("Division by zero is not allowed.")
25
  return a / b
26
 
 
27
  if __name__ == "__main__":
28
- import os
29
  port = int(os.environ.get("PORT", 7860))
30
- # Add debug mode to see more error details
31
- mcp.run(transport="streamable-http", host="0.0.0.0", port=port, debug=True)
 
 
 
1
  from fastmcp import FastMCP
2
  from fastmcp.exceptions import ToolError
3
+ import logging
4
+ import os
5
 
6
+ # Set up logging to see what's happening
7
+ logging.basicConfig(level=logging.INFO)
8
+ logger = logging.getLogger(__name__)
9
+
10
+ # 1. Create a FastMCP server instance
11
  mcp = FastMCP(name="Calculator 🧮")
12
 
13
+ # 2. Define tools using the @mcp.tool decorator
14
  @mcp.tool
15
  def add(a: float, b: float) -> float:
16
  """Adds two numbers together."""
17
+ logger.info(f"Adding {a} + {b}")
18
  return a + b
19
 
20
  @mcp.tool
21
  def multiply(a: float, b: float) -> float:
22
  """Multiplies two numbers."""
23
+ logger.info(f"Multiplying {a} * {b}")
24
  return a * b
25
 
26
  @mcp.tool
 
29
  Divides the first number by the second.
30
  Raises an error if the second number is zero.
31
  """
32
+ logger.info(f"Dividing {a} / {b}")
33
  if b == 0:
34
  raise ToolError("Division by zero is not allowed.")
35
  return a / b
36
 
37
+ # 3. Add a main block to run the server
38
  if __name__ == "__main__":
 
39
  port = int(os.environ.get("PORT", 7860))
40
+ logger.info(f"Starting FastMCP server on port {port}")
41
+
42
+ # Remove the debug parameter - it's not supported
43
+ mcp.run(transport="streamable-http", host="0.0.0.0", port=port)