mcp-server-apache-airflow 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of mcp-server-apache-airflow might be problematic. Click here for more details.

@@ -0,0 +1,39 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ .Python
7
+ build/
8
+ develop-eggs/
9
+ dist/
10
+ downloads/
11
+ eggs/
12
+ .eggs/
13
+ lib/
14
+ lib64/
15
+ parts/
16
+ sdist/
17
+ var/
18
+ wheels/
19
+ *.egg-info/
20
+ .installed.cfg
21
+ *.egg
22
+ .pypirc
23
+
24
+ # Virtual Environment
25
+ .env
26
+ .venv
27
+ env/
28
+ venv/
29
+ ENV/
30
+
31
+ # IDE
32
+ .idea/
33
+ .vscode/
34
+ *.swp
35
+ *.swo
36
+
37
+ # OS
38
+ .DS_Store
39
+ Thumbs.db
@@ -0,0 +1,149 @@
1
+ Metadata-Version: 2.4
2
+ Name: mcp-server-apache-airflow
3
+ Version: 0.1.0
4
+ Summary: Model Context Protocol (MCP) server for Apache Airflow
5
+ Project-URL: Homepage, https://github.com/yangkyeongmo/mcp-server-apache-airflow
6
+ Project-URL: Repository, https://github.com/yangkyeongmo/mcp-server-apache-airflow.git
7
+ Project-URL: Bug Tracker, https://github.com/yangkyeongmo/mcp-server-apache-airflow/issues
8
+ Author-email: Gyeongmo Yang <me@gmyang.dev>
9
+ License: MIT
10
+ Keywords: airflow,apache-airflow,mcp,model-context-protocol
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
+ Requires-Python: >=3.9
20
+ Requires-Dist: click>=8.1.7
21
+ Requires-Dist: httpx>=0.24.1
22
+ Requires-Dist: mcp>=0.1.0
23
+ Description-Content-Type: text/markdown
24
+
25
+ # mcp-server-apache-airflow
26
+
27
+ A Model Context Protocol (MCP) server implementation for Apache Airflow, enabling seamless integration with MCP clients. This project provides a standardized way to interact with Apache Airflow through the Model Context Protocol.
28
+
29
+ ## About
30
+
31
+ This project implements a [Model Context Protocol](https://modelcontextprotocol.io/introduction) server that wraps Apache Airflow's REST API, allowing MCP clients to interact with Airflow in a standardized way.
32
+
33
+ ## Feature Implementation Status
34
+
35
+ | Feature | API Path | Status |
36
+ |---------|----------|--------|
37
+ | **DAG Management** | | |
38
+ | List DAGs | `/api/v1/dags` | ✅ |
39
+ | Get DAG Details | `/api/v1/dags/{dag_id}` | ✅ |
40
+ | Pause DAG | `/api/v1/dags/{dag_id}` | ✅ |
41
+ | Unpause DAG | `/api/v1/dags/{dag_id}` | ✅ |
42
+ | Update DAG | `/api/v1/dags/{dag_id}` | ❌ |
43
+ | Delete DAG | `/api/v1/dags/{dag_id}` | ❌ |
44
+ | **DAG Runs** | | |
45
+ | List DAG Runs | `/api/v1/dags/{dag_id}/dagRuns` | ✅ |
46
+ | Create DAG Run | `/api/v1/dags/{dag_id}/dagRuns` | ✅ |
47
+ | Get DAG Run Details | `/api/v1/dags/{dag_id}/dagRuns/{dag_run_id}` | ❌ |
48
+ | Update DAG Run | `/api/v1/dags/{dag_id}/dagRuns/{dag_run_id}` | ❌ |
49
+ | Delete DAG Run | `/api/v1/dags/{dag_id}/dagRuns/{dag_run_id}` | ❌ |
50
+ | **Tasks** | | |
51
+ | List DAG Tasks | `/api/v1/dags/{dag_id}/tasks` | ✅ |
52
+ | Get Task Details | `/api/v1/dags/{dag_id}/tasks/{task_id}` | ❌ |
53
+ | Get Task Instance | `/api/v1/dags/{dag_id}/dagRuns/{dag_run_id}/taskInstances/{task_id}` | ✅ |
54
+ | List Task Instances | `/api/v1/dags/{dag_id}/dagRuns/{dag_run_id}/taskInstances` | ✅ |
55
+ | Update Task Instance | `/api/v1/dags/{dag_id}/dagRuns/{dag_run_id}/taskInstances/{task_id}` | ❌ |
56
+ | **System** | | |
57
+ | Get Import Errors | `/api/v1/importErrors` | ✅ |
58
+ | Get Import Error Details | `/api/v1/importErrors/{import_error_id}` | ✅ |
59
+ | Get Health Status | `/api/v1/health` | ✅ |
60
+ | Get Version | `/api/v1/version` | ✅ |
61
+ | **Variables** | | |
62
+ | List Variables | `/api/v1/variables` | ❌ |
63
+ | Create Variable | `/api/v1/variables` | ❌ |
64
+ | Get Variable | `/api/v1/variables/{variable_key}` | ❌ |
65
+ | Update Variable | `/api/v1/variables/{variable_key}` | ❌ |
66
+ | Delete Variable | `/api/v1/variables/{variable_key}` | ❌ |
67
+ | **Connections** | | |
68
+ | List Connections | `/api/v1/connections` | ❌ |
69
+ | Create Connection | `/api/v1/connections` | ❌ |
70
+ | Get Connection | `/api/v1/connections/{connection_id}` | ❌ |
71
+ | Update Connection | `/api/v1/connections/{connection_id}` | ❌ |
72
+ | Delete Connection | `/api/v1/connections/{connection_id}` | ❌ |
73
+
74
+ ## Setup
75
+
76
+ ### Environment Variables
77
+
78
+ Set the following environment variables:
79
+ ```
80
+ AIRFLOW_HOST=<your-airflow-host>
81
+ AIRFLOW_USERNAME=<your-airflow-username>
82
+ AIRFLOW_PASSWORD=<your-airflow-password>
83
+ ```
84
+
85
+ ### Usage with Claude Desktop
86
+
87
+ Add to your `claude_desktop_config.json`:
88
+
89
+ ```json
90
+ {
91
+ "mcpServers": {
92
+ "mcp-server-apache-airflow": {
93
+ "command": "uvx",
94
+ "args": ["mcp-server-apache-airflow"],
95
+ "env": {
96
+ "AIRFLOW_HOST": "https://your-airflow-host",
97
+ "AIRFLOW_USERNAME": "your-username",
98
+ "AIRFLOW_PASSWORD": "your-password"
99
+ }
100
+ }
101
+ }
102
+ }
103
+ ```
104
+
105
+ Alternative configuration using `uv`:
106
+
107
+ ```json
108
+ {
109
+ "mcpServers": {
110
+ "mcp-server-apache-airflow": {
111
+ "command": "uv",
112
+ "args": [
113
+ "--directory",
114
+ "/path/to/mcp-server-apache-airflow",
115
+ "run",
116
+ "mcp-server-apache-airflow"
117
+ ],
118
+ "env": {
119
+ "AIRFLOW_HOST": "https://your-airflow-host",
120
+ "AIRFLOW_USERNAME": "your-username",
121
+ "AIRFLOW_PASSWORD": "your-password"
122
+ }
123
+ }
124
+ }
125
+ }
126
+ ```
127
+
128
+ Replace `/path/to/mcp-server-apache-airflow` with the actual path where you've cloned the repository.
129
+
130
+ ### Manual Execution
131
+
132
+ You can also run the server manually:
133
+ ```bash
134
+ python src/server.py
135
+ ```
136
+
137
+ Options:
138
+ - `--port`: Port to listen on for SSE (default: 8000)
139
+ - `--transport`: Transport type (stdio/sse, default: stdio)
140
+
141
+ ## Contributing
142
+
143
+ Contributions are welcome! Please feel free to submit a Pull Request.
144
+
145
+ ## License
146
+
147
+ [Add your license information here]
148
+
149
+
@@ -0,0 +1,125 @@
1
+ # mcp-server-apache-airflow
2
+
3
+ A Model Context Protocol (MCP) server implementation for Apache Airflow, enabling seamless integration with MCP clients. This project provides a standardized way to interact with Apache Airflow through the Model Context Protocol.
4
+
5
+ ## About
6
+
7
+ This project implements a [Model Context Protocol](https://modelcontextprotocol.io/introduction) server that wraps Apache Airflow's REST API, allowing MCP clients to interact with Airflow in a standardized way.
8
+
9
+ ## Feature Implementation Status
10
+
11
+ | Feature | API Path | Status |
12
+ |---------|----------|--------|
13
+ | **DAG Management** | | |
14
+ | List DAGs | `/api/v1/dags` | ✅ |
15
+ | Get DAG Details | `/api/v1/dags/{dag_id}` | ✅ |
16
+ | Pause DAG | `/api/v1/dags/{dag_id}` | ✅ |
17
+ | Unpause DAG | `/api/v1/dags/{dag_id}` | ✅ |
18
+ | Update DAG | `/api/v1/dags/{dag_id}` | ❌ |
19
+ | Delete DAG | `/api/v1/dags/{dag_id}` | ❌ |
20
+ | **DAG Runs** | | |
21
+ | List DAG Runs | `/api/v1/dags/{dag_id}/dagRuns` | ✅ |
22
+ | Create DAG Run | `/api/v1/dags/{dag_id}/dagRuns` | ✅ |
23
+ | Get DAG Run Details | `/api/v1/dags/{dag_id}/dagRuns/{dag_run_id}` | ❌ |
24
+ | Update DAG Run | `/api/v1/dags/{dag_id}/dagRuns/{dag_run_id}` | ❌ |
25
+ | Delete DAG Run | `/api/v1/dags/{dag_id}/dagRuns/{dag_run_id}` | ❌ |
26
+ | **Tasks** | | |
27
+ | List DAG Tasks | `/api/v1/dags/{dag_id}/tasks` | ✅ |
28
+ | Get Task Details | `/api/v1/dags/{dag_id}/tasks/{task_id}` | ❌ |
29
+ | Get Task Instance | `/api/v1/dags/{dag_id}/dagRuns/{dag_run_id}/taskInstances/{task_id}` | ✅ |
30
+ | List Task Instances | `/api/v1/dags/{dag_id}/dagRuns/{dag_run_id}/taskInstances` | ✅ |
31
+ | Update Task Instance | `/api/v1/dags/{dag_id}/dagRuns/{dag_run_id}/taskInstances/{task_id}` | ❌ |
32
+ | **System** | | |
33
+ | Get Import Errors | `/api/v1/importErrors` | ✅ |
34
+ | Get Import Error Details | `/api/v1/importErrors/{import_error_id}` | ✅ |
35
+ | Get Health Status | `/api/v1/health` | ✅ |
36
+ | Get Version | `/api/v1/version` | ✅ |
37
+ | **Variables** | | |
38
+ | List Variables | `/api/v1/variables` | ❌ |
39
+ | Create Variable | `/api/v1/variables` | ❌ |
40
+ | Get Variable | `/api/v1/variables/{variable_key}` | ❌ |
41
+ | Update Variable | `/api/v1/variables/{variable_key}` | ❌ |
42
+ | Delete Variable | `/api/v1/variables/{variable_key}` | ❌ |
43
+ | **Connections** | | |
44
+ | List Connections | `/api/v1/connections` | ❌ |
45
+ | Create Connection | `/api/v1/connections` | ❌ |
46
+ | Get Connection | `/api/v1/connections/{connection_id}` | ❌ |
47
+ | Update Connection | `/api/v1/connections/{connection_id}` | ❌ |
48
+ | Delete Connection | `/api/v1/connections/{connection_id}` | ❌ |
49
+
50
+ ## Setup
51
+
52
+ ### Environment Variables
53
+
54
+ Set the following environment variables:
55
+ ```
56
+ AIRFLOW_HOST=<your-airflow-host>
57
+ AIRFLOW_USERNAME=<your-airflow-username>
58
+ AIRFLOW_PASSWORD=<your-airflow-password>
59
+ ```
60
+
61
+ ### Usage with Claude Desktop
62
+
63
+ Add to your `claude_desktop_config.json`:
64
+
65
+ ```json
66
+ {
67
+ "mcpServers": {
68
+ "mcp-server-apache-airflow": {
69
+ "command": "uvx",
70
+ "args": ["mcp-server-apache-airflow"],
71
+ "env": {
72
+ "AIRFLOW_HOST": "https://your-airflow-host",
73
+ "AIRFLOW_USERNAME": "your-username",
74
+ "AIRFLOW_PASSWORD": "your-password"
75
+ }
76
+ }
77
+ }
78
+ }
79
+ ```
80
+
81
+ Alternative configuration using `uv`:
82
+
83
+ ```json
84
+ {
85
+ "mcpServers": {
86
+ "mcp-server-apache-airflow": {
87
+ "command": "uv",
88
+ "args": [
89
+ "--directory",
90
+ "/path/to/mcp-server-apache-airflow",
91
+ "run",
92
+ "mcp-server-apache-airflow"
93
+ ],
94
+ "env": {
95
+ "AIRFLOW_HOST": "https://your-airflow-host",
96
+ "AIRFLOW_USERNAME": "your-username",
97
+ "AIRFLOW_PASSWORD": "your-password"
98
+ }
99
+ }
100
+ }
101
+ }
102
+ ```
103
+
104
+ Replace `/path/to/mcp-server-apache-airflow` with the actual path where you've cloned the repository.
105
+
106
+ ### Manual Execution
107
+
108
+ You can also run the server manually:
109
+ ```bash
110
+ python src/server.py
111
+ ```
112
+
113
+ Options:
114
+ - `--port`: Port to listen on for SSE (default: 8000)
115
+ - `--transport`: Transport type (stdio/sse, default: stdio)
116
+
117
+ ## Contributing
118
+
119
+ Contributions are welcome! Please feel free to submit a Pull Request.
120
+
121
+ ## License
122
+
123
+ [Add your license information here]
124
+
125
+
@@ -0,0 +1,48 @@
1
+ [project]
2
+ name = "mcp-server-apache-airflow"
3
+ version = "0.1.0"
4
+ description = "Model Context Protocol (MCP) server for Apache Airflow"
5
+ authors = [
6
+ { name = "Gyeongmo Yang", email = "me@gmyang.dev" }
7
+ ]
8
+ dependencies = [
9
+ "httpx>=0.24.1",
10
+ "click>=8.1.7",
11
+ "mcp>=0.1.0",
12
+ ]
13
+ requires-python = ">=3.9"
14
+ readme = "README.md"
15
+ license = { text = "MIT" }
16
+ classifiers = [
17
+ "Development Status :: 3 - Alpha",
18
+ "Intended Audience :: Developers",
19
+ "License :: OSI Approved :: MIT License",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3.9",
22
+ "Programming Language :: Python :: 3.10",
23
+ "Programming Language :: Python :: 3.11",
24
+ "Topic :: Software Development :: Libraries :: Python Modules",
25
+ ]
26
+ keywords = ["mcp", "airflow", "apache-airflow", "model-context-protocol"]
27
+
28
+ [project.urls]
29
+ Homepage = "https://github.com/yangkyeongmo/mcp-server-apache-airflow"
30
+ Repository = "https://github.com/yangkyeongmo/mcp-server-apache-airflow.git"
31
+ "Bug Tracker" = "https://github.com/yangkyeongmo/mcp-server-apache-airflow/issues"
32
+
33
+ [build-system]
34
+ requires = ["hatchling"]
35
+ build-backend = "hatchling.build"
36
+
37
+ [project.scripts]
38
+ mcp-server-apache-airflow = "server:main"
39
+
40
+ [tool.hatch.build.targets.wheel]
41
+ packages = ["src"]
42
+
43
+ [tool.hatch.build]
44
+ include = [
45
+ "src/**/*.py",
46
+ "README.md",
47
+ "LICENSE",
48
+ ]
File without changes
@@ -0,0 +1,5 @@
1
+ import sys
2
+
3
+ from server import main
4
+
5
+ sys.exit(main())
@@ -0,0 +1,291 @@
1
+ import os
2
+ import httpx
3
+ import mcp.types as types
4
+
5
+ AIRFLOW_HOST = os.getenv("AIRFLOW_HOST").rstrip("/")
6
+ AIRFLOW_USERNAME = os.getenv("AIRFLOW_USERNAME")
7
+ AIRFLOW_PASSWORD = os.getenv("AIRFLOW_PASSWORD")
8
+
9
+ def get_dag_url(dag_id: str) -> str:
10
+ return f"{AIRFLOW_HOST}/dags/{dag_id}/grid"
11
+
12
+ def get_dag_run_url(dag_id: str, dag_run_id: str) -> str:
13
+ return f"{AIRFLOW_HOST}/dags/{dag_id}/grid?dag_run_id={dag_run_id}"
14
+
15
+ def get_task_instance_url(dag_id: str, dag_run_id: str, task_id: str) -> str:
16
+ return f"{AIRFLOW_HOST}/dags/{dag_id}/grid?dag_run_id={dag_run_id}&task_id={task_id}"
17
+
18
+ async def fetch_dags(
19
+ limit: int | None = None,
20
+ offset: int | None = None,
21
+ order_by: str | None = None,
22
+ tags: list[str] | None = None,
23
+ only_active: bool | None = None,
24
+ paused: bool | None = None,
25
+ dag_id_pattern: str | None = None,
26
+ ) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
27
+ path = "/api/v1/dags"
28
+ params = {}
29
+ if limit is not None:
30
+ params["limit"] = limit
31
+ if offset is not None:
32
+ params["offset"] = offset
33
+ if order_by is not None:
34
+ params["order_by"] = order_by
35
+ if tags is not None:
36
+ params["tags"] = tags
37
+ if only_active is not None:
38
+ params["only_active"] = only_active
39
+ if paused is not None:
40
+ params["paused"] = paused
41
+ if dag_id_pattern is not None:
42
+ params["dag_id_pattern"] = dag_id_pattern
43
+
44
+ url = f"{AIRFLOW_HOST}{path}"
45
+ async with httpx.AsyncClient(follow_redirects=True) as client:
46
+ response = await client.get(
47
+ url,
48
+ auth=httpx.BasicAuth(AIRFLOW_USERNAME, AIRFLOW_PASSWORD),
49
+ params=params
50
+ )
51
+ response.raise_for_status()
52
+ data = response.json()
53
+
54
+ # Add UI links to each DAG
55
+ for dag in data.get("dags", []):
56
+ dag["ui_url"] = get_dag_url(dag["dag_id"])
57
+
58
+ return [types.TextContent(type="text", text=response.text)]
59
+
60
+ async def get_dag(dag_id: str) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
61
+ path = f"/api/v1/dags/{dag_id}"
62
+ url = f"{AIRFLOW_HOST}{path}"
63
+ async with httpx.AsyncClient(follow_redirects=True) as client:
64
+ response = await client.get(url, auth=httpx.BasicAuth(AIRFLOW_USERNAME, AIRFLOW_PASSWORD))
65
+ response.raise_for_status()
66
+ data = response.json()
67
+
68
+ # Add UI link to DAG
69
+ data["ui_url"] = get_dag_url(dag_id)
70
+
71
+ return [types.TextContent(type="text", text=response.text)]
72
+
73
+ async def pause_dag(dag_id: str) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
74
+ path = f"/api/v1/dags/{dag_id}"
75
+ url = f"{AIRFLOW_HOST}{path}"
76
+ async with httpx.AsyncClient(follow_redirects=True) as client:
77
+ response = await client.patch(
78
+ url,
79
+ auth=httpx.BasicAuth(AIRFLOW_USERNAME, AIRFLOW_PASSWORD),
80
+ json={"is_paused": True}
81
+ )
82
+ response.raise_for_status()
83
+ return [types.TextContent(type="text", text=response.text)]
84
+
85
+ async def unpause_dag(dag_id: str) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
86
+ path = f"/api/v1/dags/{dag_id}"
87
+ url = f"{AIRFLOW_HOST}{path}"
88
+ async with httpx.AsyncClient(follow_redirects=True) as client:
89
+ response = await client.patch(
90
+ url,
91
+ auth=httpx.BasicAuth(AIRFLOW_USERNAME, AIRFLOW_PASSWORD),
92
+ json={"is_paused": False}
93
+ )
94
+ response.raise_for_status()
95
+ return [types.TextContent(type="text", text=response.text)]
96
+
97
+ async def trigger_dag(dag_id: str) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
98
+ path = f"/api/v1/dags/{dag_id}/dagRuns"
99
+ url = f"{AIRFLOW_HOST}{path}"
100
+ async with httpx.AsyncClient(follow_redirects=True) as client:
101
+ response = await client.post(
102
+ url,
103
+ auth=httpx.BasicAuth(AIRFLOW_USERNAME, AIRFLOW_PASSWORD),
104
+ json={}
105
+ )
106
+ response.raise_for_status()
107
+ return [types.TextContent(type="text", text=response.text)]
108
+
109
+ async def get_dag_runs(
110
+ dag_id: str,
111
+ limit: int | None = None,
112
+ offset: int | None = None,
113
+ execution_date_gte: str | None = None,
114
+ execution_date_lte: str | None = None,
115
+ start_date_gte: str | None = None,
116
+ start_date_lte: str | None = None,
117
+ end_date_gte: str | None = None,
118
+ end_date_lte: str | None = None,
119
+ updated_at_gte: str | None = None,
120
+ updated_at_lte: str | None = None,
121
+ state: list[str] | None = None,
122
+ order_by: str | None = None,
123
+ ) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
124
+ path = f"/api/v1/dags/{dag_id}/dagRuns"
125
+ params = {}
126
+ if limit is not None:
127
+ params["limit"] = limit
128
+ if offset is not None:
129
+ params["offset"] = offset
130
+ if execution_date_gte is not None:
131
+ params["execution_date_gte"] = execution_date_gte
132
+ if execution_date_lte is not None:
133
+ params["execution_date_lte"] = execution_date_lte
134
+ if start_date_gte is not None:
135
+ params["start_date_gte"] = start_date_gte
136
+ if start_date_lte is not None:
137
+ params["start_date_lte"] = start_date_lte
138
+ if end_date_gte is not None:
139
+ params["end_date_gte"] = end_date_gte
140
+ if end_date_lte is not None:
141
+ params["end_date_lte"] = end_date_lte
142
+ if updated_at_gte is not None:
143
+ params["updated_at_gte"] = updated_at_gte
144
+ if updated_at_lte is not None:
145
+ params["updated_at_lte"] = updated_at_lte
146
+ if state is not None:
147
+ params["state"] = state
148
+ if order_by is not None:
149
+ params["order_by"] = order_by
150
+
151
+ url = f"{AIRFLOW_HOST}{path}"
152
+ async with httpx.AsyncClient(follow_redirects=True) as client:
153
+ response = await client.get(
154
+ url,
155
+ auth=httpx.BasicAuth(AIRFLOW_USERNAME, AIRFLOW_PASSWORD),
156
+ params=params
157
+ )
158
+ response.raise_for_status()
159
+ data = response.json()
160
+
161
+ # Add UI links to each DAG run
162
+ for dag_run in data.get("dag_runs", []):
163
+ dag_run["ui_url"] = get_dag_run_url(dag_id, dag_run["dag_run_id"])
164
+
165
+ return [types.TextContent(type="text", text=response.text)]
166
+
167
+ async def get_dag_tasks(dag_id: str) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
168
+ path = f"/api/v1/dags/{dag_id}/tasks"
169
+ url = f"{AIRFLOW_HOST}{path}"
170
+ async with httpx.AsyncClient(follow_redirects=True) as client:
171
+ response = await client.get(url, auth=httpx.BasicAuth(AIRFLOW_USERNAME, AIRFLOW_PASSWORD))
172
+ response.raise_for_status()
173
+ return [types.TextContent(type="text", text=response.text)]
174
+
175
+ async def get_task_instance(dag_id: str, task_id: str, dag_run_id: str) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
176
+ path = f"/api/v1/dags/{dag_id}/dagRuns/{dag_run_id}/taskInstances/{task_id}"
177
+ url = f"{AIRFLOW_HOST}{path}"
178
+ async with httpx.AsyncClient(follow_redirects=True) as client:
179
+ response = await client.get(url, auth=httpx.BasicAuth(AIRFLOW_USERNAME, AIRFLOW_PASSWORD))
180
+ response.raise_for_status()
181
+ return [types.TextContent(type="text", text=response.text)]
182
+
183
+ async def list_task_instances(
184
+ dag_id: str,
185
+ dag_run_id: str,
186
+ execution_date_gte: str | None = None,
187
+ execution_date_lte: str | None = None,
188
+ start_date_gte: str | None = None,
189
+ start_date_lte: str | None = None,
190
+ end_date_gte: str | None = None,
191
+ end_date_lte: str | None = None,
192
+ updated_at_gte: str | None = None,
193
+ updated_at_lte: str | None = None,
194
+ duration_gte: float | None = None,
195
+ duration_lte: float | None = None,
196
+ state: list[str] | None = None,
197
+ pool: list[str] | None = None,
198
+ queue: list[str] | None = None,
199
+ limit: int | None = None,
200
+ offset: int | None = None,
201
+ ) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
202
+ path = f"/api/v1/dags/{dag_id}/dagRuns/{dag_run_id}/taskInstances"
203
+ params = {}
204
+ if execution_date_gte is not None:
205
+ params["execution_date_gte"] = execution_date_gte
206
+ if execution_date_lte is not None:
207
+ params["execution_date_lte"] = execution_date_lte
208
+ if start_date_gte is not None:
209
+ params["start_date_gte"] = start_date_gte
210
+ if start_date_lte is not None:
211
+ params["start_date_lte"] = start_date_lte
212
+ if end_date_gte is not None:
213
+ params["end_date_gte"] = end_date_gte
214
+ if end_date_lte is not None:
215
+ params["end_date_lte"] = end_date_lte
216
+ if updated_at_gte is not None:
217
+ params["updated_at_gte"] = updated_at_gte
218
+ if updated_at_lte is not None:
219
+ params["updated_at_lte"] = updated_at_lte
220
+ if duration_gte is not None:
221
+ params["duration_gte"] = duration_gte
222
+ if duration_lte is not None:
223
+ params["duration_lte"] = duration_lte
224
+ if state is not None:
225
+ params["state"] = state
226
+ if pool is not None:
227
+ params["pool"] = pool
228
+ if queue is not None:
229
+ params["queue"] = queue
230
+ if limit is not None:
231
+ params["limit"] = limit
232
+ if offset is not None:
233
+ params["offset"] = offset
234
+
235
+ url = f"{AIRFLOW_HOST}{path}"
236
+ async with httpx.AsyncClient(follow_redirects=True) as client:
237
+ response = await client.get(
238
+ url,
239
+ auth=httpx.BasicAuth(AIRFLOW_USERNAME, AIRFLOW_PASSWORD),
240
+ params=params
241
+ )
242
+ response.raise_for_status()
243
+ return [types.TextContent(type="text", text=response.text)]
244
+
245
+ async def get_import_error(import_error_id: int) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
246
+ path = f"/api/v1/importErrors/{import_error_id}"
247
+ url = f"{AIRFLOW_HOST}{path}"
248
+ async with httpx.AsyncClient(follow_redirects=True) as client:
249
+ response = await client.get(url, auth=httpx.BasicAuth(AIRFLOW_USERNAME, AIRFLOW_PASSWORD))
250
+ response.raise_for_status()
251
+ return [types.TextContent(type="text", text=response.text)]
252
+
253
+ async def list_import_errors(
254
+ limit: int | None = None,
255
+ offset: int | None = None,
256
+ order_by: str | None = None,
257
+ ) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
258
+ path = "/api/v1/importErrors"
259
+ params = {}
260
+ if limit is not None:
261
+ params["limit"] = limit
262
+ if offset is not None:
263
+ params["offset"] = offset
264
+ if order_by is not None:
265
+ params["order_by"] = order_by
266
+
267
+ url = f"{AIRFLOW_HOST}{path}"
268
+ async with httpx.AsyncClient(follow_redirects=True) as client:
269
+ response = await client.get(
270
+ url,
271
+ auth=httpx.BasicAuth(AIRFLOW_USERNAME, AIRFLOW_PASSWORD),
272
+ params=params
273
+ )
274
+ response.raise_for_status()
275
+ return [types.TextContent(type="text", text=response.text)]
276
+
277
+ async def get_health() -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
278
+ path = "/api/v1/health"
279
+ url = f"{AIRFLOW_HOST}{path}"
280
+ async with httpx.AsyncClient(follow_redirects=True) as client:
281
+ response = await client.get(url, auth=httpx.BasicAuth(AIRFLOW_USERNAME, AIRFLOW_PASSWORD))
282
+ response.raise_for_status()
283
+ return [types.TextContent(type="text", text=response.text)]
284
+
285
+ async def get_version() -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
286
+ path = "/api/v1/version"
287
+ url = f"{AIRFLOW_HOST}{path}"
288
+ async with httpx.AsyncClient(follow_redirects=True) as client:
289
+ response = await client.get(url, auth=httpx.BasicAuth(AIRFLOW_USERNAME, AIRFLOW_PASSWORD))
290
+ response.raise_for_status()
291
+ return [types.TextContent(type="text", text=response.text)]
@@ -0,0 +1,532 @@
1
+ import anyio
2
+ import click
3
+ import mcp.types as types
4
+ from mcp.server.lowlevel import Server
5
+
6
+ import airflow
7
+
8
+ COMMANDS = [
9
+ "list_dags",
10
+ "get_dag",
11
+ "pause_dag",
12
+ "unpause_dag",
13
+ "trigger_dag",
14
+ "get_dag_runs",
15
+ "get_dag_tasks",
16
+ "get_task_instance",
17
+ "list_task_instances",
18
+ "get_import_error",
19
+ "list_import_errors",
20
+ "get_health",
21
+ "get_version",
22
+ ]
23
+
24
+
25
+ @click.command()
26
+ @click.option("--port", default=8000, help="Port to listen on for SSE")
27
+ @click.option(
28
+ "--transport",
29
+ type=click.Choice(["stdio", "sse"]),
30
+ default="stdio",
31
+ help="Transport type",
32
+ )
33
+ def main(port: int, transport: str) -> int:
34
+ app = Server("mcp-website-fetcher")
35
+
36
+ @app.call_tool()
37
+ async def fetch_tool(
38
+ name: str, arguments: dict
39
+ ) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
40
+ if name not in COMMANDS:
41
+ raise ValueError(f"Unknown tool: {name}")
42
+ if name == "list_dags":
43
+ return await airflow.fetch_dags(
44
+ limit=arguments.get("limit"),
45
+ offset=arguments.get("offset"),
46
+ order_by=arguments.get("order_by"),
47
+ tags=arguments.get("tags"),
48
+ only_active=arguments.get("only_active"),
49
+ paused=arguments.get("paused"),
50
+ dag_id_pattern=arguments.get("dag_id_pattern"),
51
+ )
52
+ elif name == "get_dag":
53
+ if "dag_id" not in arguments:
54
+ raise ValueError("Missing required argument 'dag_id'")
55
+ return await airflow.get_dag(arguments["dag_id"])
56
+ elif name == "pause_dag":
57
+ if "dag_id" not in arguments:
58
+ raise ValueError("Missing required argument 'dag_id'")
59
+ return await airflow.pause_dag(arguments["dag_id"])
60
+ elif name == "unpause_dag":
61
+ if "dag_id" not in arguments:
62
+ raise ValueError("Missing required argument 'dag_id'")
63
+ return await airflow.unpause_dag(arguments["dag_id"])
64
+ elif name == "trigger_dag":
65
+ if "dag_id" not in arguments:
66
+ raise ValueError("Missing required argument 'dag_id'")
67
+ return await airflow.trigger_dag(arguments["dag_id"])
68
+ elif name == "get_dag_runs":
69
+ if "dag_id" not in arguments:
70
+ raise ValueError("Missing required argument 'dag_id'")
71
+ return await airflow.get_dag_runs(
72
+ dag_id=arguments["dag_id"],
73
+ limit=arguments.get("limit"),
74
+ offset=arguments.get("offset"),
75
+ execution_date_gte=arguments.get("execution_date_gte"),
76
+ execution_date_lte=arguments.get("execution_date_lte"),
77
+ start_date_gte=arguments.get("start_date_gte"),
78
+ start_date_lte=arguments.get("start_date_lte"),
79
+ end_date_gte=arguments.get("end_date_gte"),
80
+ end_date_lte=arguments.get("end_date_lte"),
81
+ updated_at_gte=arguments.get("updated_at_gte"),
82
+ updated_at_lte=arguments.get("updated_at_lte"),
83
+ state=arguments.get("state"),
84
+ order_by=arguments.get("order_by"),
85
+ )
86
+ elif name == "get_dag_tasks":
87
+ if "dag_id" not in arguments:
88
+ raise ValueError("Missing required argument 'dag_id'")
89
+ return await airflow.get_dag_tasks(arguments["dag_id"])
90
+ elif name == "get_task_instance":
91
+ if "dag_id" not in arguments or "task_id" not in arguments or "dag_run_id" not in arguments:
92
+ raise ValueError("Missing required arguments 'dag_id', 'task_id', or 'dag_run_id'")
93
+ return await airflow.get_task_instance(arguments["dag_id"], arguments["task_id"], arguments["dag_run_id"])
94
+ elif name == "list_task_instances":
95
+ if "dag_id" not in arguments or "dag_run_id" not in arguments:
96
+ raise ValueError("Missing required arguments 'dag_id' or 'dag_run_id'")
97
+ return await airflow.list_task_instances(
98
+ dag_id=arguments["dag_id"],
99
+ dag_run_id=arguments["dag_run_id"],
100
+ execution_date_gte=arguments.get("execution_date_gte"),
101
+ execution_date_lte=arguments.get("execution_date_lte"),
102
+ start_date_gte=arguments.get("start_date_gte"),
103
+ start_date_lte=arguments.get("start_date_lte"),
104
+ end_date_gte=arguments.get("end_date_gte"),
105
+ end_date_lte=arguments.get("end_date_lte"),
106
+ updated_at_gte=arguments.get("updated_at_gte"),
107
+ updated_at_lte=arguments.get("updated_at_lte"),
108
+ duration_gte=arguments.get("duration_gte"),
109
+ duration_lte=arguments.get("duration_lte"),
110
+ state=arguments.get("state"),
111
+ pool=arguments.get("pool"),
112
+ queue=arguments.get("queue"),
113
+ limit=arguments.get("limit"),
114
+ offset=arguments.get("offset"),
115
+ )
116
+ elif name == "get_import_error":
117
+ if "import_error_id" not in arguments:
118
+ raise ValueError("Missing required argument 'import_error_id'")
119
+ return await airflow.get_import_error(int(arguments["import_error_id"]))
120
+ elif name == "list_import_errors":
121
+ return await airflow.list_import_errors(
122
+ limit=arguments.get("limit"),
123
+ offset=arguments.get("offset"),
124
+ order_by=arguments.get("order_by"),
125
+ )
126
+ elif name == "get_health":
127
+ return await airflow.get_health()
128
+ elif name == "get_version":
129
+ return await airflow.get_version()
130
+
131
+ @app.list_tools()
132
+ async def list_tools() -> list[types.Tool]:
133
+ return [
134
+ types.Tool(
135
+ name="list_dags",
136
+ description="Lists all DAGs in the Airflow instance",
137
+ inputSchema={
138
+ "type": "object",
139
+ "properties": {
140
+ "limit": {
141
+ "type": "integer",
142
+ "description": "The numbers of items to return (default: 100)",
143
+ "minimum": 1
144
+ },
145
+ "offset": {
146
+ "type": "integer",
147
+ "description": "The number of items to skip before starting to collect the result set",
148
+ "minimum": 0
149
+ },
150
+ "order_by": {
151
+ "type": "string",
152
+ "description": "The name of the field to order the results by. Prefix with - to reverse sort order"
153
+ },
154
+ "tags": {
155
+ "type": "array",
156
+ "items": {
157
+ "type": "string"
158
+ },
159
+ "description": "List of tags to filter results"
160
+ },
161
+ "only_active": {
162
+ "type": "boolean",
163
+ "description": "Only filter active DAGs (default: true)"
164
+ },
165
+ "paused": {
166
+ "type": "boolean",
167
+ "description": "Only filter paused/unpaused DAGs. If absent, returns both"
168
+ },
169
+ "dag_id_pattern": {
170
+ "type": "string",
171
+ "description": "If set, only return DAGs with dag_ids matching this pattern"
172
+ }
173
+ }
174
+ },
175
+ ),
176
+ types.Tool(
177
+ name="get_dag",
178
+ description="Get details of a specific DAG",
179
+ inputSchema={
180
+ "type": "object",
181
+ "required": ["dag_id"],
182
+ "properties": {
183
+ "dag_id": {
184
+ "type": "string",
185
+ "description": "The ID of the DAG to retrieve",
186
+ }
187
+ },
188
+ },
189
+ ),
190
+ types.Tool(
191
+ name="pause_dag",
192
+ description="Pause a DAG",
193
+ inputSchema={
194
+ "type": "object",
195
+ "required": ["dag_id"],
196
+ "properties": {
197
+ "dag_id": {
198
+ "type": "string",
199
+ "description": "The ID of the DAG to pause",
200
+ }
201
+ },
202
+ },
203
+ ),
204
+ types.Tool(
205
+ name="unpause_dag",
206
+ description="Unpause a DAG",
207
+ inputSchema={
208
+ "type": "object",
209
+ "required": ["dag_id"],
210
+ "properties": {
211
+ "dag_id": {
212
+ "type": "string",
213
+ "description": "The ID of the DAG to unpause",
214
+ }
215
+ },
216
+ },
217
+ ),
218
+ types.Tool(
219
+ name="trigger_dag",
220
+ description="Trigger a DAG run",
221
+ inputSchema={
222
+ "type": "object",
223
+ "required": ["dag_id"],
224
+ "properties": {
225
+ "dag_id": {
226
+ "type": "string",
227
+ "description": "The ID of the DAG to trigger",
228
+ }
229
+ },
230
+ },
231
+ ),
232
+ types.Tool(
233
+ name="get_dag_runs",
234
+ description="Get DAG runs for a specific DAG",
235
+ inputSchema={
236
+ "type": "object",
237
+ "required": ["dag_id"],
238
+ "properties": {
239
+ "dag_id": {
240
+ "type": "string",
241
+ "description": "The ID of the DAG to retrieve DAG runs for",
242
+ },
243
+ "limit": {
244
+ "type": "integer",
245
+ "description": "The numbers of items to return (default: 100)",
246
+ "minimum": 1
247
+ },
248
+ "offset": {
249
+ "type": "integer",
250
+ "description": "The number of items to skip before starting to collect the result set",
251
+ "minimum": 0
252
+ },
253
+ "execution_date_gte": {
254
+ "type": "string",
255
+ "format": "date-time",
256
+ "description": "Returns objects greater or equal to the specified date"
257
+ },
258
+ "execution_date_lte": {
259
+ "type": "string",
260
+ "format": "date-time",
261
+ "description": "Returns objects less than or equal to the specified date"
262
+ },
263
+ "start_date_gte": {
264
+ "type": "string",
265
+ "format": "date-time",
266
+ "description": "Returns objects greater or equal the specified date"
267
+ },
268
+ "start_date_lte": {
269
+ "type": "string",
270
+ "format": "date-time",
271
+ "description": "Returns objects less or equal the specified date"
272
+ },
273
+ "end_date_gte": {
274
+ "type": "string",
275
+ "format": "date-time",
276
+ "description": "Returns objects greater or equal the specified date"
277
+ },
278
+ "end_date_lte": {
279
+ "type": "string",
280
+ "format": "date-time",
281
+ "description": "Returns objects less than or equal to the specified date"
282
+ },
283
+ "updated_at_gte": {
284
+ "type": "string",
285
+ "format": "date-time",
286
+ "description": "Returns objects greater or equal the specified date"
287
+ },
288
+ "updated_at_lte": {
289
+ "type": "string",
290
+ "format": "date-time",
291
+ "description": "Returns objects less or equal the specified date"
292
+ },
293
+ "state": {
294
+ "type": "array",
295
+ "items": {
296
+ "type": "string"
297
+ },
298
+ "description": "The value can be repeated to retrieve multiple matching values (OR condition)"
299
+ },
300
+ "order_by": {
301
+ "type": "string",
302
+ "description": "The name of the field to order the results by. Prefix with - to reverse sort order"
303
+ }
304
+ }
305
+ },
306
+ ),
307
+ types.Tool(
308
+ name="get_dag_tasks",
309
+ description="Get tasks for a specific DAG",
310
+ inputSchema={
311
+ "type": "object",
312
+ "required": ["dag_id"],
313
+ "properties": {
314
+ "dag_id": {
315
+ "type": "string",
316
+ "description": "The ID of the DAG to retrieve tasks for",
317
+ }
318
+ },
319
+ },
320
+ ),
321
+ types.Tool(
322
+ name="get_task_instance",
323
+ description="Get details of a specific task instance",
324
+ inputSchema={
325
+ "type": "object",
326
+ "required": ["dag_id", "task_id", "dag_run_id"],
327
+ "properties": {
328
+ "dag_id": {
329
+ "type": "string",
330
+ "description": "The ID of the DAG",
331
+ },
332
+ "task_id": {
333
+ "type": "string",
334
+ "description": "The ID of the task",
335
+ },
336
+ "dag_run_id": {
337
+ "type": "string",
338
+ "description": "The ID of the DAG run",
339
+ }
340
+ },
341
+ },
342
+ ),
343
+ types.Tool(
344
+ name="list_task_instances",
345
+ description="List all task instances for a specific DAG run",
346
+ inputSchema={
347
+ "type": "object",
348
+ "required": ["dag_id", "dag_run_id"],
349
+ "properties": {
350
+ "dag_id": {
351
+ "type": "string",
352
+ "description": "The ID of the DAG",
353
+ },
354
+ "dag_run_id": {
355
+ "type": "string",
356
+ "description": "The ID of the DAG run",
357
+ },
358
+ "execution_date_gte": {
359
+ "type": "string",
360
+ "format": "date-time",
361
+ "description": "Returns objects greater or equal to the specified date"
362
+ },
363
+ "execution_date_lte": {
364
+ "type": "string",
365
+ "format": "date-time",
366
+ "description": "Returns objects less than or equal to the specified date"
367
+ },
368
+ "start_date_gte": {
369
+ "type": "string",
370
+ "format": "date-time",
371
+ "description": "Returns objects greater or equal the specified date"
372
+ },
373
+ "start_date_lte": {
374
+ "type": "string",
375
+ "format": "date-time",
376
+ "description": "Returns objects less or equal the specified date"
377
+ },
378
+ "end_date_gte": {
379
+ "type": "string",
380
+ "format": "date-time",
381
+ "description": "Returns objects greater or equal the specified date"
382
+ },
383
+ "end_date_lte": {
384
+ "type": "string",
385
+ "format": "date-time",
386
+ "description": "Returns objects less than or equal to the specified date"
387
+ },
388
+ "updated_at_gte": {
389
+ "type": "string",
390
+ "format": "date-time",
391
+ "description": "Returns objects greater or equal the specified date"
392
+ },
393
+ "updated_at_lte": {
394
+ "type": "string",
395
+ "format": "date-time",
396
+ "description": "Returns objects less or equal the specified date"
397
+ },
398
+ "duration_gte": {
399
+ "type": "number",
400
+ "description": "Returns objects greater than or equal to the specified values"
401
+ },
402
+ "duration_lte": {
403
+ "type": "number",
404
+ "description": "Returns objects less than or equal to the specified values"
405
+ },
406
+ "state": {
407
+ "type": "array",
408
+ "items": {
409
+ "type": "string"
410
+ },
411
+ "description": "States of the task instance. The value can be repeated to retrieve multiple matching values (OR condition)"
412
+ },
413
+ "pool": {
414
+ "type": "array",
415
+ "items": {
416
+ "type": "string"
417
+ },
418
+ "description": "The value can be repeated to retrieve multiple matching values (OR condition)"
419
+ },
420
+ "queue": {
421
+ "type": "array",
422
+ "items": {
423
+ "type": "string"
424
+ },
425
+ "description": "The value can be repeated to retrieve multiple matching values (OR condition)"
426
+ },
427
+ "limit": {
428
+ "type": "integer",
429
+ "description": "The numbers of items to return (default: 100)",
430
+ "minimum": 1
431
+ },
432
+ "offset": {
433
+ "type": "integer",
434
+ "description": "The number of items to skip before starting to collect the result set",
435
+ "minimum": 0
436
+ }
437
+ }
438
+ },
439
+ ),
440
+ types.Tool(
441
+ name="get_import_error",
442
+ description="Get details of a specific import error",
443
+ inputSchema={
444
+ "type": "object",
445
+ "required": ["import_error_id"],
446
+ "properties": {
447
+ "import_error_id": {
448
+ "type": "integer",
449
+ "description": "The ID of the import error to retrieve",
450
+ }
451
+ },
452
+ },
453
+ ),
454
+ types.Tool(
455
+ name="list_import_errors",
456
+ description="List all import errors",
457
+ inputSchema={
458
+ "type": "object",
459
+ "properties": {
460
+ "limit": {
461
+ "type": "integer",
462
+ "description": "The numbers of items to return (default: 100)",
463
+ "minimum": 1
464
+ },
465
+ "offset": {
466
+ "type": "integer",
467
+ "description": "The number of items to skip before starting to collect the result set",
468
+ "minimum": 0
469
+ },
470
+ "order_by": {
471
+ "type": "string",
472
+ "description": "The name of the field to order the results by. Prefix with - to reverse sort order"
473
+ }
474
+ }
475
+ },
476
+ ),
477
+ types.Tool(
478
+ name="get_health",
479
+ description="Get the health status of the Airflow instance",
480
+ inputSchema={
481
+ "type": "object",
482
+ "properties": {}
483
+ },
484
+ ),
485
+ types.Tool(
486
+ name="get_version",
487
+ description="Get the version information of the Airflow instance",
488
+ inputSchema={
489
+ "type": "object",
490
+ "properties": {}
491
+ },
492
+ ),
493
+ ]
494
+
495
+ if transport == "sse":
496
+ from mcp.server.sse import SseServerTransport
497
+ from starlette.applications import Starlette
498
+ from starlette.routing import Mount, Route
499
+
500
+ sse = SseServerTransport("/messages/")
501
+
502
+ async def handle_sse(request):
503
+ async with sse.connect_sse(
504
+ request.scope, request.receive, request._send
505
+ ) as streams:
506
+ await app.run(
507
+ streams[0], streams[1], app.create_initialization_options()
508
+ )
509
+
510
+ starlette_app = Starlette(
511
+ debug=True,
512
+ routes=[
513
+ Route("/sse", endpoint=handle_sse),
514
+ Mount("/messages/", app=sse.handle_post_message),
515
+ ],
516
+ )
517
+
518
+ import uvicorn
519
+
520
+ uvicorn.run(starlette_app, host="0.0.0.0", port=port)
521
+ else:
522
+ from mcp.server.stdio import stdio_server
523
+
524
+ async def arun():
525
+ async with stdio_server() as streams:
526
+ await app.run(
527
+ streams[0], streams[1], app.create_initialization_options()
528
+ )
529
+
530
+ anyio.run(arun)
531
+
532
+ return 0