From 901a9d97dce52fd92ab84799460668ef55ff3e71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D1=80=D0=B8=D1=8F=20=D0=91=D0=B5=D1=80=D0=B4?= =?UTF-8?q?=D0=BD=D0=B8=D0=BA=D0=BE=D0=B2=D0=B0?= Date: Wed, 27 May 2026 07:45:37 +0000 Subject: [PATCH] =?UTF-8?q?MCP-=D1=81=D0=B5=D1=80=D0=B2=D0=B5=D1=80=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D1=83=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=BF=D0=B0=D0=BC=D1=8F=D1=82=D1=8C=D1=8E?= =?UTF-8?q?=20=D0=B0=D0=B3=D0=B5=D0=BD=D1=82=D0=B0:=20README.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../README.md | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 solutions/69f8e929da860fb4533faa2a_MCP-сервер_для_управления_памятью_агента/README.md diff --git a/solutions/69f8e929da860fb4533faa2a_MCP-сервер_для_управления_памятью_агента/README.md b/solutions/69f8e929da860fb4533faa2a_MCP-сервер_для_управления_памятью_агента/README.md new file mode 100644 index 0000000..fd28333 --- /dev/null +++ b/solutions/69f8e929da860fb4533faa2a_MCP-сервер_для_управления_памятью_агента/README.md @@ -0,0 +1,116 @@ +# MCP‑Memory Server + +A lightweight **Model Context Protocol (MCP)** server that exposes a simple key/value memory store for agents and other clients. +The project contains two scripts: + +| File | Purpose | +|------|---------| +| `memory_server.py` | Runs the MCP server, exposing *set*, *get* and *delete* operations on a JSON‑backed storage. | +| `memory_client.py` | Demonstrates how to connect to the server and use its tools from a client script. | + +> **Why MCP?** +> MCP is a lightweight protocol for exchanging structured data between agents, services or CLI utilities. By running this server as a separate process we enable distributed multi‑agent systems to share state without tight coupling. + +--- + +## 📦 Installation + +```bash +# Create and activate a virtual environment (optional but recommended) +python -m venv .venv +source .venv/bin/activate # Windows: .\.venv\Scripts\activate + +# Install the required packages +pip install fastmcp pydantic python-dotenv +``` + +> **Tip:** +> `fastmcp` is a minimal framework for building MCP servers and clients. +> `pydantic` is used internally by `fastmcp` for data validation. + +--- + +## 🚀 Running the Server + +```bash +python memory_server.py +``` + +The server starts on the default port **8000** (you can change it in the script). +It will create a file called `memory_data.json` in the current directory to persist data between restarts. + +### Available Tools + +| Tool | Parameters | Description | +|------|------------|-------------| +| `set` | `key: str`, `value: Any` | Stores a value under the given key. | +| `get` | `key: str` | Retrieves the value for the key (or `null`). | +| `delete` | `key: str` | Removes the key from storage. | + +--- + +## 🧪 Running the Client + +```bash +python memory_client.py +``` + +The client script demonstrates: + +1. Setting a value (`foo = "bar"`). +2. Getting that value back. +3. Deleting the key and verifying it’s gone. + +You can also use the client interactively by editing `memory_client.py` or by sending raw MCP messages via another tool (e.g., `curl`, Postman, or a custom agent). + +--- + +## 📄 Example Usage + +```python +# memory_client.py snippet + +from fastmcp import FastMCPClient + +client = FastMCPClient("Memory-Server", host="localhost", port=8000) + +# Set a key/value pair +client.call_tool("set", {"key": "greeting", "value": "Hello, world!"}) + +# Retrieve the value +response = client.call_tool("get", {"key": "greeting"}) +print(response) # Output: Hello, world! + +# Delete the key +client.call_tool("delete", {"key": "greeting"}) + +# Verify deletion +assert client.call_tool("get", {"key": "greeting"}) is None +``` + +Feel free to integrate this server into your own agent framework or use it as a standalone memory service. + +--- + +## 📁 Project Structure + +``` +. +├── memory_server.py # MCP server implementation +├── memory_client.py # Example client script +└── memory_data.json # (generated) persistent storage +``` + +--- + +## 🔧 Customization + +- **Port** – change the `port` argument in `FastMCP("Memory-Server", port=8000)` inside `memory_server.py`. +- **Storage Path** – modify `self.storage_path = Path("./memory_data.json")` to point elsewhere. +- **Additional Tools** – add new methods decorated with `@self.mcp.tool(...)` following the pattern in the script. + +--- + +## 📜 License + +This project is released under the MIT license. Feel free to fork, extend or use it in your own projects. \ No newline at end of file