Se guarda carpeta Config y pequeños cambios en mcp
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
# cliente_prueba_http.py
|
||||
|
||||
import asyncio
|
||||
from fastmcp import Client
|
||||
|
||||
async def main():
|
||||
async with Client("http://127.0.0.1:8080/mcp") as client:
|
||||
tools = await client.list_tools()
|
||||
for tool in tools:
|
||||
print(f"🔧 {tool.name} - {tool.description or 'sin descripción'}")
|
||||
|
||||
# ✅ llamar a la herramienta correctamente
|
||||
result = await client.call_tool_mcp(name="esperar", arguments={"segundos": 5})
|
||||
print(f"\nResultado de 'saludar': {result.content[0].text}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
@@ -0,0 +1,30 @@
|
||||
# archivo: sse_server.py
|
||||
|
||||
from fastmcp.server import FastMCP
|
||||
import asyncio
|
||||
from fastmcp import Client
|
||||
|
||||
# Crear la instancia del servidor
|
||||
server = FastMCP(
|
||||
name="ServidorSSE",
|
||||
instructions="Este servidor expone herramientas de prueba.",
|
||||
)
|
||||
|
||||
# Herramienta 1: saludar
|
||||
@server.tool(name="saludar", description="Saluda a una persona por su nombre.")
|
||||
def saludar(nombre: str) -> str:
|
||||
return f"¡Hola, {nombre}!"
|
||||
|
||||
# Herramienta 2: espera asíncrona
|
||||
@server.tool(name="esperar", description="Espera N segundos y responde.")
|
||||
async def esperar(segundos: int) -> str:
|
||||
await asyncio.sleep(segundos)
|
||||
return f"Esperé {segundos} segundos como me pediste."
|
||||
|
||||
# Punto de entrada para ejecutarlo por SSE
|
||||
if __name__ == "__main__":
|
||||
server.run(
|
||||
transport="streamable-http", # <-- cambio aquí
|
||||
host="0.0.0.0",
|
||||
port=8080,
|
||||
)
|
||||
Reference in New Issue
Block a user