LogMCP Server
A Model Context Protocol (MCP) server implementation for log querying and system monitoring via Loki, using stdio transport.
Features
- MCP Protocol Support: Full implementation of the Model Context Protocol using stdio transport
- Loki Integration: Query logs from Loki using LogQL
- Multiple Environments: Support for test, dev, and prod environments
- Flexible Queries: Keyword-based and time-range-based log queries
- Error Handling: Comprehensive error handling and logging
- Async Support: Fully asynchronous implementation
Installation
This project uses uv as the package manager.
Prerequisites
- Python 3.8+
- uv package manager
Install uv
# On macOS and Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# On Windows
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
Install Dependencies
# Install project dependencies
uv sync
# Install development dependencies
uv sync --dev
Configuration
The server can be configured using environment variables:
| Variable | Description | Default |
|---|---|---|
LOKI_GATEWAY_URL |
Loki gateway URL | https://dev-hk-loki.bitkinetic.com |
LOKI_TIMEOUT |
Loki query timeout (seconds) | 30 |
LOKI_DEFAULT_LIMIT |
Default query result limit | 1000 |
LOKI_SSL_VERIFY |
Enable SSL certificate verification | true |
MCP_SERVER_NAME |
MCP server name | LogMCP Server |
LOG_LEVEL |
Logging level | INFO |
DEFAULT_SERVICE |
Default service name | zkme-token |
TEST_NAMESPACE |
Test environment namespace | zkme-test |
DEV_NAMESPACE |
Dev environment namespace | zkme-dev |
PROD_NAMESPACE |
Prod environment namespace | zkme-prod |
SSL Configuration
For test environments with self-signed certificates, you can disable SSL certificate verification:
# Disable SSL verification (for test environments only)
export LOKI_SSL_VERIFY=false
# Or enable SSL verification (default, recommended for production)
export LOKI_SSL_VERIFY=true
Security Note: Only disable SSL verification in test environments. Always keep SSL verification enabled in production environments for security.
Usage
Running the Server
# Using uvx
uvx logmcp
# Or using uv
uv run python main.py
# Or directly with Python
python main.py
MCP Tools
The server provides two main MCP tools:
1. loki_keyword_query
Query logs containing keywords from the last 30 days.
Parameters:
env(required): Environment name (test, dev, prod)keywords(required): Search keywords (comma-separated)service_name(optional): Service name (default: zkme-token)namespace(optional): Loki namespace (auto-detected from env)limit(optional): Result limit (default: 1000)
2. loki_range_query
Query logs containing keywords within a specified time range.
Parameters:
env(required): Environment name (test, dev, prod)start_date(required): Start date (YYYYMMDD format)end_date(required): End date (YYYYMMDD format)keywords(required): Search keywords (comma-separated)service_name(optional): Service name (default: zkme-token)namespace(optional): Loki namespace (auto-detected from env)limit(optional): Result limit (default: 1000)
Development
Running Tests
# Run all tests
uvx pytest
# Run tests with coverage
uvx pytest --cov=src/logmcp
# Run specific test file
uvx pytest tests/test_server.py
Code Formatting
# Format code with black
uvx black src tests
# Sort imports with isort
uvx isort src tests
# Type checking with mypy
uvx mypy src
Project Structure
LogMCP/
├── pyproject.toml # uv project configuration
├── main.py # Program entry point
├── README.md # Project documentation
├── src/logmcp/
│ ├── __init__.py # Package initialization
│ ├── server.py # MCP server implementation
│ ├── tools.py # MCP tools implementation
│ ├── config.py # Configuration management
│ ├── logger.py # Logging utilities
│ └── services/
│ ├── __init__.py # Services package
│ └── loki_service.py # Loki integration service
└── tests/
├── __init__.py # Test package
├── test_server.py # Server tests
├── test_tools.py # Tools tests
└── test_loki_service.py # Loki service tests
License
This project is licensed under the MIT License.
Metadata
Release files for logmcp 1.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| logmcp-1.0.3.tar.gz | 25.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| logmcp-1.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 38.1 kB
Release files / logmcp-1.0.3.tar.gz
| Download URL | logmcp-1.0.3.tar.gz |
|---|---|
| Size | 25.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bf88983718e09de9d4ecd2b844d08b6b75611e3e8eb940a20b48cdb05c6b9f9f
|
|
BLAKE2b-256 checksum How to use checksums |
86c6be02220f52807336cd92104ebac58fefc60f71a6cb8db6906f0ada268501
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.14
|
Release files / logmcp-1.0.3-py3-none-any.whl
| Download URL | logmcp-1.0.3-py3-none-any.whl |
|---|---|
| Size | 12.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ebf21b8c3d3a3c3b362a5a9c4d685863cc8a023d7e91277d89197ac914f79e3b
|
|
BLAKE2b-256 checksum How to use checksums |
1417293add4064fc65637ae42872aa1efa9b81af1cf2acea00d32548ff0608c6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.14
|
Security for logmcp 1.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.