M4: Tavily parity + MCP — /search/contents and MCP web_search/fetch_url
- pipeline.search_contents: search then render+extract all results in parallel; per-URL failures degrade to content:null + failed_urls instead of failing the request - REST: POST /search/contents (Tavily-like full flow with trace) - MCP server (streamable HTTP, stateless) mounted at /mcp on the orchestrator; tools web_search (with optional full content) and fetch_url share the exact pipeline + caches as REST Verified: /search/contents end-to-end with parallel scrapes; MCP tool listing and both tool calls via the official Python MCP client. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
53f0d50e7a
commit
a70a6b5f5f
3 changed files with 118 additions and 1 deletions
|
|
@ -9,6 +9,7 @@ from pydantic import BaseModel
|
|||
from . import config, pipeline
|
||||
from .cache import Cache
|
||||
from .logging_setup import setup
|
||||
from .mcp_server import mcp, runtime
|
||||
|
||||
log = setup()
|
||||
|
||||
|
|
@ -17,12 +18,16 @@ log = setup()
|
|||
async def lifespan(app: FastAPI):
|
||||
app.state.client = httpx.AsyncClient()
|
||||
app.state.cache = Cache(config.REDIS_URL)
|
||||
yield
|
||||
runtime["client"] = app.state.client
|
||||
runtime["cache"] = app.state.cache
|
||||
async with mcp.session_manager.run():
|
||||
yield
|
||||
await app.state.cache.close()
|
||||
await app.state.client.aclose()
|
||||
|
||||
|
||||
app = FastAPI(title="LWSS Orchestrator", lifespan=lifespan)
|
||||
app.mount("/mcp", mcp.streamable_http_app())
|
||||
|
||||
|
||||
class ScrapeRequest(BaseModel):
|
||||
|
|
@ -69,6 +74,22 @@ async def search(req: SearchRequest) -> dict:
|
|||
return {"results": results, "trace": trace.as_dict()}
|
||||
|
||||
|
||||
@app.post("/search/contents")
|
||||
async def search_contents(req: SearchRequest) -> dict:
|
||||
try:
|
||||
data = await pipeline.search_contents(app.state.client, req.query, req.max_results, app.state.cache)
|
||||
except pipeline.StageError as exc:
|
||||
log.error("search/contents failed at %s: %s", exc.stage, exc.detail)
|
||||
raise HTTPException(status_code=502, detail={"stage": exc.stage, "error": exc.detail}) from exc
|
||||
log.info(
|
||||
"search/contents %r -> %d results (%d failed)",
|
||||
req.query,
|
||||
len(data["results"]),
|
||||
len(data["failed_urls"]),
|
||||
)
|
||||
return data
|
||||
|
||||
|
||||
@app.post("/scrape")
|
||||
async def scrape(req: ScrapeRequest) -> dict:
|
||||
if not req.url.startswith(("http://", "https://")):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue