nvidia-nat-mcp 1.3.0a20251006__py3-none-any.whl → 1.3.0a20251008__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,131 @@
1
+ # SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ from datetime import timedelta
17
+ from typing import Literal
18
+
19
+ from pydantic import BaseModel
20
+ from pydantic import Field
21
+ from pydantic import HttpUrl
22
+ from pydantic import model_validator
23
+
24
+ from nat.data_models.component_ref import AuthenticationRef
25
+ from nat.data_models.function import FunctionGroupBaseConfig
26
+
27
+
28
+ class MCPToolOverrideConfig(BaseModel):
29
+ """
30
+ Configuration for overriding tool properties when exposing from MCP server.
31
+ """
32
+ alias: str | None = Field(default=None, description="Override the tool name (function name in the workflow)")
33
+ description: str | None = Field(default=None, description="Override the tool description")
34
+
35
+
36
+ class MCPServerConfig(BaseModel):
37
+ """
38
+ Server connection details for MCP client.
39
+ Supports stdio, sse, and streamable-http transports.
40
+ streamable-http is the recommended default for HTTP-based connections.
41
+ """
42
+ transport: Literal["stdio", "sse", "streamable-http"] = Field(
43
+ ..., description="Transport type to connect to the MCP server (stdio, sse, or streamable-http)")
44
+ url: HttpUrl | None = Field(default=None,
45
+ description="URL of the MCP server (for sse or streamable-http transport)")
46
+ command: str | None = Field(default=None,
47
+ description="Command to run for stdio transport (e.g. 'python' or 'docker')")
48
+ args: list[str] | None = Field(default=None, description="Arguments for the stdio command")
49
+ env: dict[str, str] | None = Field(default=None, description="Environment variables for the stdio process")
50
+
51
+ # Authentication configuration
52
+ auth_provider: str | AuthenticationRef | None = Field(default=None,
53
+ description="Reference to authentication provider")
54
+
55
+ @model_validator(mode="after")
56
+ def validate_model(self):
57
+ """Validate that stdio and SSE/Streamable HTTP properties are mutually exclusive."""
58
+ if self.transport == "stdio":
59
+ if self.url is not None:
60
+ raise ValueError("url should not be set when using stdio transport")
61
+ if not self.command:
62
+ raise ValueError("command is required when using stdio transport")
63
+ # Auth is not supported for stdio transport
64
+ if self.auth_provider is not None:
65
+ raise ValueError("Authentication is not supported for stdio transport")
66
+ elif self.transport == "sse":
67
+ if self.command is not None or self.args is not None or self.env is not None:
68
+ raise ValueError("command, args, and env should not be set when using sse transport")
69
+ if not self.url:
70
+ raise ValueError("url is required when using sse transport")
71
+ # Auth is not supported for SSE transport
72
+ if self.auth_provider is not None:
73
+ raise ValueError("Authentication is not supported for SSE transport.")
74
+ elif self.transport == "streamable-http":
75
+ if self.command is not None or self.args is not None or self.env is not None:
76
+ raise ValueError("command, args, and env should not be set when using streamable-http transport")
77
+ if not self.url:
78
+ raise ValueError("url is required when using streamable-http transport")
79
+
80
+ return self
81
+
82
+
83
+ class MCPClientConfig(FunctionGroupBaseConfig, name="mcp_client"):
84
+ """
85
+ Configuration for connecting to an MCP server as a client and exposing selected tools.
86
+ """
87
+ server: MCPServerConfig = Field(..., description="Server connection details (transport, url/command, etc.)")
88
+ tool_call_timeout: timedelta = Field(
89
+ default=timedelta(seconds=60),
90
+ description="Timeout (in seconds) for the MCP tool call. Defaults to 60 seconds.")
91
+ auth_flow_timeout: timedelta = Field(
92
+ default=timedelta(seconds=300),
93
+ description="Timeout (in seconds) for the MCP auth flow. When the tool call requires interactive \
94
+ authentication, this timeout is used. Defaults to 300 seconds.")
95
+ reconnect_enabled: bool = Field(
96
+ default=True,
97
+ description="Whether to enable reconnecting to the MCP server if the connection is lost. \
98
+ Defaults to True.")
99
+ reconnect_max_attempts: int = Field(default=2,
100
+ ge=0,
101
+ description="Maximum number of reconnect attempts. Defaults to 2.")
102
+ reconnect_initial_backoff: float = Field(
103
+ default=0.5, ge=0.0, description="Initial backoff time for reconnect attempts. Defaults to 0.5 seconds.")
104
+ reconnect_max_backoff: float = Field(
105
+ default=50.0, ge=0.0, description="Maximum backoff time for reconnect attempts. Defaults to 50 seconds.")
106
+ tool_overrides: dict[str, MCPToolOverrideConfig] | None = Field(
107
+ default=None,
108
+ description="""Optional tool name overrides and description changes.
109
+ Example:
110
+ tool_overrides:
111
+ calculator_add:
112
+ alias: "add_numbers"
113
+ description: "Add two numbers together"
114
+ calculator_multiply:
115
+ description: "Multiply two numbers" # alias defaults to original name
116
+ """)
117
+ session_aware_tools: bool = Field(default=True,
118
+ description="Session-aware tools are created if True. Defaults to True.")
119
+ max_sessions: int = Field(default=100,
120
+ ge=1,
121
+ description="Maximum number of concurrent session clients. Defaults to 100.")
122
+ session_idle_timeout: timedelta = Field(
123
+ default=timedelta(hours=1),
124
+ description="Time after which inactive sessions are cleaned up. Defaults to 1 hour.")
125
+
126
+ @model_validator(mode="after")
127
+ def _validate_reconnect_backoff(self) -> "MCPClientConfig":
128
+ """Validate reconnect backoff values."""
129
+ if self.reconnect_max_backoff < self.reconnect_initial_backoff:
130
+ raise ValueError("reconnect_max_backoff must be greater than or equal to reconnect_initial_backoff")
131
+ return self