Splunk MCP Server

Splunk MCP Server

Enables AI assistants to interact with Splunk Enterprise and Splunk Cloud instances through standardized MCP interface. Supports executing SPL queries, managing indexes and saved searches, listing applications, and retrieving server information with flexible authentication options.

Category
访问服务器

README

Splunk MCP Server

A Model Context Protocol (MCP) server for interacting with Splunk Enterprise and Splunk Cloud. This server enables AI assistants to search Splunk data, list indexes, manage saved searches, and retrieve server information through a standardized interface.

Features

  • Search Execution: Run SPL (Search Processing Language) queries with configurable time ranges and limits
  • Index Management: List and filter available Splunk indexes
  • Saved Searches: Retrieve and manage saved searches
  • Application Listing: Browse installed Splunk applications
  • Server Information: Get Splunk server details and health status
  • Flexible Authentication: Support for both token-based and username/password authentication
  • Async Operations: Built with modern Python async/await patterns
  • Type Safety: Full Pydantic models for request/response validation

Installation

Prerequisites

  • Python 3.8 or higher
  • Access to a Splunk Enterprise or Splunk Cloud instance
  • Valid Splunk credentials (token or username/password)

Quick Start

  1. Clone the repository:

    git clone https://github.com/yourusername/splunk-mcp.git
    cd splunk-mcp
    
  2. Install dependencies:

    pip install -r requirements.txt
    
  3. Configure environment variables:

    cp .env.example .env
    # Edit .env with your Splunk connection details
    
  4. Run the server:

    python src/main.py
    

Development Installation

For development with additional tools:

pip install -e ".[dev]"

Configuration

The server is configured using environment variables. Copy .env.example to .env and configure:

Required Variables

# Splunk server connection
SPLUNK_HOST=your-splunk-server.com

Authentication (choose one method)

Token-based authentication (recommended):

SPLUNK_TOKEN=your-splunk-token-here

Username/password authentication:

SPLUNK_USERNAME=your-username
SPLUNK_PASSWORD=your-password

Optional Variables

SPLUNK_PORT=8089                    # Management port (default: 8089)
SPLUNK_SCHEME=https                 # http or https (default: https)
SPLUNK_VERIFY_SSL=true             # SSL verification (default: true)
SPLUNK_TIMEOUT=30                  # Request timeout (default: 30)
LOG_LEVEL=INFO                     # Logging level

Usage

Once running, the MCP server provides the following tools:

1. Search Splunk Data

Execute SPL queries with configurable parameters:

{
    "query": "search index=main error | head 10",
    "earliest_time": "-24h@h",
    "latest_time": "now",
    "max_count": 100,
    "timeout": 60
}

2. List Indexes

Get available Splunk indexes with optional filtering:

{
    "pattern": "main*"  # Optional pattern filter
}

3. Manage Saved Searches

Retrieve saved searches by name or owner:

{
    "search_name": "Security Alert",  # Optional
    "owner": "admin"                  # Optional
}

4. List Applications

Browse installed Splunk apps:

{
    "visible_only": true  # Show only visible apps
}

5. Get Server Information

Retrieve Splunk server details and health status.

API Reference

Search Parameters

Parameter Type Default Description
query string required SPL search query
earliest_time string "-24h@h" Search time range start
latest_time string "now" Search time range end
max_count integer 100 Maximum results (1-10000)
timeout integer 60 Search timeout in seconds

Time Range Examples

  • "-24h@h" - 24 hours ago, rounded to the hour
  • "-7d@d" - 7 days ago, rounded to the day
  • "2024-01-01T00:00:00" - Absolute timestamp
  • "now" - Current time
  • "-1h" - 1 hour ago

SPL Query Examples

# Basic search
search index=main error

# Search with stats
index=main | stats count by host

# Time-based search
index=security earliest=-1h | where _time > relative_time(now(), "-30m")

# Complex search with transformations
index=web_logs 
| rex field=_raw "(?<status_code>\d{3})" 
| stats count by status_code 
| sort -count

Authentication

Token-Based Authentication (Recommended)

  1. Create a token in Splunk Web:

    • Go to Settings > Tokens
    • Click "New Token"
    • Set appropriate permissions
    • Copy the generated token
  2. Configure environment:

    SPLUNK_TOKEN=your-token-here
    

Username/Password Authentication

SPLUNK_USERNAME=your-username
SPLUNK_PASSWORD=your-password

Note: Token authentication is more secure and is the recommended approach for production deployments.

Error Handling

The server provides detailed error responses:

{
    "status": "error",
    "error": "Authentication failed",
    "details": {
        "code": 401,
        "message": "Invalid credentials"
    }
}

Common error scenarios:

  • Authentication failures: Invalid credentials or expired tokens
  • Query syntax errors: Malformed SPL queries
  • Permission issues: Insufficient access to indexes or searches
  • Timeout errors: Long-running searches exceeding timeout limits
  • Connection issues: Network problems or Splunk server unavailability

Security Considerations

  • Use HTTPS: Always use encrypted connections in production
  • Secure credentials: Store tokens and passwords securely
  • Limit permissions: Use principle of least privilege for Splunk accounts
  • Network security: Restrict network access to Splunk management ports
  • Token rotation: Regularly rotate authentication tokens

Development

Project Structure

splunk-mcp/
├── src/
│   ├── main.py              # MCP server entry point
│   ├── splunk_client.py     # Splunk REST API client
│   ├── config.py            # Configuration management
│   └── models.py            # Pydantic data models
├── tests/                   # Test files
├── docs/                    # Documentation
└── requirements.txt         # Dependencies

Running Tests

pytest tests/

Code Formatting

black src/ tests/
isort src/ tests/

Type Checking

mypy src/

Deployment

Docker Deployment

Create a Dockerfile:

FROM python:3.11-slim

WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt

COPY src/ ./src/
COPY .env .

CMD ["python", "src/main.py"]

Build and run:

docker build -t splunk-mcp .
docker run --env-file .env splunk-mcp

Production Considerations

  • Use a process manager like supervisor or systemd
  • Configure proper logging and monitoring
  • Set up health checks
  • Use environment-specific configuration
  • Implement proper secret management

Troubleshooting

Common Issues

  1. Connection refused:

    • Check Splunk server is running
    • Verify host and port settings
    • Check network connectivity
  2. Authentication errors:

    • Verify credentials are correct
    • Check token hasn't expired
    • Ensure user has necessary permissions
  3. Search timeouts:

    • Reduce search time range
    • Optimize SPL query
    • Increase timeout setting
  4. SSL errors:

    • Check certificate validity
    • Set SPLUNK_VERIFY_SSL=false for testing (not recommended for production)

Enabling Debug Logging

LOG_LEVEL=DEBUG python src/main.py

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Run the test suite
  6. Submit a pull request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

Changelog

v1.0.0

  • Initial release
  • Basic search functionality
  • Token and username/password authentication
  • Index and saved search management
  • Application listing
  • Server information retrieval

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选