Spaces:
Sleeping
Sleeping
File size: 1,105 Bytes
08dd397 66b4ff6 08dd397 66b4ff6 08dd397 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
from fastmcp import FastMCP
import numpy as np
mcp = FastMCP("Demo 🚀")
@mcp.tool()
def hello(name: str) -> str:
return f"Hello, {name}!"
@mcp.tool()
def multiply(a: float, b: float) -> float:
"""Multiplies two numbers."""
return a * b
@mcp.tool()
def inner_product(a: list[float], b: list[float]) -> float:
"""Calculates the inner product of two vectors."""
return np.dot(a, b)
@mcp.tool()
def matrix_multiply(a: list[list[float]], b: list[list[float]]) -> list[list[float]]:
"""Multiplies two matrices."""
return np.matmul(a, b)
# Static resource
@mcp.resource("config://version")
def get_version():
return "2.0.1"
# Dynamic resource template
@mcp.resource("users://{user_id}/profile")
def get_profile(user_id: int):
# Fetch profile for user_id...
return {"name": f"User {user_id}", "status": "active"}
@mcp.prompt()
def summarize_request(text: str) -> str:
"""Generate a prompt asking for a summary."""
return f"Please summarize the following text:\n\n{text}"
if __name__ == "__main__":
mcp.run(transport="sse", host="0.0.0.0", port=7860) |