Skip to content

Commit 7431164

Browse files
authored
feat: make workspace configurable (#106)
1 parent 95690d4 commit 7431164

8 files changed

Lines changed: 545 additions & 374 deletions

File tree

src/deepset_mcp/main.py

Lines changed: 23 additions & 374 deletions
Large diffs are not rendered by default.

src/deepset_mcp/mcp/__init__.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from .custom_components import get_latest_custom_component_installation_logs, list_custom_component_installations
2+
from .indexes import create_index, deploy_index, get_index, list_indexes, update_index
3+
from .pipeline_templates import get_pipeline_template, list_pipeline_templates, search_pipeline_templates
4+
from .pipelines import (
5+
create_pipeline,
6+
deploy_pipeline,
7+
get_pipeline,
8+
get_pipeline_logs,
9+
list_pipelines,
10+
search_pipeline,
11+
update_pipeline,
12+
validate_pipeline,
13+
)
14+
15+
__all__ = [
16+
"list_pipelines",
17+
"get_pipeline",
18+
"create_pipeline",
19+
"update_pipeline",
20+
"validate_pipeline",
21+
"deploy_pipeline",
22+
"get_pipeline_logs",
23+
"search_pipeline",
24+
"list_indexes",
25+
"get_index",
26+
"update_index",
27+
"create_index",
28+
"deploy_index",
29+
"get_latest_custom_component_installation_logs",
30+
"list_custom_component_installations",
31+
"search_pipeline_templates",
32+
"list_pipeline_templates",
33+
"get_pipeline_template",
34+
]
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from deepset_mcp.api.client import AsyncDeepsetClient
2+
from deepset_mcp.tools.custom_components import (
3+
get_latest_custom_component_installation_logs as get_latest_custom_component_installation_logs_tool,
4+
list_custom_component_installations as list_custom_component_installations_tool,
5+
)
6+
7+
8+
async def list_custom_component_installations(workspace: str) -> str:
9+
"""Retrieves a list of recent custom component installations.
10+
11+
Use this to see the installation history of custom components, including status,
12+
version information, and who installed them. This also includes installation logs.
13+
14+
:param workspace: The deepset workspace to operate on.
15+
"""
16+
async with AsyncDeepsetClient() as client:
17+
response = await list_custom_component_installations_tool(client, workspace)
18+
19+
return response
20+
21+
22+
async def get_latest_custom_component_installation_logs(workspace: str) -> str:
23+
"""Retrieves the logs from the latest custom component installation.
24+
25+
Use this to debug custom component installation issues or to understand
26+
what happened during the most recent installation.
27+
28+
:param workspace: The deepset workspace to operate on.
29+
"""
30+
async with AsyncDeepsetClient() as client:
31+
response = await get_latest_custom_component_installation_logs_tool(client, workspace)
32+
33+
return response

src/deepset_mcp/mcp/indexes.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
from deepset_mcp.api.client import AsyncDeepsetClient
2+
from deepset_mcp.tools.indexes import (
3+
create_index as create_index_tool,
4+
deploy_index as deploy_index_tool,
5+
get_index as get_index_tool,
6+
list_indexes as list_indexes_tool,
7+
update_index as update_index_tool,
8+
)
9+
10+
11+
async def list_indexes(workspace: str) -> str:
12+
"""Retrieves a list of all indexes available in the deepset workspace.
13+
14+
Use this to get an overview of existing indexes and their configurations.
15+
The response includes basic information for each index.
16+
17+
:param workspace: The deepset workspace to operate on.
18+
"""
19+
async with AsyncDeepsetClient() as client:
20+
response = await list_indexes_tool(client=client, workspace=workspace)
21+
return response
22+
23+
24+
async def get_index(workspace: str, index_name: str) -> str:
25+
"""Fetches detailed configuration information for a specific index.
26+
27+
Use this to get the full configuration and details of a single index.
28+
29+
:param workspace: The deepset workspace to operate on.
30+
:param index_name: The name of the index to fetch.
31+
"""
32+
async with AsyncDeepsetClient() as client:
33+
response = await get_index_tool(client=client, workspace=workspace, index_name=index_name)
34+
return response
35+
36+
37+
async def create_index(workspace: str, index_name: str, yaml_configuration: str, description: str | None = None) -> str:
38+
"""Creates a new index in the deepset workspace.
39+
40+
Use this to create a new index with the given configuration.
41+
Make sure the YAML configuration is valid before creating the index.
42+
43+
:param workspace: The deepset workspace to operate on.
44+
:param index_name: The name for the new index.
45+
:param yaml_configuration: YAML configuration for the index.
46+
:param description: Optional description for the index.
47+
"""
48+
async with AsyncDeepsetClient() as client:
49+
response = await create_index_tool(
50+
client=client,
51+
workspace=workspace,
52+
index_name=index_name,
53+
yaml_configuration=yaml_configuration,
54+
description=description,
55+
)
56+
return response
57+
58+
59+
async def update_index(
60+
workspace: str, index_name: str, updated_index_name: str | None = None, yaml_configuration: str | None = None
61+
) -> str:
62+
"""Updates an existing index in the deepset workspace.
63+
64+
Use this to update the name or configuration of an existing index.
65+
You must provide at least one of updated_index_name or yaml_configuration.
66+
67+
:param workspace: The deepset workspace to operate on.
68+
:param index_name: The name of the index to update.
69+
:param updated_index_name: Optional new name for the index.
70+
:param yaml_configuration: Optional new YAML configuration.
71+
"""
72+
async with AsyncDeepsetClient() as client:
73+
response = await update_index_tool(
74+
client=client,
75+
workspace=workspace,
76+
index_name=index_name,
77+
updated_index_name=updated_index_name,
78+
yaml_configuration=yaml_configuration,
79+
)
80+
return response
81+
82+
83+
async def deploy_index(workspace: str, index_name: str) -> str:
84+
"""Deploys an index to production in the deepset workspace.
85+
86+
Use this to deploy an index that has been created and configured.
87+
The deployment process will validate the index configuration and deploy it if valid.
88+
If deployment fails due to validation errors, you will receive detailed error information.
89+
90+
:param workspace: The deepset workspace to operate on.
91+
:param index_name: Name of the index to deploy.
92+
"""
93+
async with AsyncDeepsetClient() as client:
94+
response = await deploy_index_tool(client=client, workspace=workspace, index_name=index_name)
95+
return response
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from functools import lru_cache
2+
3+
from model2vec import StaticModel
4+
5+
6+
@lru_cache(maxsize=1)
7+
def get_initialized_model() -> StaticModel:
8+
"""Gets the initialized embedding model.
9+
10+
The model is cached to avoid reloading.
11+
"""
12+
return StaticModel.from_pretrained("minishlab/potion-base-2M")
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from deepset_mcp.api.client import AsyncDeepsetClient
2+
from deepset_mcp.mcp.initialize_embedding_model import get_initialized_model
3+
from deepset_mcp.tools.pipeline_template import (
4+
get_pipeline_template as get_pipeline_template_tool,
5+
list_pipeline_templates as list_pipeline_templates_tool,
6+
search_pipeline_templates as search_pipeline_templates_tool,
7+
)
8+
9+
10+
async def list_pipeline_templates(workspace: str) -> str:
11+
"""Retrieves a list of all pipeline templates available within the currently configured deepset workspace.
12+
13+
Use this when you need to know the available pipeline templates and their capabilities.
14+
15+
:param workspace: The name of the workspace where the pipeline templates are located.
16+
"""
17+
async with AsyncDeepsetClient() as client:
18+
response = await list_pipeline_templates_tool(client, workspace)
19+
20+
return response
21+
22+
23+
async def get_pipeline_template(workspace: str, template_name: str) -> str:
24+
"""Fetches detailed configuration information for a specific pipeline template.
25+
26+
This includes its YAML configuration, metadata, and recommended use cases.
27+
Use this when you need to inspect a specific template's structure or settings.
28+
29+
:param workspace: The deepset workspace to operate on.
30+
:param template_name: Name of the pipeline template to retrieve.
31+
"""
32+
async with AsyncDeepsetClient() as client:
33+
response = await get_pipeline_template_tool(client, workspace, template_name)
34+
35+
return response
36+
37+
38+
async def search_pipeline_templates(workspace: str, query: str) -> str:
39+
"""Use this to search for pipeline templates in deepset.
40+
41+
You can use full natural language queries to find templates.
42+
You can also use simple keywords.
43+
Use this if you want to find pipeline templates for specific use cases,
44+
but you are not sure what the exact name of the template is.
45+
46+
:param workspace: The deepset workspace to operate on.
47+
:param query: Search query for templates.
48+
"""
49+
async with AsyncDeepsetClient() as client:
50+
response = await search_pipeline_templates_tool(
51+
client=client, query=query, model=get_initialized_model(), workspace=workspace
52+
)
53+
54+
return response

src/deepset_mcp/mcp/pipelines.py

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
from deepset_mcp.api.client import AsyncDeepsetClient
2+
from deepset_mcp.api.pipeline.log_level import LogLevel
3+
from deepset_mcp.tools.pipeline import (
4+
create_pipeline as create_pipeline_tool,
5+
deploy_pipeline as deploy_pipeline_tool,
6+
get_pipeline as get_pipeline_tool,
7+
get_pipeline_logs as get_pipeline_logs_tool,
8+
list_pipelines as list_pipelines_tool,
9+
search_pipeline as search_pipeline_tool,
10+
update_pipeline as update_pipeline_tool,
11+
validate_pipeline as validate_pipeline_tool,
12+
)
13+
14+
15+
async def list_pipelines(workspace: str) -> str:
16+
"""Retrieves a list of all pipeline available within the currently configured deepset workspace.
17+
18+
Use this when you need to know the names or IDs of existing pipeline.
19+
This does not return the pipeline configuration.
20+
"""
21+
async with AsyncDeepsetClient() as client:
22+
response = await list_pipelines_tool(client, workspace)
23+
24+
return response
25+
26+
27+
async def get_pipeline(workspace: str, pipeline_name: str) -> str:
28+
"""Fetches detailed configuration information for a specific pipeline, identified by its unique `pipeline_name`.
29+
30+
This includes its components, connections, and metadata.
31+
Use this when you need to inspect the structure or settings of a known pipeline.
32+
33+
:param workspace: The deepset workspace to operate on.
34+
:param pipeline_name: Name of the pipeline to retrieve.
35+
"""
36+
async with AsyncDeepsetClient() as client:
37+
response = await get_pipeline_tool(client, workspace, pipeline_name)
38+
39+
return response
40+
41+
42+
async def create_pipeline(workspace: str, pipeline_name: str, yaml_configuration: str) -> str:
43+
"""Creates a new pipeline in deepset.
44+
45+
:param workspace: The deepset workspace to operate on.
46+
:param pipeline_name: Name of the pipeline to create
47+
:param yaml_configuration: YAML configuration for the pipeline
48+
"""
49+
async with AsyncDeepsetClient() as client:
50+
response = await create_pipeline_tool(client, workspace, pipeline_name, yaml_configuration)
51+
52+
return response
53+
54+
55+
async def update_pipeline(
56+
workspace: str, pipeline_name: str, original_configuration_snippet: str, replacement_configuration_snippet: str
57+
) -> str:
58+
"""Updates an existing pipeline in deepset.
59+
60+
The update is performed by replacing the original configuration snippet with the new one.
61+
Make sure that your original snippet only has a single exact match in the pipeline configuration.
62+
Respect whitespace and formatting.
63+
64+
:param workspace: The deepset workspace to operate on.
65+
:param pipeline_name: Name of the pipeline to update
66+
:param original_configuration_snippet: The configuration snippet to replace
67+
:param replacement_configuration_snippet: The new configuration snippet
68+
"""
69+
async with AsyncDeepsetClient() as client:
70+
response = await update_pipeline_tool(
71+
client=client,
72+
workspace=workspace,
73+
pipeline_name=pipeline_name,
74+
original_config_snippet=original_configuration_snippet,
75+
replacement_config_snippet=replacement_configuration_snippet,
76+
)
77+
78+
return response
79+
80+
81+
async def validate_pipeline(workspace: str, yaml_configuration: str) -> str:
82+
"""
83+
Validates the structure and syntax of a provided pipeline YAML configuration against the deepset API specifications.
84+
85+
Provide the YAML configuration as a string.
86+
Returns a validation result, indicating success or detailing any errors or warnings found.
87+
Use this *before* attempting to create or update a pipeline with new YAML.
88+
89+
:param workspace: The deepset workspace to operate on.
90+
:param yaml_configuration: YAML configuration to validate.
91+
"""
92+
async with AsyncDeepsetClient() as client:
93+
response = await validate_pipeline_tool(client, workspace, yaml_configuration)
94+
95+
return response
96+
97+
98+
async def get_pipeline_logs(workspace: str, pipeline_name: str, limit: int = 30, level: str | None = None) -> str:
99+
"""Fetches logs for a specific pipeline in the deepset workspace.
100+
101+
Use this to debug pipeline issues, monitor pipeline execution, or understand what happened during pipeline runs.
102+
The logs provide detailed information about pipeline operations, errors, and warnings.
103+
104+
:param workspace: The deepset workspace to operate on.
105+
:param pipeline_name: Name of the pipeline to fetch logs for.
106+
:param limit: Maximum number of log entries to return (default: 30, max: 100).
107+
:param level: Filter logs by level. Valid values: 'info', 'warning', 'error'. If not specified, returns all levels.
108+
"""
109+
# Convert string level to LogLevel enum if provided
110+
log_level: LogLevel | None = None
111+
if level is not None:
112+
try:
113+
log_level = LogLevel(level)
114+
except ValueError:
115+
return f"Invalid log level '{level}'. Valid values are: 'info', 'warning', 'error'."
116+
117+
async with AsyncDeepsetClient() as client:
118+
response = await get_pipeline_logs_tool(
119+
client=client,
120+
workspace=workspace,
121+
pipeline_name=pipeline_name,
122+
limit=limit,
123+
level=log_level,
124+
)
125+
return response
126+
127+
128+
async def deploy_pipeline(workspace: str, pipeline_name: str) -> str:
129+
"""Deploys a pipeline to production in the deepset workspace.
130+
131+
Use this to deploy a pipeline that has been created and validated.
132+
The deployment process will validate the pipeline configuration and deploy it if valid.
133+
If deployment fails due to validation errors, you will receive detailed error information.
134+
135+
:param workspace: The deepset workspace to operate on.
136+
:param pipeline_name: Name of the pipeline to deploy.
137+
"""
138+
async with AsyncDeepsetClient() as client:
139+
response = await deploy_pipeline_tool(
140+
client=client, workspace=workspace, pipeline_name=pipeline_name, wait_for_deployment=True
141+
)
142+
return response
143+
144+
145+
async def search_pipeline(workspace: str, pipeline_name: str, query: str) -> str:
146+
"""Search using a deployed pipeline in the deepset workspace.
147+
148+
This tool allows you to execute a search query using a specific pipeline.
149+
The pipeline must already be deployed (status = DEPLOYED) for the search to work.
150+
If the pipeline is not deployed, you will receive an error message instructing you to deploy it first.
151+
152+
Use this tool when you want to:
153+
- Test a deployed pipeline with a specific query
154+
- Get search results from a knowledge base using a specific pipeline
155+
- Retrieve answers or documents based on a search query
156+
157+
:param workspace: The deepset workspace to operate on.
158+
:param pipeline_name: Name of the deployed pipeline to use for search.
159+
:param query: The search query to execute.
160+
"""
161+
async with AsyncDeepsetClient() as client:
162+
response = await search_pipeline_tool(
163+
client=client, workspace=workspace, pipeline_name=pipeline_name, query=query
164+
)
165+
return response

0 commit comments

Comments
 (0)