Skip to content

MCP Configuration

MCP Server

deepset_mcp.mcp.ToolConfig dataclass

Configuration for tool registration.

It allows users to define what arguments should be passed to the tool at registration time. These arguments will not be provided by the LLM as the tool will receive them programmatically through partial application.

The configuration also determines if a tool should store outputs in the object store.

needs_client class-attribute instance-attribute

needs_client: bool = False

If the tool should receive a configured instance of the 'AsyncDeepsetClient' at tool-registration time.

needs_workspace class-attribute instance-attribute

needs_workspace: bool = False

If the tool should receive a static deepset workspace at tool-registration time.

memory_type class-attribute instance-attribute

memory_type: MemoryType = NO_MEMORY

The type of memory this tool should use.

custom_args class-attribute instance-attribute

custom_args: dict[str, Any] = field(default_factory=dict)

Any other arguments that should be passed to the tool at registration time instead of being passed by the LLM.

deepset_mcp.mcp.configure_mcp_server

configure_mcp_server(
    mcp_server_instance: FastMCP,
    tools_to_register: set[str] | None = None,
    deepset_api_key: str | None = None,
    deepset_api_url: str | None = None,
    deepset_workspace: str | None = None,
    deepset_docs_shareable_prototype_url: str | None = None,
    get_api_key_from_authorization_header: bool = False,
    object_store_backend: str = "memory",
    object_store_redis_url: str | None = None,
    object_store_ttl: int = 600,
) -> None

Configure the MCP server with the specified tools and settings.

Parameters:

Name Type Description Default
mcp_server_instance FastMCP

The FastMCP server instance to configure

required
tools_to_register set[str] | None

Set of tool names to register with the server. Will register all tools if set to None.

None
deepset_api_key str | None

Optional Deepset API key for authentication

None
deepset_api_url str | None

Optional Deepset API base URL

None
deepset_workspace str | None

Pass a deepset workspace name if you only want to run the tools on a specific workspace.

None
deepset_docs_shareable_prototype_url str | None

Shareable prototype URL that allows access to a docs search pipeline. Will fall back to the default shareable prototype URL if set to None.

None
get_api_key_from_authorization_header bool

Whether to extract API key from authorization header

False
object_store_backend str

Object store backend type ('memory' or 'redis')

'memory'
object_store_redis_url str | None

Redis connection URL (required if backend='redis')

None
object_store_ttl int

TTL in seconds for stored objects

600

Raises:

Type Description
ValueError

If required parameters are missing or invalid

deepset_mcp.mcp.initialize_or_get_initialized_store cached

initialize_or_get_initialized_store(
    backend: str = "memory",
    redis_url: str | None = None,
    ttl: int = 600,
) -> ObjectStore

Initializes the object store or gets an existing object store instance if it was initialized before.

Parameters:

Name Type Description Default
backend str

Backend type ('memory' or 'redis')

'memory'
redis_url str | None

Redis connection URL (required if backend='redis')

None
ttl int

Time-to-live in seconds for stored objects

600

Raises:

Type Description
ValueError

If Redis backend selected but no URL provided

Exception

If Redis connection fails

deepset_mcp.mcp.build_tool

build_tool(
    base_func: Callable[..., Any],
    config: ToolConfig,
    api_key: str | None = None,
    workspace: str | None = None,
    use_request_context: bool = True,
    base_url: str | None = None,
    object_store: ObjectStore | None = None,
) -> Callable[..., Awaitable[Any]]

Universal tool creator that handles client injection, workspace, and decorators.

This function takes a base tool function and enhances it based on the tool's configuration.

Parameters:

Name Type Description Default
base_func Callable[..., Any]

The base tool function.

required
config ToolConfig

Tool configuration specifying dependencies and custom arguments.

required
api_key str | None

The deepset API key to use.

None
workspace str | None

The workspace to use when using a static workspace.

None
use_request_context bool

Whether to collect the API key from the request context.

True
base_url str | None

Base URL for the deepset API.

None
object_store ObjectStore | None

The ObjectStore instance to use for memory decorators.

None

Returns:

Type Description
Callable[..., Awaitable[Any]]

An enhanced, awaitable tool function with an updated signature and docstring.

Object Store

deepset_mcp.tokonomics.RichExplorer

Presents Python objects in various Rich formats with navigation support.

Parameters:

Name Type Description Default
store ObjectStore

Object store used for lookups.

required
max_items int

Maximum number of items to show for lists and nested collections (default: 20). Note: All keys are shown for top-level dicts.

25
max_string_length int

Maximum string length before truncation (default: 300).

300
max_depth int

Maximum depth for object representation (default: 3).

4
max_search_matches int

Maximum number of search matches to display (default: 10).

10
search_context_length int

Number of characters to show around search matches (default: 150).

150

__init__

__init__(
    store: ObjectStore,
    max_items: int = 25,
    max_string_length: int = 300,
    max_depth: int = 4,
    max_search_matches: int = 10,
    search_context_length: int = 150,
) -> None

Initialize the RichExplorer with storage and configuration options.

parse_reference

parse_reference(ref_str: str) -> tuple[str, str]

Parse @obj_id.path into (obj_id, path).

Parameters:

Name Type Description Default
ref_str str

Reference string like @obj_id.path or obj_id

required

Returns:

Type Description
tuple[str, str]

Tuple of (obj_id, path)

explore

explore(obj_id: str, path: str = '') -> str

Return a string preview of the requested object.

Parameters:

Name Type Description Default
obj_id str

Identifier obtained from the store.

required
path str

Navigation path using . or [...] notation (e.g. @obj_id.path.to.attribute).

''

Returns:

Type Description
str

String representation of the object.

search

search(
    obj_id: str,
    pattern: str,
    path: str = "",
    case_sensitive: bool = False,
) -> str

Search for a pattern within a string object.

Parameters:

Name Type Description Default
obj_id str

Identifier obtained from the store.

required
pattern str

Regular expression pattern to search for.

required
path str

Navigation path to search within (optional).

''
case_sensitive bool

Whether search should be case sensitive.

False

Returns:

Type Description
str

Search results as formatted string.

slice

slice(
    obj_id: str,
    start: int = 0,
    end: int | None = None,
    path: str = "",
) -> str

Extract a slice from a string or list object.

Parameters:

Name Type Description Default
obj_id str

Identifier of the object.

required
start int

Start index for slicing.

0
end int | None

End index for slicing (None for end of sequence).

None
path str

Navigation path to object to slice (optional).

''

Returns:

Type Description
str

String representation of the slice.

deepset_mcp.tokonomics.InMemoryBackend

In-memory backend with counter-based IDs.

__init__

__init__() -> None

Initialize an instance of InMemoryBackend.

generate_id

generate_id() -> str

Generate sequential ID.

set

set(
    key: str, value: bytes, ttl_seconds: int | None
) -> None

Set a value at key.

get

get(key: str) -> bytes | None

Get a value at key.

delete

delete(key: str) -> bool

Delete a value at key.

deepset_mcp.tokonomics.ObjectStore

JSON-based object store with pluggable backends.

__init__

__init__(
    backend: ObjectStoreBackend, ttl: int = 600
) -> None

Initialize ObjectStore with backend and TTL.

Parameters

backend : Backend implementation for storage ttl : Time-to-live in seconds for stored objects. The TTL is managed by the backend.

put

put(obj: Any) -> str

Store any object as JSON using backend-generated ID.

get

get(obj_id: str) -> Any | None

Get object as JSON-decoded data.

delete

delete(obj_id: str) -> bool

Delete object.

deepset_mcp.tokonomics.ObjectStoreBackend

Bases: Protocol

Backend protocol with ID generation.

generate_id

generate_id() -> str

Generate a unique ID for this backend.

set

set(
    key: str, value: bytes, ttl_seconds: int | None
) -> None

Store bytes value with optional TTL.

get

get(key: str) -> bytes | None

Retrieve bytes value or None if not found/expired.

delete

delete(key: str) -> bool

Delete and return True if existed.

deepset_mcp.tokonomics.RedisBackend

Redis backend with UUID-based IDs.

__init__

__init__(redis_url: str) -> None

Initialize the redis backend.

generate_id

generate_id() -> str

Generate UUID.

set

set(
    key: str, value: bytes, ttl_seconds: int | None
) -> None

Set a value at key.

get

get(key: str) -> bytes | None

Get a value at key.

delete

delete(key: str) -> bool

Delete a value at key.

deepset_mcp.tokonomics.explorable

explorable(
    *, object_store: ObjectStore, explorer: RichExplorer
) -> Callable[[F], F]

Decorator factory that stores function results for later reference.

Parameters:

Name Type Description Default
object_store ObjectStore

The object store instance to use for storage.

required
explorer RichExplorer

The RichExplorer instance to use for previews.

required

Returns:

Type Description
Callable[[F], F]

Decorator function. Examples -------- >>> store = ObjectStore() >>> explorer = RichExplorer(store) >>> >>> @explorable(object_store=store, explorer=explorer) ... def process_data(data: dict) -> dict: ... return {"processed": data} ... >>> result = process_data({"input": "value"}) >>> # result contains a preview and object ID like "@obj_123"

deepset_mcp.tokonomics.explorable_and_referenceable

explorable_and_referenceable(
    *, object_store: ObjectStore, explorer: RichExplorer
) -> Callable[[F], F]

Decorator factory that combines @explorable and @referenceable functionality.

The decorated function can accept reference parameters AND stores its result in the object store for later reference.

Parameters:

Name Type Description Default
object_store ObjectStore

The object store instance to use.

required
explorer RichExplorer

The RichExplorer instance to use.

required

Returns:

Type Description
Callable[[F], F]

Decorator function. Examples -------- >>> store = ObjectStore() >>> explorer = RichExplorer(store) >>> >>> @explorable_and_referenceable(object_store=store, explorer=explorer) ... def merge_data(data1: dict, data2: dict) -> dict: ... return {data1, data2} ... >>> # Accepts references and returns preview with object ID >>> result = merge_data("@obj_123", {"new": "data"}) >>> # result contains a preview and can be referenced as "@obj_002"

deepset_mcp.tokonomics.referenceable

referenceable(
    *, object_store: ObjectStore, explorer: RichExplorer
) -> Callable[[F], F]

Decorator factory that enables parameters to accept object references.

Parameters can accept reference strings like '@obj_id' or '@obj_id.path.to.value' which are automatically resolved before calling the function.

Parameters:

Name Type Description Default
object_store ObjectStore

The object store instance to use for lookups.

required
explorer RichExplorer

The RichExplorer instance to use for path validation.

required

Returns:

Type Description
Callable[[F], F]

Decorator function. Examples -------- >>> store = ObjectStore() >>> explorer = RichExplorer(store) >>> >>> @referenceable(object_store=store, explorer=explorer) ... def process_data(data: dict, threshold: int) -> str: ... return f"Processed {len(data)} items with threshold {threshold}" ... >>> # Call with actual values >>> process_data({"a": 1, "b": 2}, 10) >>> >>> # Call with references >>> process_data("@obj_123", "@obj_456.config.threshold")