Use this file to discover all available pages before exploring further.
Extensions are how you add custom functionality to goose. By implementing a Model Context Protocol (MCP) server, you can provide tools, resources, and prompts that agents can discover and use.
from fastmcp import FastMCP# Initialize MCP servermcp = FastMCP("My Custom Tools")@mcp.tool()def calculate_fibonacci(n: int) -> int: """Calculate the nth Fibonacci number""" if n <= 1: return n a, b = 0, 1 for _ in range(2, n + 1): a, b = b, a + b return b@mcp.tool()def reverse_string(text: str) -> str: """Reverse a string""" return text[::-1]if __name__ == "__main__": mcp.run()
Provide detailed descriptions so the agent understands when to use your tool:
@mcp.tool()def search_database( query: str, filters: dict = None, limit: int = 10) -> list: """ Search the product database using natural language. Use this tool when the user asks about products, inventory, or wants to find items matching certain criteria. Args: query: Natural language search query filters: Optional filters (e.g., {"category": "electronics", "price_max": 100}) limit: Maximum number of results to return (default 10) Returns: List of matching products with name, price, and availability """ # Implementation
Good descriptions improve agent accuracy. Include:
@mcp.tool()def fetch_weather(city: str) -> dict: """Get current weather for a city""" try: response = requests.get(f"https://api.weather.com/v1/weather?city={city}") response.raise_for_status() return response.json() except requests.HTTPError as e: if e.response.status_code == 404: return {"error": f"City '{city}' not found. Check the spelling or try a nearby city."} elif e.response.status_code == 429: return {"error": "API rate limit exceeded. Please try again in a few minutes."} else: return {"error": f"Weather API error: {str(e)}"} except Exception as e: return {"error": f"Unexpected error fetching weather: {str(e)}"}
@mcp.tool()def create_user(email: str, name: str) -> dict: """Create a new user account (idempotent)""" # Check if user exists first existing = db.query(User).filter_by(email=email).first() if existing: return {"id": existing.id, "message": "User already exists"} # Create new user user = User(email=email, name=name) db.add(user) db.commit() return {"id": user.id, "message": "User created"}