feat: event research mcp
Browse files- event_research.py +36 -0
- requirements.txt +2 -0
- server.py +2 -0
event_research.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from mcp.server.fastmcp import FastMCP
|
| 2 |
+
from playwright.sync_api import sync_playwright
|
| 3 |
+
from bs4 import BeautifulSoup
|
| 4 |
+
import pandas as pd
|
| 5 |
+
|
| 6 |
+
mcp = FastMCP(name="Event research", stateless_http=True)
|
| 7 |
+
|
| 8 |
+
@mcp.tool(description="Analyze all games from the last 30 days and return behavioral patterns")
|
| 9 |
+
def get_chess_event():
|
| 10 |
+
url = "https://www.echecsfrance.com/en/tournaments"
|
| 11 |
+
|
| 12 |
+
with sync_playwright() as p:
|
| 13 |
+
browser = p.chromium.launch(headless=True)
|
| 14 |
+
page = browser.new_page()
|
| 15 |
+
print(f"🌐 Chargement de {url} ...")
|
| 16 |
+
page.goto(url, timeout=60000)
|
| 17 |
+
page.wait_for_timeout(5000) # attendre le rendu JS
|
| 18 |
+
html = page.content()
|
| 19 |
+
browser.close()
|
| 20 |
+
|
| 21 |
+
soup = BeautifulSoup(html, "html.parser")
|
| 22 |
+
table = soup.find("table")
|
| 23 |
+
|
| 24 |
+
if not table:
|
| 25 |
+
print("❌ Aucun tableau trouvé dans le DOM final")
|
| 26 |
+
return None
|
| 27 |
+
|
| 28 |
+
headers = [th.text.strip() for th in table.find_all("th")]
|
| 29 |
+
rows = [
|
| 30 |
+
[td.text.strip() for td in tr.find_all("td")]
|
| 31 |
+
for tr in table.find_all("tr")[1:]
|
| 32 |
+
if tr.find_all("td")
|
| 33 |
+
]
|
| 34 |
+
|
| 35 |
+
df = pd.DataFrame(rows, columns=headers)
|
| 36 |
+
return df.to_json()
|
requirements.txt
CHANGED
|
@@ -64,3 +64,5 @@ typing_extensions==4.15.0
|
|
| 64 |
urllib3==2.5.0
|
| 65 |
uvicorn==0.35.0
|
| 66 |
Werkzeug==3.1.1
|
|
|
|
|
|
|
|
|
| 64 |
urllib3==2.5.0
|
| 65 |
uvicorn==0.35.0
|
| 66 |
Werkzeug==3.1.1
|
| 67 |
+
pandas,
|
| 68 |
+
bs4,
|
server.py
CHANGED
|
@@ -5,6 +5,7 @@ from fastapi.staticfiles import StaticFiles
|
|
| 5 |
from fastapi.templating import Jinja2Templates
|
| 6 |
from echo_server import mcp as echo_mcp
|
| 7 |
from math_server import mcp as math_mcp
|
|
|
|
| 8 |
import os
|
| 9 |
|
| 10 |
|
|
@@ -14,6 +15,7 @@ async def lifespan(app: FastAPI):
|
|
| 14 |
async with contextlib.AsyncExitStack() as stack:
|
| 15 |
await stack.enter_async_context(echo_mcp.session_manager.run())
|
| 16 |
await stack.enter_async_context(math_mcp.session_manager.run())
|
|
|
|
| 17 |
yield
|
| 18 |
|
| 19 |
|
|
|
|
| 5 |
from fastapi.templating import Jinja2Templates
|
| 6 |
from echo_server import mcp as echo_mcp
|
| 7 |
from math_server import mcp as math_mcp
|
| 8 |
+
from event_research import mcp as event_research_mcp
|
| 9 |
import os
|
| 10 |
|
| 11 |
|
|
|
|
| 15 |
async with contextlib.AsyncExitStack() as stack:
|
| 16 |
await stack.enter_async_context(echo_mcp.session_manager.run())
|
| 17 |
await stack.enter_async_context(math_mcp.session_manager.run())
|
| 18 |
+
await stack.enter_async_context(event_research_mcp.session_manager.run())
|
| 19 |
yield
|
| 20 |
|
| 21 |
|