genai llm代理mcp服务器
一种模型上下文协议(MCP)服务器,为LangChain代理提供基于HTTP的工具服务功能。 还有一个代理连接到mcp服务器。
恋物癖
MCP服务器
- 可以作为FTTP服务器独立工作
- 也可以在stdio模式下进行本地开发
代理
- 使用MCP服务器上的工具
- 使用本地工具
快速开始
1.设置
git clone https://github.com/akhil-jr/genai-llm-agent-mcp-server.gitcd genai-llm-agent-mcp-serverpip install -r requirements.txt2.运行MCP服务器
在单独的窗口中启动mcp服务器
cd genai-llm-agent-mcp-server
python -m mcp_server.server3.运行代理
在原始控制台中继续运行以下查询
cp .env.example .env
#Add your gemini API key in .env filepython -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())