Skip to main content
Glama

ERPNext MCP Server

by Zero056
test.pyโ€ข3.64 kB
import asyncio import json import os import sys from pathlib import Path # Add the current directory to Python path sys.path.append(str(Path(__file__).parent)) async def run_interactive(): # Load config config_path = "config/multi_doctype_config.json" if not os.path.exists(config_path): print(f"โŒ Config file not found: {config_path}") return with open(config_path, "r") as f: config = json.load(f) from src.erpnext_client import ERPNextClient from src.permissions import PermissionManager # Initialize clients erp_config = config["erpnext"] client = ERPNextClient( url=erp_config["url"], api_key=erp_config["api_key"], api_secret=erp_config["api_secret"] ) perm_manager = PermissionManager(config) # Test connection print("\n๐Ÿ”— Testing connection...") connected = await client.test_connection() print(f"Connected: {connected}") if not connected: print("โŒ Cannot connect to ERPNext. Exiting.") return # Menu for user print("\n๐Ÿ“Œ Choose operation:") print("1. Get Item") print("2. Create Item") print("3. Update Item") print("4. Delete Item") choice = input("Enter choice (1-4): ").strip() try: if choice == "1": # GET item_code = input("Enter Item Code to fetch: ").strip() result = await client.get_item(item_code) print("\n๐Ÿ“„ Item Data:") print(json.dumps(result, indent=2)) elif choice == "2": # CREATE item_code = input("Enter new Item Code: ").strip() item_name = input("Enter Item Name: ").strip() uom = input("Enter Stock UOM (default Nos): ").strip() or "Nos" group = input("Enter Item Group (default All Item Groups): ").strip() or "All Item Groups" test_data = { "item_code": item_code, "item_name": item_name, "is_stock_item": 1, "stock_uom": uom, "item_group": group, } filtered = perm_manager.filter_allowed_fields(test_data, "Item") result = await client.create_item(filtered) print("\nโœ… Item Created:") print(json.dumps(result, indent=2)) elif choice == "3": # UPDATE item_code = input("Enter Item Code to update: ").strip() field = input("Enter field to update (e.g. item_name): ").strip() value = input(f"Enter new value for {field}: ").strip() update_data = {field: value} filtered = perm_manager.filter_allowed_fields(update_data, "Item") result = await client.update_item(item_code, filtered) print("\nโœ… Item Updated:") print(json.dumps(result, indent=2)) elif choice == "4": # DELETE item_code = input("Enter Item Code to delete: ").strip() confirm = input(f"โš ๏ธ Are you sure you want to delete {item_code}? (yes/no): ").strip().lower() if confirm == "yes": result = await client.delete_item(item_code) print("\nโœ… Item Deleted:") print(json.dumps(result, indent=2)) else: print("โŒ Delete cancelled") else: print("โŒ Invalid choice") except Exception as e: print(f"Error: {e}") print("\nโœ… TEST COMPLETED!") if __name__ == "__main__": asyncio.run(run_interactive())

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Zero056/Mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server