|
2 | 2 |
|
3 | 3 | r"""***PyAirbyte MCP Server - Model Context Protocol Integration*** |
4 | 4 |
|
| 5 | +> **NOTE:** |
| 6 | +> This MCP server implementation is experimental and may change without notice between minor |
| 7 | +> versions of PyAirbyte. The API may be modified or entirely refactored in future versions. |
| 8 | +
|
5 | 9 | The PyAirbyte MCP (Model Context Protocol) server provides a standardized interface for |
6 | 10 | managing Airbyte connectors through MCP-compatible clients. This experimental feature |
7 | 11 | allows you to list connectors, validate configurations, and run sync operations using |
8 | 12 | the MCP protocol. |
9 | 13 |
|
10 | | -The Model Context Protocol (MCP) is an open standard that enables AI assistants and |
11 | | -other tools to securely connect to data sources, tools, and services. PyAirbyte's MCP |
12 | | -server implementation allows you to build and interact with Airbyte connectors through |
13 | | -this standardized protocol. |
| 14 | +## Getting Started with PyAirbyte MCP |
14 | 15 |
|
15 | | -Create a JSON configuration file to register the PyAirbyte MCP server with your MCP |
16 | | -client. Create a file named `server_config.json`: |
| 16 | +To get started with the PyAirbyte MCP server, follow these steps: |
17 | 17 |
|
18 | | -> **NOTE:** |
19 | | -> This MCP server implementation is experimental and may change without notice between minor |
20 | | -> versions of PyAirbyte. The API may be modified or entirely refactored in future versions. |
| 18 | +1. Create a Dotenv secrets file. |
| 19 | +2. Register the MCP server with your MCP client. |
| 20 | +3. Test the MCP server connection using your MCP client. |
| 21 | +
|
| 22 | +### Step 1: Generate a Dotenv Secrets File |
| 23 | +
|
| 24 | +To get started with the PyAirbyte MCP server, you will need to create a dotenv |
| 25 | +file containing your Airbyte Cloud credentials, as well as credentials for any |
| 26 | +third-party services you wish to connect to via Airbyte. |
| 27 | +
|
| 28 | +Create a file named `~/.mcp/airbyte_mcp.env` with the following content: |
| 29 | +
|
| 30 | +```ini |
| 31 | +# Airbyte Project Artifacts Directory |
| 32 | +AIRBYTE_PROJECT_DIR=/path/to/any/writeable/project-dir |
21 | 33 |
|
22 | | -# MCP Server Configuration |
| 34 | +# Airbyte Cloud Credentials (Required for Airbyte Cloud Operations) |
| 35 | +AIRBYTE_CLOUD_CLIENT_ID=your_api_key |
| 36 | +AIRBYTE_CLOUD_CLIENT_SECRET=your_api_secret |
| 37 | +AIRBYTE_CLOUD_WORKSPACE_ID=your_workspace_id |
23 | 38 |
|
24 | | -Assuming `uv` is installed, you can use the following configuration: |
| 39 | +# API-Specific Credentials (Optional, depending on your connectors) |
| 40 | +
|
| 41 | +# For example, for a PostgreSQL source connector: |
| 42 | +# POSTGRES_HOST=your_postgres_host |
| 43 | +# POSTGRES_PORT=5432 |
| 44 | +# POSTGRES_DB=your_database_name |
| 45 | +# POSTGRES_USER=your_database_user |
| 46 | +# POSTGRES_PASSWORD=your_database_password |
| 47 | +
|
| 48 | +# For example, for a Stripe source connector: |
| 49 | +# STRIPE_API_KEY=your_stripe_api_key |
| 50 | +# STRIPE_API_SECRET=your_stripe_api_secret |
| 51 | +# STRIPE_WEBHOOK_SECRET=your_stripe_webhook_secret |
| 52 | +``` |
| 53 | +
|
| 54 | +Note: |
| 55 | +1. You can add more environment variables to this file as needed for different connectors. To start, |
| 56 | + you only need to create the file and pass it to the MCP server. |
| 57 | +2. Ensure that this file is kept secure, as it contains sensitive information. Your LLM |
| 58 | + *should never* be given direct access to this file or its contents. |
| 59 | +3. The MCP tools will give your LLM the ability to view *which* variables are available, but it |
| 60 | + does not give access to their values. |
| 61 | +4. The `AIRBYTE_PROJECT_DIR` variable specifies a directory where the MCP server can |
| 62 | + store temporary project files. Ensure this directory is writable by the user running |
| 63 | + the MCP server. |
| 64 | +
|
| 65 | +### Step 2: Registering the MCP Server |
| 66 | +
|
| 67 | +First install `uv` (`brew install uv`). |
| 68 | +
|
| 69 | +Then, create a file named `server_config.json` (or the file name required by your MCP client) |
| 70 | +with the following content: |
25 | 71 |
|
26 | 72 | ```json |
27 | 73 | { |
|
30 | 76 | "command": "uvx", |
31 | 77 | "args": ["--from=airbyte", "airbyte-mcp"], |
32 | 78 | "env": { |
33 | | - "AIRBYTE_MCP_ENV_FILE": "~/.mcp/airbyte_mcp.env" |
| 79 | + "AIRBYTE_MCP_ENV_FILE": "/path/to/my/.mcp/airbyte_mcp.env" |
34 | 80 | } |
35 | 81 | } |
36 | 82 | } |
|
47 | 93 | "command": "airbyte-mcp", |
48 | 94 | "args": [], |
49 | 95 | "env": { |
50 | | - "AIRBYTE_MCP_ENV_FILE": "~/.mcp/airbyte_mcp.env" |
| 96 | + "AIRBYTE_MCP_ENV_FILE": "/path/to/my/.mcp/airbyte_mcp.env" |
51 | 97 | } |
52 | 98 | } |
53 | 99 | } |
54 | 100 | } |
55 | 101 | ``` |
56 | 102 |
|
57 | | -## Testing the MCP Server |
58 | | -
|
59 | | -
|
60 | | -The easiest way to test PyAirbyte MCP tools during development is using the built-in Poe tasks. |
61 | | -These tasks automatically inherit environment variables from your shell session: |
62 | | -
|
63 | | -```bash |
64 | | -poe mcp-tool-test <tool_name> '<json_args>' |
65 | | -
|
66 | | -poe mcp-tool-test list_connectors '{}' |
67 | | -poe mcp-tool-test get_config_spec '{"connector_name": "source-pokeapi"}' |
68 | | -poe mcp-tool-test validate_config \ |
69 | | - '{"connector_name": "source-pokeapi", "config": {"pokemon_name": "pikachu"}}' |
70 | | -poe mcp-tool-test run_sync \ |
71 | | - '{"connector_name": "source-pokeapi", "config": {"pokemon_name": "pikachu"}}' |
72 | | -
|
73 | | -poe mcp-tool-test check_airbyte_cloud_workspace '{}' |
74 | | -poe mcp-tool-test list_deployed_cloud_connections '{}' |
75 | | -``` |
76 | | -
|
77 | | -
|
78 | | -```bash |
79 | | -poe mcp-serve-local # STDIO transport (default) |
80 | | -poe mcp-serve-http # HTTP transport on localhost:8000 |
81 | | -poe mcp-serve-sse # Server-Sent Events transport on localhost:8000 |
82 | | -
|
83 | | -poe mcp-inspect # Show all available MCP tools and their schemas |
84 | | -``` |
| 103 | +Note: |
| 104 | +- Replace `/path/to/my/.mcp/airbyte_mcp.env` with the absolute path to your dotenv file created in |
| 105 | + Step 1. |
85 | 106 |
|
| 107 | +### Step 3: Testing the MCP Server Connection |
86 | 108 |
|
| 109 | +You can test the MCP server connection using your MCP client. |
87 | 110 |
|
88 | | -## Contributing to PyAirbyte and the Airbyte MCP Server |
| 111 | +Helpful prompts to try: |
89 | 112 |
|
90 | | -The Airbyte MCP server is part of the PyAirbyte project. Contributions are welcome! |
| 113 | +1. "Use your MCP tools to list all available Airbyte connectors." |
| 114 | +2. "Use your MCP tools to get information about the Airbyte Stripe connector." |
| 115 | +3. "Use your MCP tools to list all variables you have access to in the dotenv secrets |
| 116 | + file." |
| 117 | +4. "Use your MCP tools to check your connection to your Airbyte Cloud workspace." |
| 118 | +5. "Use your MCP tools to list all available destinations in my Airbyte Cloud workspace." |
91 | 119 |
|
92 | | -You can contribute to the MCP server by adding new tools, improving existing functionality, or |
93 | | -fixing bugs. The server is built using the FastMCP framework, which provides a flexible |
94 | | -interface for defining tools and handling requests. |
| 120 | +## Contributing to the Airbyte MCP Server |
95 | 121 |
|
96 | | -As a starting point, you can clone the repo and inspect the server definition using the `fastmcp` |
97 | | -CLI tool: |
98 | | -
|
99 | | -```bash |
100 | | -poetry install --all-extras |
101 | | -poetry run fastmcp inspect airbyte/mcp/server.py:app |
102 | | -``` |
103 | | -
|
104 | | -In your MCP config, you can test your development updates using `poetry` as the entrypoint: |
105 | | -
|
106 | | -```json |
107 | | -{ |
108 | | - "mcpServers": { |
109 | | - "airbyte": { |
110 | | - "command": "poetry", |
111 | | - "args": [ |
112 | | - "--directory=~/repos/PyAirbyte", |
113 | | - "run", |
114 | | - "airbyte-mcp" |
115 | | - ], |
116 | | - "env": { |
117 | | - "AIRBYTE_MCP_ENV_FILE": "~/.mcp/airbyte_mcp.env" |
118 | | - } |
119 | | - } |
120 | | - } |
121 | | -} |
122 | | -``` |
| 122 | +- [PyAirbyte Contributing Guide](https://github.com/airbytehq/PyAirbyte/blob/main/docs/CONTRIBUTING.md) |
123 | 123 |
|
124 | 124 | ### Additional resources |
125 | 125 |
|
126 | 126 | - [Model Context Protocol Documentation](https://modelcontextprotocol.io/) |
127 | 127 | - [MCP Python SDK](https://github.com/modelcontextprotocol/python-sdk) |
128 | 128 |
|
129 | 129 | For issues and questions: |
130 | | -- [PyAirbyte Contributing Guide](https://github.com/airbytehq/PyAirbyte/blob/main/docs/CONTRIBUTING.md) |
131 | 130 | - [PyAirbyte GitHub Issues](https://github.com/airbytehq/pyairbyte/issues) |
132 | 131 | - [PyAirbyte Discussions](https://github.com/airbytehq/pyairbyte/discussions) |
133 | 132 |
|
134 | 133 | """ # noqa: D415 |
135 | 134 |
|
136 | | -from airbyte.mcp import server |
| 135 | +from airbyte.mcp import cloud_ops, connector_registry, local_ops, server |
137 | 136 |
|
138 | 137 |
|
139 | | -__all__: list[str] = ["server"] |
| 138 | +__all__: list[str] = [ |
| 139 | + "cloud_ops", |
| 140 | + "connector_registry", |
| 141 | + "local_ops", |
| 142 | + "server", |
| 143 | +] |
140 | 144 |
|
141 | 145 | __docformat__ = "google" |
0 commit comments