Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
**/__pycache__/
**/.git
**/.github
**/.mypy_cache
**/.pytest_cache
**/.vscode
**/.idea
**/.coverage
**/.DS_Store
**/.python-version
**/*.bak
**/*.pyc
**/node_modules/

tests/
docs/
install/
venv
.venv
1 change: 1 addition & 0 deletions .github/copilot-instructions.md
13 changes: 13 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
repos:
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.15.0
hooks:
- id: mypy
name: mypy
args: [--show-error-codes src/]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.12.4
hooks:
- id: ruff-format
- id: ruff
args: [--fix]
1 change: 1 addition & 0 deletions CLAUDE.md
1 change: 1 addition & 0 deletions GEMINI.md
1 change: 1 addition & 0 deletions GPT.md
49 changes: 49 additions & 0 deletions LLMS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# LLM Context Guide for Infrahub MCP Server

Infrahub MCP Server connects your AI assistants to Infrahub using the open MCP standard—so agents can read and (optionally) change your infra state through a consistent, audited, human-approved interface.

## Key Directories

```
infrahub-mcp/
├── docs/ # Documentation (UPDATE FOR CHANGES)
├── src/ # Python Code
│   └── infrahub_mcp/
│ ├── __init__.py
| ├── branch.py
| ├── constants.py
| ├── gql.py
| ├── nodes.py
| ├── prompts/
| │   └── main.md
| ├── schema.py
| ├── server.py
| └── utils.py
└── tests/ # Python/integration tests
```

## Code Standards

### Python Backend

- **Type hints required** for all new code
- **MyPy compliant** - run `pre-commit run mypy`
- **Ruf compliant**- run `pre-commit run ruff`
- **pytest** for testing

## Documentation Requirements

- **docs/**: Update for any user-facing changes
- **Docstrings**: Required for new functions/classes

## Test Utilities

### Running Tests

## Platform-Specific Instructions

- **[CLAUDE.md](CLAUDE.md)** - For Claude/Anthropic tools
- **[.github/copilot-instructions.md](.github/copilot-instructions.md)** - For GitHub Copilot
- **[GEMINI.md](GEMINI.md)** - For Google Gemini tools
- **[GPT.md](GPT.md)** - For OpenAI/ChatGPT tools
- **[.cursor/rules/dev-standard.mdc](.cursor/rules/dev-standard.mdc)** - For Cursor editor
155 changes: 12 additions & 143 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,150 +1,19 @@
# Infrahub MCP Server
<!-- markdownlint-disable -->
![Infrahub Logo](https://assets-global.website-files.com/657aff4a26dd8afbab24944b/657b0e0678f7fd35ce130776_Logo%20INFRAHUB.svg)
<!-- markdownlint-restore -->

MCP server to interact with Infrahub
# Infrahub MCP

## Requirements
[Infrahub](https://github.com/opsmill/infrahub) by [OpsMill](https://opsmill.com) acts as a central hub to manage the data, templates and playbooks that powers your infrastructure. At its heart, Infrahub is built on 3 fundamental pillars:

- Python 3.13+
- fastmcp
- infrahub_sdk
- **A Flexible Schema**: A model of the infrastructure and the relation between the objects in the model, that's easily extensible.
- **Version Control**: Natively integrated into the graph database which opens up some new capabilities like branching, diffing, and merging data directly in the database.
- **Unified Storage**: By combining a graph database and git, Infrahub stores data and code needed to manage the infrastructure.

## Introduction

## Installation
Infrahub MCP Server connects your AI assistants to Infrahub using the open MCP standard—so agents can read and (optionally) change your infra state through a consistent, audited, human-approved interface.

1. **Clone the repo**

```bash
git clone https://github.com/opsmill/infrahub-mcp-server.git
cd infrahub-mcp-server
```

2. **Install dependencies**

```bash
uv sync
```

3. **Run the server**

```bash
uv run fastmcp run src/infrahub_mcp_server/server.py:mcp
```


## Configuration

Set the following environment variables as needed:

| Variable | Description | Default |
|---------------------|-------------------------------------|--------------------------|
| `INFRAHUB_ADDRESS` | URL of your Infrahub instance | `http://localhost:8000` |
| `INFRAHUB_API_TOKEN`| API token for Infrahub | `placeholder UUID` |
| `MCP_HOST` | Host for the web server | `0.0.0.0` |
| `MCP_PORT` | Port for the web server | `8001` |


## Usage

### HTTP API mode

```bash
poetry run python server.py --web
```

Send a POST request to the root endpoint (/):

```bash
curl -X POST http://localhost:8001/ \\
-H "Content-Type: application/json" \\
-d '{
"tool": "infrahub_get_nodes",
"params": {
"kind": "Tag",
"filters": { "any": "blue" },
"partial_match": false
}
}'
```

### CLI / stdin-stdout mode

```bash
uv run fastmcp run src/infrahub_mcp_server/server.py:mcp
```

Then send JSON-RPC requests to stdin:

```bash
{"jsonrpc":"2.0","method":"tools/discover","params":{}}
{"jsonrpc":"2.0","method":"tools/call","params":{"name": "infrahub_get_nodes","arguments": {"kind":"Router","filters": {"location":"eu-west"}}}}
```

Process one-shot request with --oneshot:

```bash
echo '{"method":"tools/discover"}' | poetry run python server.py --oneshot
```

## MCP Methods

### infrahub_get_nodes
Retrieve nodes of a given kind.

Params:

- kind (string, required): node kind (e.g. "Router")
- branch (string): branch name
- filters (object): key/value filters
- simple keys → <key>__value
- list values → <key>__values
- use "any" to search across all attributes
- partial_match (boolean): true for substring matches
- infrahub_url (string): override via param
- infrahub_api_token (string): override via param

Response:

```json
{
"success": true,
"count": 5,
"nodes": [ { ... }, ... ]
}
```

### infrahub_get_schema

Retrieve schema details.

Params:

- kind (string): kind name; omit to fetch all schemas
- branch (string)
- exclude_profiles (boolean)
- exclude_templates (boolean)
- infrahub_url (string)
- infrahub_api_token (string)

Response (single kind):

```json
{
"success": true,
"kind": "Tag",
"namespace": "...",
"name": "...",
"attributes": [ { "name": "...", "type": "...", "description": "..." }, ... ],
"relationships": [ { "name": "...", "rel_kind": "...", "cardinality": "...", "description": "..." }, ... ]
}
```

Response (all schemas):

```json
{
"success": true,
"count": 12,
"schemas": [ { ... }, ... ]
}
```
## Using Infrahub MCP

Documentation for using Infrahub Sync is available [here](https://docs.infrahub.app/mcp/)
Loading
Loading