For the complete documentation index, see llms.txt. This page is also available as Markdown.

LangChain集成

將 LangChain 和 LangGraph 代理連接到 TalorData MCP 伺服器,即可將即時網路搜尋、抓取和結構化數據工具添加至您的 AI 工作流程。

託管 MCP

1

获取您的 API 令牌

2

安裝所需軟件包

pip install langchain-mcp-adapters
3

配寘您的 MCP 服務器

import asyncio
from langchain_openai import ChatOpenAI
from langchain.agents import create_agent
from langchain_mcp_adapters.client import MultiServerMCPClient
from dotenv import load_dotenv
import os

load_dotenv()

async def main():
    # Configure MCP client
    client = MultiServerMCPClient({
        "talor_data": {
            "url": "https://mcp.talordata.net/<API_TOKEN>/mcp",
            "transport": "http",
        }
    })

    # Get available tools
    tools = await client.get_tools()
    print("Available tools:", [tool.name for tool in tools])

    # Configure LLM
    llm = ChatOpenAI(
        openai_api_key=os.getenv("OPENROUTER_API_KEY"),
        openai_api_base="https://openrouter.ai/api/v1",
        model_name="moonshotai/kimi-k2"
    )

    # System prompt for web search agent
    system_prompt = """
    You are a web search agent with comprehensive scraping capabilities. Your tools include:
    - **search_engine**: Get search results from Google/Bing/Yandex
    - **scrape_as_markdown**: Extract content from any webpage with bot detection bypass
    - **Structured extractors**: Fast, reliable data from major platforms (Amazon, LinkedIn, Instagram, Facebook, X, TikTok, YouTube, Reddit, Zillow, etc.)
    - **Browser automation**: Navigate, click, type, screenshot for complex interactions

    Guidelines:
    - Use structured web_data_* tools for supported platforms when possible (faster/more reliable)
    - Use general scraping for other sites
    - Handle errors gracefully and respect rate limits
    - Think step by step about what information you need and which tools to use
    - Be thorough in your research and provide comprehensive answers

    When responding, follow this pattern:
    1. Think about what information is needed
    2. Choose the appropriate tool(s)
    3. Execute the tool(s)
    4. Analyze the results
    5. Provide a clear, comprehensive answer
    """

    # Create ReAct agent
    agent = create_agent(
        model=llm,
        tools=tools,
        system_prompt=system_prompt
    )

    # Test the agent
    print("Testing ReAct Agent with available tools...")
    print("=" * 50)

    result = await agent.ainvoke({
        "messages": [("human", "Search for the latest news about AI developments")]
    })

    print("\nAgent Response:")
    print(result["messages"][-1].content)

if __name__ == "__main__":
    asyncio.run(main())
4

設定環境變量

.env在項目目錄中創建一個文件:

OPENROUTER_API_KEY=your_openrouter_api_key_here
5

測試一下是否有效

  • 請替換<API_TOKEN>為您的實際TalorData API令牌

  • 運行你的LangChain腳本

  • 你應該看到 agent 執行網絡搜尋並提供全面的回復。

6

監控使用情況

  • 在 TalorData SERP API-使用記錄中查看您的 API 使用情况。

如需更多協助,請透過 線上客服 或電郵 [email protected] 聯絡我們。

最后更新于