Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,6 +7,8 @@ from datetime import datetime, timedelta
|
|
| 7 |
from starlette.routing import Mount # 用于挂载
|
| 8 |
from fastmcp.server import FastMCP
|
| 9 |
from contextlib import asynccontextmanager
|
|
|
|
|
|
|
| 10 |
import logging
|
| 11 |
|
| 12 |
# 启用 FastMCP 日志调试
|
|
@@ -65,7 +67,9 @@ async def fetch_github_trending():
|
|
| 65 |
return cached_trending if cached_trending else []
|
| 66 |
|
| 67 |
# 定义MCP服务器和工具
|
| 68 |
-
mcp_server = FastMCP(name="GithubTrending")
|
|
|
|
|
|
|
| 69 |
|
| 70 |
@mcp_server.tool()
|
| 71 |
def get_trending_repos(num: int = 10) -> dict:
|
|
@@ -74,7 +78,8 @@ def get_trending_repos(num: int = 10) -> dict:
|
|
| 74 |
fetch_github_trending()
|
| 75 |
return {"trending": cached_trending[:num]}
|
| 76 |
|
| 77 |
-
app.mount("/mcp", mcp_server.http_app())
|
|
|
|
| 78 |
|
| 79 |
async def trending_generator():
|
| 80 |
"""SSE 事件生成器"""
|
|
|
|
| 7 |
from starlette.routing import Mount # 用于挂载
|
| 8 |
from fastmcp.server import FastMCP
|
| 9 |
from contextlib import asynccontextmanager
|
| 10 |
+
from fastmcp.server.fastapi import add_fastmcp_routes
|
| 11 |
+
|
| 12 |
import logging
|
| 13 |
|
| 14 |
# 启用 FastMCP 日志调试
|
|
|
|
| 67 |
return cached_trending if cached_trending else []
|
| 68 |
|
| 69 |
# 定义MCP服务器和工具
|
| 70 |
+
#mcp_server = FastMCP(name="GithubTrending")
|
| 71 |
+
mcp_server = FastMCP(name="GithubTrending", transport="streamable-http")
|
| 72 |
+
|
| 73 |
|
| 74 |
@mcp_server.tool()
|
| 75 |
def get_trending_repos(num: int = 10) -> dict:
|
|
|
|
| 78 |
fetch_github_trending()
|
| 79 |
return {"trending": cached_trending[:num]}
|
| 80 |
|
| 81 |
+
#app.mount("/mcp", mcp_server.http_app())
|
| 82 |
+
add_fastmcp_routes(app, mcp_server, path="/mcp")
|
| 83 |
|
| 84 |
async def trending_generator():
|
| 85 |
"""SSE 事件生成器"""
|