MCP-Frappe/frappe_mcp/tools/naming_series.py
MOHAN 2ee93048e1 feat: Add tools for managing server scripts, client scripts, translations, assignment rules, user permissions, webhooks, API keys, and workflows
- Implemented server and client script management tools in `frappe_mcp/tools/scripts.py`
- Added translation and user permission management tools in `frappe_mcp/tools/translations.py`
- Created user and role management tools in `frappe_mcp/tools/users.py`
- Developed webhook and API key management tools in `frappe_mcp/tools/webhooks.py`
- Introduced workflow management tools in `frappe_mcp/tools/workflow_tools.py`
- Added `pyproject.toml` for project metadata and dependencies
2026-04-21 20:26:45 +05:30

112 lines
3.6 KiB
Python

"""Naming Series tools — manage document naming patterns in Frappe."""
import json
from mcp.types import Tool
from frappe_mcp.client.frappe_api import FrappeClient
def tools() -> list[Tool]:
return [
Tool(
name="frappe_get_naming_series",
description="Get all naming series options for a DocType.",
inputSchema={
"type": "object",
"required": ["doctype"],
"properties": {
"doctype": {"type": "string"},
},
},
),
Tool(
name="frappe_set_naming_series",
description=(
"Set or update naming series options for a DocType. "
"Series format: 'PREFIX-.YYYY.-.MM.-.####' where #### is zero-padded counter."
),
inputSchema={
"type": "object",
"required": ["doctype", "series"],
"properties": {
"doctype": {"type": "string"},
"series": {
"type": "string",
"description": "Newline-separated list of series patterns e.g. 'INV-.YYYY.-.####\\nINV-TEST-.####'",
},
},
},
),
Tool(
name="frappe_get_series_counter",
description="Get the current counter value for a naming series prefix.",
inputSchema={
"type": "object",
"required": ["prefix"],
"properties": {
"prefix": {"type": "string", "description": "Prefix e.g. 'INV-2024-'"},
},
},
),
Tool(
name="frappe_update_series_counter",
description="Manually set the counter for a naming series prefix.",
inputSchema={
"type": "object",
"required": ["prefix", "value"],
"properties": {
"prefix": {"type": "string"},
"value": {"type": "integer", "description": "New counter value"},
},
},
),
]
def handlers() -> dict:
return {
"frappe_get_naming_series": _get_naming_series,
"frappe_set_naming_series": _set_naming_series,
"frappe_get_series_counter": _get_series_counter,
"frappe_update_series_counter": _update_series_counter,
}
async def _get_naming_series(args: dict) -> str:
client = FrappeClient()
result = await client.call_method(
"frappe.core.doctype.naming_series.naming_series.get_options",
arg=args["doctype"],
)
return json.dumps(result, indent=2)
async def _set_naming_series(args: dict) -> str:
client = FrappeClient()
result = await client.call_method(
"frappe.core.doctype.naming_series.naming_series.update_series",
args={
"df": {"options": args["series"]},
"doctype": args["doctype"],
},
)
return json.dumps(result, indent=2)
async def _get_series_counter(args: dict) -> str:
client = FrappeClient()
result = await client.call_method(
"frappe.core.doctype.naming_series.naming_series.get_current",
prefix=args["prefix"],
)
return json.dumps({"prefix": args["prefix"], "current": result}, indent=2)
async def _update_series_counter(args: dict) -> str:
client = FrappeClient()
result = await client.call_method(
"frappe.core.doctype.naming_series.naming_series.update_counter",
prefix=args["prefix"],
value=args["value"],
)
return json.dumps(result, indent=2)