ims-mcp 1.0.9__tar.gz → 1.0.10__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ims-mcp
3
- Version: 1.0.9
3
+ Version: 1.0.10
4
4
  Summary: Model Context Protocol server for IMS (Instruction Management Systems)
5
5
  Author: Igor Solomatov
6
6
  License-Expression: MIT
@@ -84,6 +84,7 @@ The server automatically reads configuration from environment variables:
84
84
  | `R2R_API_KEY` | API key for authentication | None |
85
85
  | `R2R_EMAIL` | Email for authentication (requires R2R_PASSWORD) | None |
86
86
  | `R2R_PASSWORD` | Password for authentication (requires R2R_EMAIL) | None |
87
+ | `IMS_DEBUG` | Enable debug logging to stderr (1/true/yes/on) | None (disabled) |
87
88
 
88
89
  **Authentication Priority:**
89
90
  1. If `R2R_API_KEY` is set, it will be used
@@ -57,6 +57,7 @@ The server automatically reads configuration from environment variables:
57
57
  | `R2R_API_KEY` | API key for authentication | None |
58
58
  | `R2R_EMAIL` | Email for authentication (requires R2R_PASSWORD) | None |
59
59
  | `R2R_PASSWORD` | Password for authentication (requires R2R_EMAIL) | None |
60
+ | `IMS_DEBUG` | Enable debug logging to stderr (1/true/yes/on) | None (disabled) |
60
61
 
61
62
  **Authentication Priority:**
62
63
  1. If `R2R_API_KEY` is set, it will be used
@@ -11,7 +11,7 @@ Environment Variables:
11
11
  Note: Environment variables use R2R_ prefix for compatibility with underlying R2R SDK.
12
12
  """
13
13
 
14
- __version__ = "1.0.9"
14
+ __version__ = "1.0.10"
15
15
  __author__ = "Igor Solomatov"
16
16
 
17
17
  from ims_mcp.server import mcp
@@ -15,15 +15,60 @@ configuration is needed when running via uvx or other launchers.
15
15
  """
16
16
 
17
17
  import functools
18
+ import logging
18
19
  import os
20
+ import signal
19
21
  import sys
20
22
  import uuid
21
23
  from r2r import R2RClient, R2RException
22
24
 
25
+ # Debug mode controlled by environment variable
26
+ DEBUG_MODE = os.getenv('IMS_DEBUG', '').lower() in ('1', 'true', 'yes', 'on')
27
+
28
+ # Configure logging based on debug mode
29
+ if DEBUG_MODE:
30
+ logging.basicConfig(level=logging.DEBUG)
31
+ else:
32
+ # Suppress all logging output from R2R and other libraries
33
+ logging.basicConfig(level=logging.CRITICAL)
34
+ # Specifically suppress httpx and httpcore which R2R uses
35
+ logging.getLogger('httpx').setLevel(logging.CRITICAL)
36
+ logging.getLogger('httpcore').setLevel(logging.CRITICAL)
37
+ logging.getLogger('r2r').setLevel(logging.CRITICAL)
38
+
23
39
  # Global client instance with authentication
24
40
  _authenticated_client = None
25
41
 
26
42
 
43
+ def debug_print(msg: str):
44
+ """Print debug message to stderr if debug mode enabled."""
45
+ if DEBUG_MODE:
46
+ print(msg, file=sys.stderr)
47
+ sys.stderr.flush()
48
+
49
+
50
+ def cleanup_and_exit(signum=None, frame=None):
51
+ """Gracefully shutdown the server on termination signals."""
52
+ global _authenticated_client
53
+
54
+ debug_print(f"[ims-mcp] Shutting down gracefully...")
55
+
56
+ # Cleanup authenticated client if exists
57
+ if _authenticated_client is not None:
58
+ try:
59
+ # R2R client cleanup if needed
60
+ _authenticated_client = None
61
+ except Exception:
62
+ pass # Ignore errors during shutdown
63
+
64
+ debug_print(f"[ims-mcp] Shutdown complete")
65
+ sys.exit(0)
66
+
67
+
68
+ # Register signal handlers for graceful shutdown
69
+ signal.signal(signal.SIGTERM, cleanup_and_exit)
70
+ signal.signal(signal.SIGINT, cleanup_and_exit)
71
+
27
72
  def get_authenticated_client() -> R2RClient:
28
73
  """Get or create an authenticated R2R client.
29
74
 
@@ -48,13 +93,12 @@ def get_authenticated_client() -> R2RClient:
48
93
  email = os.getenv("R2R_EMAIL")
49
94
  password = os.getenv("R2R_PASSWORD")
50
95
 
51
- print(f"[ims-mcp v{__version__}]", file=sys.stderr)
52
- print(f" server={base_url}", file=sys.stderr)
53
- print(f" collection={collection}", file=sys.stderr)
54
- print(f" api_key={api_key[:3] + '...' if api_key else 'none'}", file=sys.stderr)
55
- print(f" email={email if email else 'none'}", file=sys.stderr)
56
- print(f" password={password[:3] + '...' if password else 'none'}", file=sys.stderr)
57
- sys.stderr.flush()
96
+ debug_print(f"[ims-mcp v{__version__}]")
97
+ debug_print(f" server={base_url}")
98
+ debug_print(f" collection={collection}")
99
+ debug_print(f" api_key={api_key[:3] + '...' if api_key else 'none'}")
100
+ debug_print(f" email={email if email else 'none'}")
101
+ debug_print(f" password={password[:3] + '...' if password else 'none'}")
58
102
 
59
103
  # Create new client
60
104
  client = R2RClient()
@@ -67,9 +111,9 @@ def get_authenticated_client() -> R2RClient:
67
111
  try:
68
112
  # Login - R2RClient automatically handles token internally
69
113
  client.users.login(email=email, password=password)
70
- print(f"[ims-mcp] Login successful", file=sys.stderr)
114
+ debug_print(f"[ims-mcp] Login successful")
71
115
  except Exception as e:
72
- print(f"[ims-mcp] Login failed: {e}", file=sys.stderr)
116
+ debug_print(f"[ims-mcp] Login failed: {e}")
73
117
  # If login fails, continue without authentication (might work for local servers)
74
118
  pass
75
119
 
@@ -97,7 +141,7 @@ def retry_on_auth_error(func):
97
141
  except R2RException as e:
98
142
  # Check if this is an authentication error (token expired)
99
143
  if hasattr(e, 'status_code') and e.status_code in [401, 403]:
100
- print(f"[ims-mcp] Token expired, re-authenticating...", file=sys.stderr)
144
+ debug_print(f"[ims-mcp] Token expired, re-authenticating...")
101
145
  invalidate_client()
102
146
  # Retry once with fresh authentication
103
147
  return await func(*args, **kwargs)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ims-mcp
3
- Version: 1.0.9
3
+ Version: 1.0.10
4
4
  Summary: Model Context Protocol server for IMS (Instruction Management Systems)
5
5
  Author: Igor Solomatov
6
6
  License-Expression: MIT
@@ -84,6 +84,7 @@ The server automatically reads configuration from environment variables:
84
84
  | `R2R_API_KEY` | API key for authentication | None |
85
85
  | `R2R_EMAIL` | Email for authentication (requires R2R_PASSWORD) | None |
86
86
  | `R2R_PASSWORD` | Password for authentication (requires R2R_EMAIL) | None |
87
+ | `IMS_DEBUG` | Enable debug logging to stderr (1/true/yes/on) | None (disabled) |
87
88
 
88
89
  **Authentication Priority:**
89
90
  1. If `R2R_API_KEY` is set, it will be used
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "ims-mcp"
7
- version = "1.0.9"
7
+ version = "1.0.10"
8
8
  description = "Model Context Protocol server for IMS (Instruction Management Systems)"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
File without changes
File without changes
File without changes