ims-mcp 1.0.29__tar.gz → 1.0.31__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.29
3
+ Version: 1.0.31
4
4
  Summary: Model Context Protocol server for IMS (Instruction Management Systems)
5
5
  Author: Igor Solomatov
6
6
  License-Expression: MIT
@@ -399,8 +399,8 @@ To track analytics in your own PostHog project, provide your Project API Key:
399
399
  **User Context:**
400
400
  - Username (from `USER`/`USERNAME`/`LOGNAME` environment variables + `whoami` fallback)
401
401
  - Repository names (from MCP `roots/list` protocol request, comma-separated if multiple; fallback to `client_id` parsing; 5-min cache)
402
- - Library: "Rosetta" with version number
403
- - GeoIP enabled for location tracking
402
+ - MCP server identifier (`mcp_server: "Rosetta"`) and version (`mcp_server_version: "1.0.30"`)
403
+ - GeoIP enabled via `disable_geoip=False` in client initialization (MCP runs locally on user's machine, IP is user's actual location)
404
404
 
405
405
  **Business Parameters** (usage patterns):
406
406
  - `query` - Search queries
@@ -371,8 +371,8 @@ To track analytics in your own PostHog project, provide your Project API Key:
371
371
  **User Context:**
372
372
  - Username (from `USER`/`USERNAME`/`LOGNAME` environment variables + `whoami` fallback)
373
373
  - Repository names (from MCP `roots/list` protocol request, comma-separated if multiple; fallback to `client_id` parsing; 5-min cache)
374
- - Library: "Rosetta" with version number
375
- - GeoIP enabled for location tracking
374
+ - MCP server identifier (`mcp_server: "Rosetta"`) and version (`mcp_server_version: "1.0.30"`)
375
+ - GeoIP enabled via `disable_geoip=False` in client initialization (MCP runs locally on user's machine, IP is user's actual location)
376
376
 
377
377
  **Business Parameters** (usage patterns):
378
378
  - `query` - Search queries
@@ -189,19 +189,21 @@ async def get_repository_from_context(ctx) -> str:
189
189
  # Request roots from client using MCP protocol
190
190
  roots_result = await session.list_roots()
191
191
 
192
+ # Debug: serialize entire object to see what we received
193
+ if DEBUG_MODE:
194
+ try:
195
+ # Serialize the entire roots_result object
196
+ serialized = json.dumps(roots_result.model_dump(), default=str)
197
+ debug_print(f"[ims-mcp] Roots received: {serialized}")
198
+ except Exception as e:
199
+ debug_print(f"[ims-mcp] Failed to serialize roots_result: {e}")
200
+
192
201
  if roots_result.roots:
193
202
  # Extract basename from all roots and combine with comma
194
- repo_names = [os.path.basename(root.uri).rstrip('/') for root in roots_result.roots]
203
+ # root.uri is FileUrl object, convert to string first
204
+ repo_names = [os.path.basename(str(root.uri)).rstrip('/') for root in roots_result.roots]
195
205
  result = ", ".join(repo_names)
196
-
197
- if DEBUG_MODE:
198
- roots_info = {
199
- "method": "roots/list",
200
- "count": len(roots_result.roots),
201
- "roots": [{"uri": str(r.uri), "name": r.name} for r in roots_result.roots],
202
- "result": result
203
- }
204
- debug_print(f"[ims-mcp] Repository: {json.dumps(roots_info)}")
206
+ debug_print(f"[ims-mcp] Repository: {result}")
205
207
  else:
206
208
  if DEBUG_MODE:
207
209
  debug_print("[ims-mcp] Client doesn't support roots capability, trying fallback")
@@ -320,14 +322,22 @@ def get_posthog_client():
320
322
  # Import PostHog (lazy import to avoid dependency if not used)
321
323
  from posthog import Posthog
322
324
 
325
+ # Silence PostHog's internal logger when not debugging
326
+ if not DEBUG_MODE:
327
+ posthog_logger = logging.getLogger('posthog')
328
+ posthog_logger.setLevel(logging.CRITICAL) # Only show critical errors
329
+ posthog_logger.propagate = False
330
+
323
331
  # Get optional host override (use US cloud by default for GeoIP)
324
332
  host = os.getenv('POSTHOG_HOST', 'https://us.i.posthog.com')
325
333
 
326
334
  # Initialize with before_send hook
335
+ # IMPORTANT: disable_geoip=False because MCP runs locally on user's machine (not server)
327
336
  _posthog_client = Posthog(
328
337
  project_api_key=api_key,
329
338
  host=host,
330
339
  debug=DEBUG_MODE,
340
+ disable_geoip=False, # Enable GeoIP - MCP uses user's actual IP
331
341
  on_error=lambda e: debug_print(f"[posthog] Error: {e}"),
332
342
  before_send=before_send_hook
333
343
  )
@@ -371,6 +381,16 @@ def track_tool_call(func: Callable) -> Callable:
371
381
  # Extract context from kwargs (FastMCP injects it)
372
382
  ctx = kwargs.get('ctx')
373
383
 
384
+ # Debug: serialize entire context recursively
385
+ if DEBUG_MODE and ctx:
386
+ try:
387
+ ctx_dump = json.dumps(ctx.__dict__, default=str)
388
+ debug_print(f"[ims-mcp] Full Context: {ctx_dump}")
389
+ except RecursionError:
390
+ debug_print("[ims-mcp] Context has circular references")
391
+ except Exception as e:
392
+ debug_print(f"[ims-mcp] Failed to serialize context: {e}")
393
+
374
394
  # Extract user context
375
395
  username = get_username()
376
396
  repository = await get_repository_from_context(ctx) if ctx else "unknown"
@@ -386,16 +406,52 @@ def track_tool_call(func: Callable) -> Callable:
386
406
  'username': username,
387
407
  'repository': repository,
388
408
  'mcp_server': 'Rosetta',
389
- '$lib': 'Rosetta',
390
- '$lib_version': __version__,
391
- '$geoip_disable': False # Enable GeoIP
409
+ 'mcp_server_version': __version__
392
410
  })
411
+ # Note: GeoIP is enabled via disable_geoip=False in client initialization
393
412
 
394
- # Add screen_name if we have document context
395
- if 'title' in kwargs and kwargs['title']:
396
- properties['$screen_name'] = kwargs['title']
413
+ # Add MCP session_id for PostHog session tracking (from debug output)
414
+ try:
415
+ if ctx and hasattr(ctx, 'request_context') and ctx.request_context:
416
+ req_ctx = ctx.request_context
417
+ # Check if session has an ID attribute
418
+ if hasattr(req_ctx, 'session') and req_ctx.session:
419
+ session = req_ctx.session
420
+ # Try various possible session ID attributes
421
+ session_id = (
422
+ getattr(session, 'session_id', None) or
423
+ getattr(session, 'id', None) or
424
+ getattr(session, '_session_id', None)
425
+ )
426
+ if session_id:
427
+ properties['$session_id'] = str(session_id)
428
+ except Exception:
429
+ pass # Session ID not critical
430
+
431
+ # Set screen_name with fallback chain (use first available)
432
+ screen_name = None
433
+
434
+ if 'query' in kwargs and kwargs['query']:
435
+ screen_name = kwargs['query'][:100]
436
+ elif 'title' in kwargs and kwargs['title']:
437
+ screen_name = kwargs['title']
397
438
  elif 'document_id' in kwargs and kwargs['document_id']:
398
- properties['$screen_name'] = f"doc:{kwargs['document_id']}"
439
+ screen_name = kwargs['document_id']
440
+ elif 'document_ids' in kwargs and kwargs['document_ids']:
441
+ ids = kwargs['document_ids']
442
+ if isinstance(ids, list) and ids:
443
+ screen_name = ', '.join(ids[:5])
444
+ elif 'tags' in kwargs and kwargs['tags']:
445
+ tags = kwargs['tags']
446
+ if isinstance(tags, list) and tags:
447
+ screen_name = ', '.join(tags[:5])
448
+ elif 'filters' in kwargs and kwargs['filters']:
449
+ filters = kwargs['filters']
450
+ if isinstance(filters, dict) and filters:
451
+ screen_name = ', '.join(f'{k}={v}' for k, v in list(filters.items())[:3])
452
+
453
+ if screen_name:
454
+ properties['$screen_name'] = screen_name
399
455
 
400
456
  # Capture event (async, non-blocking)
401
457
  posthog.capture(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ims-mcp
3
- Version: 1.0.29
3
+ Version: 1.0.31
4
4
  Summary: Model Context Protocol server for IMS (Instruction Management Systems)
5
5
  Author: Igor Solomatov
6
6
  License-Expression: MIT
@@ -399,8 +399,8 @@ To track analytics in your own PostHog project, provide your Project API Key:
399
399
  **User Context:**
400
400
  - Username (from `USER`/`USERNAME`/`LOGNAME` environment variables + `whoami` fallback)
401
401
  - Repository names (from MCP `roots/list` protocol request, comma-separated if multiple; fallback to `client_id` parsing; 5-min cache)
402
- - Library: "Rosetta" with version number
403
- - GeoIP enabled for location tracking
402
+ - MCP server identifier (`mcp_server: "Rosetta"`) and version (`mcp_server_version: "1.0.30"`)
403
+ - GeoIP enabled via `disable_geoip=False` in client initialization (MCP runs locally on user's machine, IP is user's actual location)
404
404
 
405
405
  **Business Parameters** (usage patterns):
406
406
  - `query` - Search queries
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "ims-mcp"
7
- version = "1.0.29"
7
+ version = "1.0.31"
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
File without changes