Skip to content

Commit de3b82a

Browse files
authored
feat: tools for exploring and slicing objects in the object store (#118)
1 parent ec2f744 commit de3b82a

1 file changed

Lines changed: 37 additions & 2 deletions

File tree

src/deepset_mcp/tool_factory.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,39 @@
5353
)
5454
from deepset_mcp.tools.tokonomics import RichExplorer, explorable, explorable_and_referenceable, referenceable
5555

56+
EXPLORER = RichExplorer(store=STORE)
57+
58+
59+
def get_from_object_store(object_id: str, path: str = "") -> str:
60+
"""Use this tool to fetch an object from the object store.
61+
62+
You can fetch a specific object by using the object's id (e.g. `@obj_001`).
63+
You can also fetch any nested path by using the path-parameter
64+
(e.g. `{"object_id": "@obj_001", "path": "user_info.given_name"}`
65+
-> returns the content at obj.user_info.given_name).
66+
67+
:param object_id: The id of the object to fetch in the format `@obj_001`.
68+
:param path: The path of the object to fetch in the format of `access.to.attr` or `["access"]["to"]["attr"]`.
69+
"""
70+
return EXPLORER.explore(obj_id=object_id, path=path)
71+
72+
73+
def get_slice_from_object_store(
74+
object_id: str,
75+
start: int = 0,
76+
end: int | None = None,
77+
path: str = "",
78+
) -> str:
79+
"""Extract a slice from a string or list object that is stored in the object store.
80+
81+
:param object_id: Identifier of the object.
82+
:param start: Start index for slicing.
83+
:param end: End index for slicing (None for end of sequence).
84+
:param path: Navigation path to object to slice (optional).
85+
:return: String representation of the slice.
86+
"""
87+
return EXPLORER.slice(obj_id=object_id, start=start, end=end, path=path)
88+
5689

5790
# Special wrapper for search_component_definitions that needs the model
5891
async def search_component_definitions_wrapper(client: Any, query: str, top_k: int = 5) -> ComponentSearchResults | str:
@@ -220,6 +253,8 @@ def get_workspace_from_env() -> str:
220253
),
221254
"list_secrets": (list_secrets_tool, ToolConfig(needs_client=True, memory_type=MemoryType.EXPLORABLE)),
222255
"get_secret": (get_secret_tool, ToolConfig(needs_client=True, memory_type=MemoryType.EXPLORABLE)),
256+
"get_from_object_store": (get_from_object_store, ToolConfig(memory_type=MemoryType.NO_MEMORY)),
257+
"get_slice_from_object_store": (get_slice_from_object_store, ToolConfig(memory_type=MemoryType.NO_MEMORY)),
223258
}
224259

225260

@@ -335,8 +370,8 @@ def register_all_tools(mcp: FastMCP, workspace_mode: WorkspaceMode, workspace: s
335370
workspace_mode: How workspace should be handled
336371
workspace: Workspace to use for implicit mode (if None, reads from env)
337372
"""
338-
for _tool_name, (base_func, config) in TOOL_REGISTRY.items():
373+
for tool_name, (base_func, config) in TOOL_REGISTRY.items():
339374
# Create enhanced tool
340375
enhanced_tool = create_enhanced_tool(base_func, config, workspace_mode, workspace) # type: ignore[arg-type]
341376

342-
mcp.add_tool(enhanced_tool)
377+
mcp.add_tool(enhanced_tool, name=tool_name)

0 commit comments

Comments
 (0)