33 lines
1.2 KiB
Python
33 lines
1.2 KiB
Python
|
|
import sys
|
||
|
|
import asyncio
|
||
|
|
import argparse
|
||
|
|
import requests
|
||
|
|
from mcp.client.session import ClientSession
|
||
|
|
from mcp.client.stdio import stdio_client
|
||
|
|
from mcp.client.sse import sse_client
|
||
|
|
|
||
|
|
async def main():
|
||
|
|
parser = argparse.ArgumentParser(description="MCP Remote Proxy Client")
|
||
|
|
parser.add_argument("--url", default="http://dietpi.tail706a7a.ts.net:8001/sse", help="URL do servidor MCP SSE")
|
||
|
|
args = parser.parse_args()
|
||
|
|
|
||
|
|
print(f"Conectando ao servidor MCP remoto: {args.url}", file=sys.stderr)
|
||
|
|
|
||
|
|
try:
|
||
|
|
async with sse_client(args.url) as streams:
|
||
|
|
async with ClientSession(streams[0], streams[1]) as session:
|
||
|
|
await session.initialize()
|
||
|
|
print("Conectado com sucesso! Aguardando comandos da IA...", file=sys.stderr)
|
||
|
|
# Mantém a conexão aberta e repassa STDIO para SSE
|
||
|
|
# Nota: A biblioteca MCP lida com o repasse automaticamente dentro do session
|
||
|
|
await asyncio.Future() # Roda para sempre
|
||
|
|
except Exception as e:
|
||
|
|
print(f"Erro na conexão: {e}", file=sys.stderr)
|
||
|
|
sys.exit(1)
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
try:
|
||
|
|
asyncio.run(main())
|
||
|
|
except KeyboardInterrupt:
|
||
|
|
pass
|