stdio_server.py 522 B

12345678910111213141516171819202122
  1. from mcp.server.fastmcp import FastMCP
  2. # Create the MCP server
  3. mcp = FastMCP("STDIO Example Server")
  4. @mcp.tool()
  5. def greet(name: str) -> str:
  6. """Greet a user by name"""
  7. return f"Hello, {name}! Welcome to the STDIO server."
  8. @mcp.tool()
  9. def add(a: int, b: int) -> str:
  10. """Add two numbers and return the result"""
  11. return f"The sum of {a} and {b} is {a + b}."
  12. if __name__ == "__main__":
  13. print("Starting MCP server with STDIO transport...")
  14. # The run() method uses stdio by default
  15. mcp.run()