Skip to content

Commit c7f5b91

Browse files
Added doctests to config and schema modules (#401)
* Added doctests to config and schema modules Signed-off-by: Manav Gupta <[email protected]> * Add missing doctest Signed-off-by: Mihai Criveti <[email protected]> * Add missing doctest Signed-off-by: Mihai Criveti <[email protected]> --------- Signed-off-by: Manav Gupta <[email protected]> Signed-off-by: Mihai Criveti <[email protected]> Co-authored-by: Mihai Criveti <[email protected]>
1 parent b582363 commit c7f5b91

File tree

2 files changed

+67
-6
lines changed

2 files changed

+67
-6
lines changed

mcpgateway/config.py

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,23 @@
2727
- TOOL_TIMEOUT: Tool invocation timeout (default: 60)
2828
- PROMPT_CACHE_SIZE: Max cached prompts (default: 100)
2929
- HEALTH_CHECK_INTERVAL: Gateway health check interval (default: 60)
30+
31+
Examples:
32+
>>> from mcpgateway.config import Settings
33+
>>> s = Settings(basic_auth_user='admin', basic_auth_password='secret')
34+
>>> s.api_key
35+
'admin:secret'
36+
>>> s2 = Settings(transport_type='http')
37+
>>> s2.validate_transport() # no error
38+
>>> s3 = Settings(transport_type='invalid')
39+
>>> try:
40+
... s3.validate_transport()
41+
... except ValueError as e:
42+
... print('error')
43+
error
44+
>>> s4 = Settings(database_url='sqlite:///./test.db')
45+
>>> isinstance(s4.database_settings, dict)
46+
True
3047
"""
3148

3249
# Standard
@@ -46,7 +63,26 @@
4663

4764

4865
class Settings(BaseSettings):
49-
"""MCP Gateway configuration settings."""
66+
"""
67+
MCP Gateway configuration settings.
68+
69+
Examples:
70+
>>> from mcpgateway.config import Settings
71+
>>> s = Settings(basic_auth_user='admin', basic_auth_password='secret')
72+
>>> s.api_key
73+
'admin:secret'
74+
>>> s2 = Settings(transport_type='http')
75+
>>> s2.validate_transport() # no error
76+
>>> s3 = Settings(transport_type='invalid')
77+
>>> try:
78+
... s3.validate_transport()
79+
... except ValueError as e:
80+
... print('error')
81+
error
82+
>>> s4 = Settings(database_url='sqlite:///./test.db')
83+
>>> isinstance(s4.database_settings, dict)
84+
True
85+
"""
5086

5187
# Basic Settings
5288
app_name: str = "MCP_Gateway"
@@ -207,12 +243,14 @@ def _parse_federation_peers(cls, v):
207243

208244
@property
209245
def api_key(self) -> str:
210-
"""Generate API key from auth credentials.
246+
"""
247+
Generate API key from auth credentials.
211248
212249
Returns:
213250
str: API key string in the format "username:password".
214251
215252
Examples:
253+
>>> from mcpgateway.config import Settings
216254
>>> settings = Settings(basic_auth_user="admin", basic_auth_password="secret")
217255
>>> settings.api_key
218256
'admin:secret'
@@ -284,10 +322,17 @@ def supports_sse(self) -> bool:
284322

285323
@property
286324
def database_settings(self) -> dict:
287-
"""Get SQLAlchemy database settings.
325+
"""
326+
Get SQLAlchemy database settings.
288327
289328
Returns:
290329
dict: Dictionary containing SQLAlchemy database configuration options.
330+
331+
Examples:
332+
>>> from mcpgateway.config import Settings
333+
>>> s = Settings(database_url='sqlite:///./test.db')
334+
>>> isinstance(s.database_settings, dict)
335+
True
291336
"""
292337
return {
293338
"pool_size": self.db_pool_size,
@@ -316,10 +361,22 @@ def cors_settings(self) -> dict:
316361
)
317362

318363
def validate_transport(self) -> None:
319-
"""Validate transport configuration.
364+
"""
365+
Validate transport configuration.
320366
321367
Raises:
322368
ValueError: If the transport type is not one of the valid options.
369+
370+
Examples:
371+
>>> from mcpgateway.config import Settings
372+
>>> s = Settings(transport_type='http')
373+
>>> s.validate_transport() # no error
374+
>>> s2 = Settings(transport_type='invalid')
375+
>>> try:
376+
... s2.validate_transport()
377+
... except ValueError as e:
378+
... print('error')
379+
error
323380
"""
324381
valid_types = {"http", "ws", "sse", "all"}
325382
if self.transport_type not in valid_types:

mcpgateway/db.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@
1010
- Resources with subscription tracking
1111
- Prompts with argument templates
1212
- Federated gateways with capability tracking
13+
- Updated to record server associations independently using many-to-many relationships,
14+
- and to record tool execution metrics.
1315
14-
Updated to record server associations independently using many-to-many relationships,
15-
and to record tool execution metrics.
16+
Examples:
17+
>>> from mcpgateway.db import connect_args
18+
>>> isinstance(connect_args, dict)
19+
True
1620
"""
1721

1822
# Standard

0 commit comments

Comments
 (0)