new_mcp / app.py
Batnini's picture
Update app.py
bf039d0 verified
Raw
History Blame Contribute Delete
1.43 kB
import gradio as gr
# This will work
def my_tool(text: str) -> str:
"""Process text.
Args:
text: Input text
Returns:
Processed text
"""
return text.upper()
# This won't work (no docstring)
def bad_tool(text: str) -> str:
return text.upper()
# Good: Clear types, docstring, Args/Returns sections
def process_data(data: str, format: str = "json") -> str:
"""Process data in specified format.
Args:
data: Input data string
format: Output format (default: json)
Returns:
Processed data as string
"""
return data
# Good: Handles multiple parameters
def calculate(a: float, b: float, operation: str) -> float:
"""Perform mathematical operation.
Args:
a: First number
b: Second number
operation: Operation (add, subtract, multiply, divide)
Returns:
Result of operation
"""
if operation == "add":
return a + b
# ... more operations
# Avoid: Missing type hints
def bad_function(data): # No return type!
return data
# Avoid: No docstring
def also_bad(text: str) -> str:
return text.upper()
# Avoid: Complex types without clarification
def confusing(data: dict) -> list: # What's in the dict/list?
return []
demo = gr.Interface(fn=my_tool, inputs="text", outputs="text")
if __name__ == "__main__":
demo.launch(mcp_server=True)