-
Notifications
You must be signed in to change notification settings - Fork 4
MCP Server #255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
runleveldev
wants to merge
5
commits into
main
Choose a base branch
from
rgingras/feature/mcp
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
MCP Server #255
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
87348e7
fix: openapi spec cleanup
runleveldev 896ce54
feat: expose openapi.json on a URL for MCP consumption
runleveldev 6b1fe97
feat: awslabs.openapi-mcp-server wrapper for application/json support
runleveldev 71eebfc
fix: duplicate host-managed key
runleveldev 8f471b8
feat: api route for fetching sites
runleveldev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| .venv/ | ||
| build/ | ||
| *.egg-info/ | ||
| __pycache__/ | ||
| *.pyc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 3.13 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| # manager-control-program | ||
|
|
||
| MCP server that exposes the [create-a-container](../create-a-container/) REST API as [Model Context Protocol](https://modelcontextprotocol.io/) tools. It reads the OpenAPI spec at runtime from `create-a-container` and auto-generates MCP tool definitions using [`awslabs-openapi-mcp-server`](https://github.com/awslabs/mcp/tree/main/src/openapi-mcp-server), so it stays in sync with API changes automatically. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Python 3.13+ | ||
| - [uv](https://docs.astral.sh/uv/) package manager | ||
| - A running `create-a-container` instance with API access | ||
| - A bearer token (API key) from `create-a-container` | ||
|
|
||
| ## Setup | ||
|
|
||
| ```bash | ||
| uv sync | ||
| ``` | ||
|
|
||
| ## Environment Variables | ||
|
|
||
| | Variable | Required | Description | | ||
| |---|---|---| | ||
| | `API_BASE_URL` | **Yes** | Base URL of the `create-a-container` instance (e.g., `https://containers.example.com`) | | ||
| | `AUTH_TOKEN` | **Yes** | Bearer token for API authentication (create one at `/apikeys` in `create-a-container`) | | ||
|
|
||
| The server automatically sets `API_SPEC_URL` to `${API_BASE_URL}/api/openapi.json` and `AUTH_TYPE` to `bearer`. | ||
|
|
||
| ## Usage | ||
|
|
||
| ### From a Local Clone | ||
|
|
||
| ```bash | ||
| API_BASE_URL=https://containers.example.com AUTH_TOKEN=your-api-key uv run manager-control-program | ||
| ``` | ||
|
|
||
| ### From Git (No Clone Required) | ||
|
|
||
| ```bash | ||
| API_BASE_URL=https://containers.example.com AUTH_TOKEN=your-api-key \ | ||
| uvx --from "manager-control-program @ git+https://github.com/mieweb/opensource-server.git#subdirectory=manager-control-program" \ | ||
| manager-control-program | ||
| ``` | ||
|
|
||
| ### MCP Client Configuration | ||
|
|
||
| Add to your MCP client config (e.g., Claude Desktop, VS Code): | ||
|
|
||
| ```json | ||
| { | ||
| "mcpServers": { | ||
| "container-manager": { | ||
| "command": "uvx", | ||
| "args": [ | ||
| "--from", | ||
| "manager-control-program @ git+https://github.com/mieweb/opensource-server.git#subdirectory=manager-control-program", | ||
| "manager-control-program" | ||
| ], | ||
| "env": { | ||
| "API_BASE_URL": "https://containers.example.com", | ||
| "AUTH_TOKEN": "your-api-key" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## How It Works | ||
|
|
||
| ```mermaid | ||
| graph LR | ||
| A[MCP Client<br/>e.g. Claude] -->|MCP protocol<br/>stdio| B[manager-control-program] | ||
| B -->|GET /api/openapi.json| C[create-a-container] | ||
| B -->|REST API calls<br/>Bearer auth| C | ||
| ``` | ||
|
|
||
| 1. On startup, fetches the OpenAPI spec from `create-a-container` | ||
| 2. Generates an MCP tool for each API operation (list containers, create jobs, etc.) | ||
| 3. Proxies tool calls as authenticated REST requests to the API | ||
|
|
||
| ## Available Tools | ||
|
|
||
| Tools are generated dynamically from the OpenAPI spec. Typical operations include: | ||
|
|
||
| - **API Keys** — list, create, update, delete API keys | ||
| - **Containers** — list, create, inspect, delete LXC containers | ||
| - **Jobs** — create and monitor provisioning jobs | ||
| - **Storage** — query available Proxmox storage |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import os | ||
| import awslabs.openapi_mcp_server | ||
| from awslabs.openapi_mcp_server.server import load_config, create_mcp_server, setup_signal_handlers | ||
|
|
||
| def main(): | ||
| # We require API_BASE_URL to be set by the user so we know how to route API | ||
| # requests. | ||
| api_base_url = os.getenv("API_BASE_URL") | ||
| if not api_base_url: | ||
| raise RuntimeError( | ||
| "API_BASE_URL environment variable must be set to the base URL of the API " | ||
| "(for example, 'https://example.com')." | ||
| ) | ||
|
|
||
| api_base_url = api_base_url.rstrip("/") | ||
|
|
||
| # The default for the API_SPEC_URL is the shown path, but we allow the user | ||
| # to override it. This is useful when testing spec changes. | ||
| if "API_SPEC_URL" not in os.environ: | ||
| os.environ["API_SPEC_URL"] = f"{api_base_url}/api/openapi.json" | ||
|
|
||
| # We default to Bearer auth with requires the user to have set the | ||
| # AUTH_TOKEN environment variable. I'm unsure if any other auth types work, | ||
| # but we leave that door open incase it's needed. | ||
| if "AUTH_TYPE" not in os.environ: | ||
| os.environ["AUTH_TYPE"] = "bearer" | ||
|
|
||
| # The rest of this is more-or-less copied from the official | ||
| # awslabs.openapi_mpc_server.server:main function with the small exception | ||
| # of setting the Accept header to application/json. The official defaults to | ||
| # */* which makes our API return HTML instead of the JSON response, breaking | ||
| # the API spec. | ||
| config = load_config() | ||
| mcp_server = create_mcp_server(config) | ||
| mcp_server._client.headers['accept'] = 'application/json' | ||
| setup_signal_handlers() | ||
| mcp_server.run() | ||
|
|
||
| if __name__=='__main__': | ||
| main() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| [project] | ||
| name = "manager-control-program" | ||
| version = "0.1.0" | ||
| description = "MCP server that exposes the create-a-container REST API as Model Context Protocol tools" | ||
| readme = "README.md" | ||
| requires-python = ">=3.13" | ||
| dependencies = [ | ||
| "awslabs.openapi-mcp-server>=0.2.14", | ||
| "fastmcp>=2.14.0,<3.0.0", | ||
| ] | ||
|
|
||
runleveldev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| [project.scripts] | ||
| "manager-control-program" = "manager_control_program.server:main" | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.