- Add langchain-mcp-adapters dependency - New app/tools/mcp_jina.py: Jina MCP client with filtered tool loading (search_web, read_url, sort_by_relevance) - Update resolve_tools to return (tools, needs_jina_mcp) tuple - Update builder.py: skip graph cache for MCP-bound tools, add search tool guidance to system prompt - Refactor chat.py: extract _run_graph_stream, add MCP/non-MCP paths, update tool titles and summaries for MCP tool names - Tested locally: both MCP search path and non-MCP knowledge path work Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
28 lines
901 B
Python
28 lines
901 B
Python
"""Jina MCP tools via langchain-mcp-adapters."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from langchain_mcp_adapters.client import MultiServerMCPClient
|
|
|
|
from app.config import settings
|
|
|
|
# Only load the 3 tools we need, avoid 19 tools filling the context
|
|
JINA_MCP_TOOL_NAMES = {"search_web", "read_url", "sort_by_relevance"}
|
|
JINA_MCP_URL = "https://mcp.jina.ai/v1"
|
|
|
|
|
|
def create_jina_mcp_client() -> MultiServerMCPClient:
|
|
return MultiServerMCPClient({
|
|
"jina": {
|
|
"url": JINA_MCP_URL,
|
|
"transport": "streamable_http",
|
|
"headers": {"Authorization": f"Bearer {settings.jina_api_key}"},
|
|
}
|
|
})
|
|
|
|
|
|
async def get_jina_mcp_tools(client: MultiServerMCPClient) -> list:
|
|
"""Get filtered Jina MCP tools (search_web / read_url / sort_by_relevance)."""
|
|
all_tools = await client.get_tools()
|
|
return [t for t in all_tools if t.name in JINA_MCP_TOOL_NAMES]
|