LLM代理MCP服务器

一个基于HTTP的工具服务协议服务器,为LangChain代理提供工具服务能力,支持独立运行或本地开发模式。

  • by akhil-jr
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 akhil-jr/genai-llm-agent-mcp-server

使用说明

genai llm代理mcp服务器

一种模型上下文协议(MCP)服务器,为LangChain代理提供基于HTTP的工具服务功能。 还有一个代理连接到mcp服务器。

恋物癖

MCP服务器

  • 可以作为FTTP服务器独立工作
  • 也可以在stdio模式下进行本地开发

代理

  • 使用MCP服务器上的工具
  • 使用本地工具

快速开始

1.设置

git clone https://github.com/akhil-jr/genai-llm-agent-mcp-server.git
cd genai-llm-agent-mcp-server
pip install -r requirements.txt

2.运行MCP服务器

在单独的窗口中启动mcp服务器

cd genai-llm-agent-mcp-server
python -m mcp_server.server

3.运行代理

在原始控制台中继续运行以下查询

cp .env.example .env
#Add your gemini API key in .env file
python -m agent.main

MCP服务器的附加配置

用于使用自定义参数运行

python服务器.py--传输http--主机0.0.0.0--端口8080--路径/mcp

在stdio模式下运行(附带的代理不支持):

python服务器.py——传输stdio

命令行参数

  • --transport:传输协议(stdio, http, sse)-默认值: http
  • --host:HTTP服务器主机-默认值: 127.0.0.1
  • --port:HTTP服务器端口-默认值: 8000
  • --path:HTTP端点路径-默认值: /mcp

程序化使用

连接到stdio服务器

import asyncio
from fastmcp import Client
from src.http_mcp_tools.tools import create_mcp_server

async def main():
    # Create and run server
    mcp = create_mcp_server()
    
    # Connect via client
    async with Client(mcp) as client:
        # Use tools
        result = await client.call_tool("get_customer_details", {"customer_id": "102"})
        print(result.content[0].text)

asyncio.run(main())

连接到HTTP服务器

import asyncio
from fastmcp import Client

async def connect_to_remote_server():
    async with Client("http://localhost:8000/mcp") as client:
        result = await client.call_tool("get_customer_details", {"customer_id": "102"})
        print(result.content[0].text)

asyncio.run(connect_to_remote_server())