Skip to content

Latest commit

 

History

History
314 lines (257 loc) · 11.6 KB

File metadata and controls

314 lines (257 loc) · 11.6 KB

ISTAT MCP Server - Project Status

Last Updated: March 14, 2026

Current Status

Core Functionality: Complete and operational ✅ All Tests: Passing (22/22 tests, 0.27s) ✅ Code Quality: Optimized (~80 lines reduced) ✅ Enhanced Logging: Implemented and documented ✅ Dataflow Blacklist: Implemented and operational ✅ Get Constraints Tool: Implemented with complete descriptions ⚠️ Claude Desktop Integration: Configuration management issue


Completed Work

1. Get Constraints Tool (March 14, 2026)

  • Feature: New MCP tool to retrieve available constraint values for each dimension with descriptions
  • Implementation:
    • Created src/istat_mcp_server/tools/get_constraints.py handler
    • Added DimensionConstraintWithDescriptions and TimeConstraintOutput models
    • Combines data from:
      • availableconstraint endpoint (valid values per dimension)
      • datastructure endpoint (dimension-to-codelist mapping)
      • codelist endpoint (code descriptions in IT/EN)
    • Returns complete JSON with dimensions, codelists, codes, and descriptions
    • Maintains dimension order from datastructure
    • Special handling for TIME_PERIOD dimension
  • Caching: 1 month TTL for constraints
  • Tests: 4 comprehensive tests covering success, errors, and edge cases
  • Documentation: Updated README.md with usage examples

2. Dataflow Blacklist System (March 13, 2026)

  • Feature: Filter out specific dataflows from all queries
  • Implementation:
    • Created src/istat_mcp_server/utils/blacklist.py module
    • Environment variable configuration via DATAFLOW_BLACKLIST
    • Automatic filtering in discover_dataflows tool
    • Validation blocking in get_data tool
  • Configuration: Comma-separated list in .env file
  • Use Cases:
    • Exclude deprecated datasets
    • Filter problematic dataflows
    • Hide internal/test datasets
  • Documentation: Updated README.md with configuration guide

2. Query String Format Correction (March 12-13, 2026)

  • Problem: ISTAT API returned 404 errors for queries with incorrect dimension formatting
  • Solution:
    • Empty dimensions now use . between separators (not ...)
    • Added conditional /ALL/ suffix based on dimension path
    • Example fixed: /data/{id}/A.IT.LU.1092./ALL/ (was /data/{id}/A.IT.LU.1092.../ALL/)
  • Files Modified:
    • src/istat_mcp_server/api/client.py (fetch_data method)

2. Empty Dimension Filtering (March 13, 2026)

  • Problem: Datastructures with empty dimension elements caused malformed queries
  • Solution: Added filter if not dimension: continue in fetch_datastructure
  • Location: src/istat_mcp_server/api/client.py line ~296
  • Impact: Prevents queries like ............/ALL/ that cause 404 errors

3. Code Optimization (March 12-13, 2026)

  • Achievement: Reduced ~80 lines across 4 files
  • Techniques Applied:
    • List comprehensions for filtering
    • Dict comprehensions for mappings
    • next() instead of loops for single items
    • Context managers for diskcache
    • Inline cache key construction
  • Files Optimized:
    • src/istat_mcp_server/tools/get_data.py
    • src/istat_mcp_server/tools/discover_dataflows.py
    • src/istat_mcp_server/tools/get_cache_diagnostics.py
    • src/istat_mcp_server/api/client.py

4. Enhanced Logging System (March 13, 2026)

  • Features:
    • MCP tool call logging: Arguments (JSON), execution time, response size
    • HTTP request logging: Visual symbols (→/←/✗), timing, response size
    • Structured format for easy parsing and analysis
  • Documentation: Created LOGGING_FORMAT.md
  • Files Modified:
    • src/istat_mcp_server/server.py (tool call wrapper)
    • src/istat_mcp_server/api/client.py (_get method enhancement)

Testing & Validation (March 14, 2026)

  • Status: All 22 tests passing
  • Execution Time: 0.27 seconds
  • Coverage: API client, cache system, all tools including get_constraints
  • New Tests: 4 tests for get_constraints tool
  • Files: tests/ directory

Known Issues

Claude Desktop Configuration Management

Issue ID: CLAUDE-CONFIG-001 Priority: High Status: Active Investigation

Description: Claude Desktop rewrites %APPDATA%\Claude\claude_desktop_config.json on startup, removing the mcpServers section that configures the ISTAT MCP server.

Impact:

  • Server fails to load automatically when Claude Desktop starts
  • User must manually reconfigure after each restart

Evidence:

  • Server worked correctly on March 12, 2026 21:50 (log files confirm)
  • Log file size: 5.2 MB (mcp-server-istat.log)
  • All tools executed successfully in previous sessions
  • Configuration file consistently reset to defaults

Root Cause Analysis:

  • Claude Desktop writes config file multiple times during startup
  • mcpServers section is either:
    • Stored in a different location (database, registry, UI-managed)
    • Managed through Claude Desktop UI (not yet discovered)
    • Subject to a bug in current Claude Desktop version

Current Workarounds:

  1. PowerShell Scripts (preferred):

    • setup_claude_config.ps1 - Configure before starting
    • verify_claude_config.ps1 - Verify after startup
  2. Manual Testing:

    .venv\Scripts\python.exe -m istat_mcp_server
  3. Read-only Flag (risky):

    • Makes config file read-only
    • May prevent Claude Desktop from saving other settings

Documentation Created:

  • CONFIGURAZIONE_CLAUDE.md - Complete setup guide
  • TROUBLESHOOTING_CLAUDE.md - Detailed troubleshooting procedures
  • Updated SKILLS.md - User-facing workflow guide
  • Updated copilot-instructions.md - Developer reference

Next Steps:

  1. ✅ Document the issue thoroughly
  2. ✅ Create setup/verification scripts
  3. ⏳ Check Claude Desktop UI for MCP server management
  4. ⏳ Investigate SQLite database (DIPS file) for configurations
  5. ⏳ Check Windows Registry for MCP server settings
  6. ⏳ Contact Anthropic support if issue persists

Technical Metrics

  • Lines of Code: ~1,800 (after get_constraints addition)
  • Test Coverage: Core functionality covered (22 tests)
  • Type Hints: 100% of public APIs
  • Docstrings: Google-style for all public functions

Performance

  • API Rate Limit: 3 calls/minute (enforced)
  • Cache Hit Rate: High (24h for dataflows, 1 month for metadata/constraints)
  • Average Tool Execution: < 1 second (cached), 1-3 seconds (API call)
  • Test Suite Execution: 0.27 seconds

MCP Tools

  • Total Tools: 7
  • discover_dataflows: Find datasets by keywords (with blacklist filtering)
  • get_structure: Get dimension definitions and codelists
  • get_constraints: Get available values for dimensions with descriptions (NEW)
  • get_codelist_description: Get codelist value descriptions
  • get_concepts: Get all concept schemes
  • get_data: Fetch actual statistical data (with blacklist validation)
  • get_cache_diagnostics: Debug cache system (cached), 1-3 seconds (API call)
  • Test Suite Execution: 0.19 seconds

Dependencies

  • Python 3.11+
  • MCP SDK 0.9.0+
  • 11 runtime dependencies (see pyproject.toml)
  • All dependencies up-to-date

Files Inventory

Core Implementation

  • src/istat_mcp_server/server.py - MCP server initialization (7 tools)
  • src/istat_mcp_server/api/client.py - ISTAT API client
  • src/istat_mcp_server/api/models.py - Pydantic models (including constraint models)
  • src/istat_mcp_server/cache/manager.py - Cache management
  • src/istat_mcp_server/tools/*.py - 7 tool implementations:
    • discover_dataflows.py
    • get_structure.py
    • get_constraints.py (NEW)
    • get_codelist_description.py
    • get_concepts.py
    • get_data.py
    • get_cache_diagnostics.py
  • src/istat_mcp_server/utils/blacklist.py - Dataflow blacklist manager

Documentation

  • README.md - Project overview and installation (updated for get_constraints)
  • SKILLS.md - User workflow guide
  • BLACKLIST_GUIDE.md - Blacklist configuration guide
  • .github/instructions/copilot-instructions.md - Developer reference
  • LOGGING_FORMAT.md - Logging documentation
  • CONFIGURAZIONE_CLAUDE.md - Claude Desktop setup
  • TROUBLESHOOTING_CLAUDE.md - Troubleshooting procedures

Scripts

  • setup_claude_config.ps1 - Configure Claude Desktop
  • verify_claude_config.ps1 - Verify configuration

Testing

  • tests/conftest.py - Test fixtures (including mock_cache_manager)
  • tests/test_*.py - 7 test modules (22 tests total):
    • test_blacklist.py (12 tests)
    • test_cache.py (4 tests)
    • test_get_constraints.py (4 tests, NEW)
    • test_validators.py (2 tests)
  • pytest.ini - Test configuration

Configuration

  • pyproject.toml - Project metadata and dependencies
  • .env.example - Environment variables template
  • ruff.toml - Code formatter configuration

Changelog Summary

v0.2.0 (March 14, 2026)

Added:

  • get_constraints tool - New MCP tool combining constraints, structure, and codelist descriptions
  • Mock cache manager fixture for testing
  • 4 comprehensive tests for get_constraints
  • DimensionConstraintWithDescriptions and TimeConstraintOutput models

Updated:

  • README.md with get_constraints examples and workflow
  • PROJECT_STATUS.md with latest metrics (22 tests, 7 tools)
  • Server tool count from 6 to 7

Testing:

  • All 22 tests passing (18 existing + 4 new)
  • Execution time: 0.27 seconds

v0.1.0 (March 13, 2026)

Added:

  • Dataflow blacklist system with environment variable configuration
  • Empty dimension filtering in datastructure parser
  • Enhanced logging for MCP tools and HTTP requests
  • Configuration management scripts for Claude Desktop
  • Comprehensive troubleshooting documentation
  • 12 tests for blacklist functionality

Fixed:

  • ISTAT API query string format for empty dimensions
  • Double slash issue when dimension path is empty
  • Cache key construction for data queries Add get_constraints tool - ✅ COMPLETED (March 14, 2026)
  1. Verify constraint ordering - Ensure dimensions maintain correct order

Medium Priority

  1. Add Resources capability - Expose cached data as MCP resources
  2. Implement Prompts capability - Pre-built analysis prompts
  3. Add data format conversion - CSV output option
  • Added BLACKLIST_GUIDE.md
  • Added LOGGING_FORMAT.md
  • Added CONFIGURAZIONE_CLAUDE.md
  • Added TROUBLESHOOTING_CLAUDE.md
  • Updated SKILLS.md with configuration section
  • Updated copilot-instructions.md with recent changes and lessons learned

Next Development Priorities

High Priority

  1. Resolve Claude Desktop configuration issue - Blocks automatic loading
  2. Add get_concepts tool tests - Currently missing from test suite
  3. Verify dataflow discovery filtering - Ensure keywords work correctly

Medium Priority

  1. Add Resources capability - Expose cached data as MCP resources
  2. Implement Prompts capability - Pre-built analysis prompts
  3. Add data format conversion - TSV/CSV output in get_data
  4. Enhance error messages - More user-friendly error descriptions

Low Priority

  1. Add progress indicators - For long-running API calls
  2. Implement partial caching - Cache query filters separately
  3. Add data validation - Verify SDMX XML structure
  4. Performance profiling - Identify bottlenecks

Contact & Support

Developer: [Your Name] Repository: [GitHub Link] Issues: [GitHub Issues Link] Documentation: See README.md and SKILLS.md

For questions about:

  • Usage: See SKILLS.md
  • Development: See .github/instructions/copilot-instructions.md
  • Claude Desktop: See CONFIGURAZIONE_CLAUDE.md and TROUBLESHOOTING_CLAUDE.md
  • Logging: See LOGGING_FORMAT.md