update_item
Modify existing items by updating their name, description, or metadata fields using the item's unique identifier.
Instructions
Update an existing item.
Args: item_id: The unique identifier of the item to update name: New name (optional) description: New description (optional) metadata: New metadata (optional, replaces existing)
Returns: The updated item data
Raises: ValueError: If the item is not found
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| item_id | Yes | ||
| name | No | ||
| description | No | ||
| metadata | No |
Input Schema (JSON Schema)
{
"properties": {
"description": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null
},
"item_id": {
"type": "string"
},
"metadata": {
"anyOf": [
{
"additionalProperties": {
"type": "string"
},
"type": "object"
},
{
"type": "null"
}
],
"default": null
},
"name": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null
}
},
"required": [
"item_id"
],
"type": "object"
}
Implementation Reference
- src/skeleton_mcp/api/example.py:143-185 (handler)The main handler function for the 'update_item' tool. It updates an existing item in the mock data store by ID, allowing optional updates to name, description, and metadata. Updates the 'updated_at' timestamp and returns the modified item.async def update_item( item_id: str, name: str | None = None, description: str | None = None, metadata: dict[str, str] | None = None, ) -> dict[str, Any]: """ Update an existing item. Args: item_id: The unique identifier of the item to update name: New name (optional) description: New description (optional) metadata: New metadata (optional, replaces existing) Returns: The updated item data Raises: ValueError: If the item is not found """ # In a real implementation: # client = get_client() # return client.put(f"items/{item_id}", data={"name": name, "description": description, "metadata": metadata}) if item_id not in MOCK_ITEMS: raise ValueError(f"Item not found: {item_id}") from datetime import datetime, timezone item = MOCK_ITEMS[item_id].copy() if name is not None: item["name"] = name if description is not None: item["description"] = description if metadata is not None: item["metadata"] = metadata item["updated_at"] = datetime.now(timezone.utc).isoformat().replace("+00:00", "Z") MOCK_ITEMS[item_id] = item return item
- src/skeleton_mcp/server.py:92-92 (registration)Registration of the 'update_item' tool using FastMCP's @mcp.tool() decorator applied to the imported example.update_item function.mcp.tool()(example.update_item)
- src/skeleton_mcp/server.py:128-128 (registration)Documentation of the 'update_item' tool in the getting_started prompt.5. update_item - Update an existing item
- Mock data store used by update_item (and other functions) to simulate persistent item storage.MOCK_ITEMS: dict[str, dict[str, Any]] = { "item-1": { "id": "item-1", "name": "Example Item 1", "description": "This is a sample item", "created_at": "2024-01-01T00:00:00Z", "updated_at": "2024-01-01T00:00:00Z", }, "item-2": { "id": "item-2", "name": "Example Item 2", "description": "Another sample item", "created_at": "2024-01-02T00:00:00Z", "updated_at": "2024-01-02T00:00:00Z", }, }