模型上下文协议服务器

一个用于管理AI模型上下文数据的简单实现,提供存储、获取和删除上下文的功能。

  • by linsun
  • Python
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 linsun/simple-agent-and-mcp-server

使用说明

模型上下文协议(MCP)服务器和代理

管理AI模型上下文数据的模型上下文协议服务器的简单实现。

设置

  1. 安装所需的依赖项:
uv venv
uv pip install -r requirements.txt
  1. 运行服务器:
uv run server.py

服务器将于启动 localhost:8080.

API终点

商店上下文

curl -X POST http://localhost:8080/mcp/context \
  -H "Content-Type: application/json" \
  -d '{
    "context_id": "example-context",
    "data": {
      "key": "value",
      "metadata": "example"
    }
  }'

获取上下文

curl -X GET http://localhost:8080/mcp/context/example-context

删除上下文

curl -X DELETE http://localhost:8080/mcp/context/example-context

列出所有工具

curl -X GET http://localhost:8080/mcp/tools

运行代理

OPENAI_API_KEY=$OPENAI_API_KEY uv run agent.py 

样本输出:

Connected to server
LLM decided to use: calculator
Reasoning: The user is asking for the sum of 5 and 3, which is a basic arithmetic operation suitable for the calculator tool.
Tool 'calculator' executed with result: {'status': 'success', 'result': 8}

Final result: {'status': 'success', 'result': 8}
LLM decided to use: calculator
Reasoning: The user requested to multiply two numbers, so a calculator tool is appropriate to perform this arithmetic operation.
Tool 'calculator' executed with result: {'status': 'success', 'result': 24}

Final result: {'status': 'success', 'result': 24}
Disconnected from server