Skip to content

Conversation

aarora79
Copy link
Contributor

@aarora79 aarora79 commented Oct 1, 2025

Summary

This PR implements a comprehensive CLI tool for MCP server registration, health validation, and lifecycle management, addressing issue #120.

Key Features

1. Service Management Script (cli/service_mgmt.sh)

  • Add Command: Register new servers with automated verification
    • Config validation
    • Server registration
    • Scopes update verification
    • FAISS index verification
    • Health check validation
  • Delete Command: Remove servers with complete cleanup verification
  • Test Command: Validate server discoverability through intelligent search
  • Monitor Command: Real-time health status for all or specific services
  • Scopes Management: Add/remove servers from custom scopes groups

2. Enhanced MCP Client (cli/mcp_client.py)

  • Streamable HTTP transport support
  • JSON-formatted output for automation
  • Comprehensive error handling
  • Support for all MCP operations (ping, list tools, call tools)

3. MCP Utilities Library (cli/mcp_utils.py)

  • Token credential management
  • Automatic token refresh
  • HTTP client with authentication
  • Reusable functions for scripts

4. Example Server

  • Full-featured example MCP server (servers/example-server/)
  • Demonstrates best practices
  • Used for testing and validation
  • Complete with pyproject.toml and dependencies

5. Registry Management Tools (mcpgw server)

New tools exposed via /mcpgw endpoint:

  • list_services - List all registered servers
  • healthcheck_services - Get health status for all servers
  • register_service - Register new servers
  • remove_service - Remove servers
  • toggle_service - Enable/disable servers
  • add_server_to_scopes_groups - Add servers to specific scopes groups
  • remove_server_from_scopes_groups - Remove servers from scopes groups

6. Scopes Management

  • New registry/utils/scopes_manager.py for automated scopes.yml updates
  • Add/remove servers from scopes groups programmatically
  • Automatic auth server reload after scopes changes
  • Fix: New servers now only added to unrestricted groups by default (not all groups)

7. Documentation

  • Complete CLI guide (docs/cli.md)
  • Service management guide (docs/service-management.md)
  • Updated testing guide with new workflows
  • Integration examples and best practices

Changes

New Files

  • cli/service_mgmt.sh - Main service management script (822 lines)
  • cli/mcp_client.py - Enhanced MCP client (137 lines)
  • cli/mcp_utils.py - Utility library (426 lines)
  • cli/examples/ - Example configuration files
  • servers/example-server/ - Example MCP server implementation
  • registry/utils/scopes_manager.py - Scopes management utilities (408 lines)
  • docs/cli.md - CLI documentation (266 lines)
  • docs/service-management.md - Service management guide (503 lines)

Modified Files

  • servers/mcpgw/server.py - Added registry management tools
  • registry/api/server_routes.py - New internal API endpoints
  • registry/services/server_service.py - Enhanced server management
  • auth_server/server.py - Scopes reload endpoint
  • docs/testing.md - Updated with new testing workflows
  • README.md - Added service management references

Bug Fixes

  • Fixed server registration to only add new servers to unrestricted groups by default
  • Fixed service verification in add/delete workflows
  • Improved error handling in server registration

Testing

All features have been tested with:

  • Server registration and verification
  • Health check validation
  • Search and discovery testing
  • Scopes management operations
  • Token credential refresh

Documentation

Complete documentation provided:

Breaking Changes

None - all changes are additive and backward compatible.

Related Issues

Closes #120

Demo

The service management script provides comprehensive output:

# Add a server
./cli/service_mgmt.sh add cli/examples/server-config.json

=== Adding Service: example-server ===
✓ Credentials ready
✓ Registering service completed
✓ Server found in service list
✓ Server found in container scopes.yml (2 occurrences)
✓ Server found in host scopes.yml (2 occurrences)
✓ Server found in FAISS metadata (1 occurrences)
✓ Health check completed

Health Check Results:
==================================================
Service: /example-server
  Status: ✓ healthy
  Last checked: 5 seconds ago
  Tools available: 3

✓ Service example-server successfully added and verified!

- Move mcp_client.py to cli/ directory with enhanced functionality
- Add CLI installation script and comprehensive examples
- Create example MCP server with 3 tools (example_tool, echo_tool, status_tool)
- Add server management documentation with all mcp_client.py commands
- Implement internal API endpoints for toggle_service with HTTP Basic Auth
- Update scopes.yml to include all mcpgw tools in restricted scopes
- Add registry configuration for example-server
- Clean up redundant functions from mcpgw server (get_server_details, get_service_tools)
- Update tool counts and schemas in registry configurations
- Add Docker Compose service for example-server

Key features:
- Full CLI toolkit for MCP server management
- Dynamic server registration/removal via API
- Internal authentication for administrative operations
- Comprehensive documentation and examples
- Ready-to-use example server for testing

Addresses dynamic server management workflow and CLI tooling needs.
Major improvements to server registration workflow and service management:

Core Fixes:
- Fix server registration enabling order to resolve is_enabled: false in FAISS metadata
- Fix tool discovery conditions and add scopes update functionality in health checks
- Fix enum comparison bug in health status checking
- Add configurable health check interval via environment variable
- Improve logging to show discovered tool names

Service Management Overhaul:
- Add comprehensive service_mgmt.sh script for server lifecycle management
- Remove obsolete CLI tools (mcp_registry_cli.py, test_registry_cli.sh, install.sh)
- Add credential management system with automatic refresh
- Add scopes_manager.py utility for dynamic scopes.yml updates

Documentation Reorganization:
- Rename server-management.md to service-management.md with complete rewrite
- Move mcp_client.py documentation to new cli.md file
- Rewrite testing.md to use mcp_client.py instead of obsolete scripts
- Add end-to-end example section with example-server workflow
- Fix all references to non-existent scripts

Infrastructure Updates:
- Remove example-server from docker-compose.yml (backup created)
- Add service management utility to README.md What's New section
- Update environment variable configuration for health check intervals

This addresses server registration issues and establishes service_mgmt.sh
as the primary tool for server management with comprehensive verification.
- Add Regenerate Credentials section at top of testing.md
- Reference credentials-provider/generate_creds.sh script
- Explain 5-minute Keycloak token lifetime requirement
- Provide clear steps for generating fresh authentication tokens
Remove temporary backup files:
- README_backup.md
- cli/examples/server-config.json.backup
- docker-compose.yml.backup

These were created during development and are no longer needed.
- Add add_server_to_scopes_groups and remove_server_from_scopes_groups MCP tools
- Implement internal API endpoints for scopes groups management with admin auth
- Update service_mgmt.sh with add-to-groups and remove-from-groups commands
- Fix service verification to use server path instead of name
- Prevent YAML anchors/aliases in scopes.yml to maintain clean format
- Add comprehensive documentation for advanced scopes management
- Update docker-compose.yml to support ADMIN_USER and ADMIN_PASSWORD
Modified add_server_to_scopes() to only add newly registered servers
to unrestricted groups (mcp-servers-unrestricted/read and execute).
Previously, servers were being added to both unrestricted AND restricted
groups, which violated the principle of least privilege.

Changes:
- registry/utils/scopes_manager.py: Updated sections list in
  add_server_to_scopes() to only include unrestricted groups
- docs/service-management.md: Added documentation explaining the
  default behavior when registering new servers

This ensures new servers are only accessible to users with unrestricted
permissions by default. Administrators can explicitly add servers to
restricted groups using add_server_to_groups() when needed.
Corrected references to mcp_client.py to include the cli/ directory prefix.
The file was moved to cli/mcp_client.py but the macOS guide was not updated.
@aarora79 aarora79 merged commit 70a1d3a into main Oct 1, 2025
7 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI Tool for MCP Server Registration and Health Validation

1 participant