commit 178a716b9455f3e21ea7917cda8f7b5d4dd13617 Author: Аделина Саттарова Date: Tue Jun 2 06:04:34 2026 +0000 Created main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..93d5774 --- /dev/null +++ b/main.py @@ -0,0 +1,47 @@ +from fastmcp import MCP +import json, os, time + +# Simple in-memory store with JSON persistence +DATA_FILE = "data.json" +store = {} +if os.path.exists(DATA_FILE): + with open(DATA_FILE) as f: + store = json.load(f) + +@MCP.tool() +def save(key: str, value: str): + store[key] = {"value": value, "timestamp": time.time()} + with open(DATA_FILE, "w") as f: + json.dump(store, f) + return f"Saved {key}" + +@MCP.tool() +def get(key: str): + return store.get(key, {}).get("value", None) + +@MCP.tool() +def delete(key: str): + if key in store: + del store[key] + with open(DATA_FILE, "w") as f: + json.dump(store, f) + return f"Deleted {key}" + return f"{key} not found" + +@MCP.tool() +def list_keys(): + return list(store.keys()) + +# Namespace helpers +@MCP.tool() +def save_with_namespace(namespace: str, key: str, value: str): + full = f"{namespace}:{key}" + return save(full, value) + +@MCP.tool() +def get_by_namespace(namespace: str, key: str): + full = f"{namespace}:{key}" + return get(full) + +if __name__ == "__main__": + MCP.run() \ No newline at end of file