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()