|
1 |
| -# MXCP Jira Plugin Example |
| 1 | +# MXCP Jira Python Endpoints Example |
2 | 2 |
|
3 |
| -This example demonstrates how to use MXCP with Jira data. It shows how to: |
4 |
| -- Create and use a custom MXCP plugin for Jira integration |
5 |
| -- Query Jira data using SQL |
6 |
| -- Combine Jira data with other data sources |
| 3 | +This example demonstrates how to use MXCP with Jira data using **plain Python endpoints** instead of plugins. This approach is simpler, more direct, and easier to debug than the plugin-based approach. |
7 | 4 |
|
8 | 5 | ## Overview
|
9 | 6 |
|
10 |
| -The plugin provides several UDFs that allow you to: |
| 7 | +This example provides Python MCP endpoints that allow you to: |
11 | 8 | - Execute JQL queries to search issues
|
| 9 | +- Get detailed information for specific issues |
12 | 10 | - Get user information
|
13 | 11 | - List projects and their details
|
14 | 12 | - Get project metadata
|
15 | 13 |
|
| 14 | +## Key Differences from Plugin Approach |
| 15 | + |
| 16 | +- **No custom plugins required** - just plain Python functions |
| 17 | +- **Direct MCP tool calls** - no SQL wrapper layer needed |
| 18 | +- **Simpler configuration** - no plugin registration required |
| 19 | +- **Easier debugging** - standard Python debugging works naturally |
| 20 | +- **More flexible** - can return any JSON-serializable data |
| 21 | + |
16 | 22 | ## Configuration
|
17 | 23 |
|
18 | 24 | ### 1. Creating an Atlassian API Token
|
19 | 25 |
|
20 |
| -**Important:** This plugin currently only supports API tokens **without scopes**. While Atlassian has introduced scoped API tokens, there are known compatibility issues when using scoped tokens with basic authentication that this plugin relies on. |
21 |
| - |
22 |
| -To create an API token without scopes: |
| 26 | +Follow the same process as the plugin example: |
23 | 27 |
|
24 | 28 | 1. **Log in to your Atlassian account** at [https://id.atlassian.com/manage-profile/security/api-tokens](https://id.atlassian.com/manage-profile/security/api-tokens)
|
25 | 29 |
|
26 |
| -2. **Verify your identity** (if prompted): |
27 |
| - - Atlassian may ask you to verify your identity before creating API tokens |
28 |
| - - Check your email for a one-time passcode and enter it when prompted |
29 |
| - |
30 |
| -3. **Create the API token**: |
| 30 | +2. **Create the API token**: |
31 | 31 | - Click **"Create API token"** (not "Create API token with scopes")
|
32 |
| - - Enter a descriptive name for your token (e.g., "MXCP Jira Integration") |
33 |
| - - Select an expiration date (tokens can last from 1 day to 1 year) |
| 32 | + - Enter a descriptive name for your token (e.g., "MXCP Jira Python Integration") |
| 33 | + - Select an expiration date |
34 | 34 | - Click **"Create"**
|
35 | 35 |
|
36 |
| -4. **Copy and save your token**: |
37 |
| - - Click **"Copy to clipboard"** to copy the token |
38 |
| - - **Important:** Save this token securely (like in a password manager) as you won't be able to view it again |
39 |
| - - This token will be used as your "password" in the configuration below |
| 36 | +3. **Copy and save your token** securely |
40 | 37 |
|
41 | 38 | ### 2. User Configuration
|
42 | 39 |
|
43 |
| -Add the following to your MXCP user config (`~/.mxcp/config.yml`). You can use the example `config.yml` in this directory as a template: |
| 40 | +Add the following to your MXCP user config (`~/.mxcp/config.yml`): |
44 | 41 |
|
45 | 42 | ```yaml
|
46 | 43 | mxcp: 1
|
47 | 44 |
|
48 | 45 | projects:
|
49 |
| - jira-demo: |
| 46 | + jira-python-demo: |
50 | 47 | profiles:
|
51 |
| - dev: |
52 |
| - plugin: |
53 |
| - config: |
54 |
| - jira: |
| 48 | + default: |
| 49 | + secrets: |
| 50 | + # JIRA credentials - using "python" type to demonstrate behavior |
| 51 | + - name: "jira" |
| 52 | + type: "python" # This will cause DuckDB injection to fail (but continue gracefully) |
| 53 | + parameters: |
55 | 54 | url: "https://your-domain.atlassian.net"
|
56 | 55 | username: "your-email@example.com"
|
57 | 56 | password: "your-api-token" # Use the API token you created above
|
58 | 57 | ```
|
59 | 58 |
|
60 |
| -**Configuration Notes:** |
61 |
| -- Replace `your-domain` with your actual Atlassian domain |
62 |
| -- Replace `your-email@example.com` with the email address of your Atlassian account |
63 |
| -- Replace `your-api-token` with the API token you created in step 1 |
64 |
| -- The `password` field should contain your API token, not your actual Atlassian password |
| 59 | +### Experimental Setup: DuckDB Secret Injection |
| 60 | +
|
| 61 | +This example is set up to demonstrate what happens when: |
| 62 | +1. **Secret is required** - Listed in `mxcp-site.yml`'s `secrets` array |
| 63 | +2. **Invalid DuckDB type** - Using `type: "python"` which DuckDB doesn't understand |
| 64 | +
|
| 65 | +**Expected behavior:** |
| 66 | +- DuckDB injection will fail during startup (logged as debug message) |
| 67 | +- Python endpoints will still work perfectly via `config.get_secret()` |
| 68 | +- Server will continue running normally |
| 69 | + |
| 70 | +This shows MXCP's graceful handling of unsupported secret types! |
65 | 71 |
|
66 |
| -### 2. Site Configuration |
| 72 | +### 3. Site Configuration |
67 | 73 |
|
68 | 74 | Create an `mxcp-site.yml` file:
|
69 | 75 |
|
70 | 76 | ```yaml
|
71 | 77 | mxcp: 1
|
72 |
| -project: jira-demo |
73 |
| -profile: dev |
74 |
| -plugin: |
75 |
| - - name: jira |
76 |
| - module: mxcp_plugin_jira |
77 |
| - config: jira |
| 78 | +project: jira-python-demo |
| 79 | +profile: default |
| 80 | +secrets: |
| 81 | + - jira # This forces the secret to be injected into DuckDB |
78 | 82 | ```
|
79 | 83 |
|
| 84 | +Note: We're listing the JIRA secret as required to demonstrate DuckDB injection behavior. |
| 85 | + |
80 | 86 | ## Available Tools
|
81 | 87 |
|
82 | 88 | ### JQL Query
|
83 |
| -```sql |
84 |
| --- Execute a JQL query to search issues |
85 |
| -SELECT jql_query_jira($jql, $limit) as result; |
| 89 | +Execute JQL queries directly as Python function calls: |
| 90 | +```bash |
| 91 | +mxcp run tool jql_query --param query="project = TEST" --param limit=10 |
| 92 | +``` |
| 93 | + |
| 94 | +### Get Issue |
| 95 | +Get detailed information for a specific issue by its key: |
| 96 | +```bash |
| 97 | +mxcp run tool get_issue --param issue_key="RD-123" |
86 | 98 | ```
|
87 | 99 |
|
88 | 100 | ### Get User
|
89 |
| -```sql |
90 |
| --- Get user information |
91 |
| -SELECT get_user_jira($username) as result; |
| 101 | +Get a specific user by their account ID: |
| 102 | +```bash |
| 103 | +mxcp run tool get_user --param account_id="557058:ab168c94-8485-405c-88e6-6458375eb30b" |
| 104 | +``` |
| 105 | + |
| 106 | +### Search Users |
| 107 | +Search for users by name, email, or other criteria: |
| 108 | +```bash |
| 109 | +mxcp run tool search_user --param query="john.doe@example.com" |
92 | 110 | ```
|
93 | 111 |
|
94 | 112 | ### List Projects
|
95 |
| -```sql |
96 |
| --- List all projects |
97 |
| -SELECT list_projects_jira($project_name) as result; |
| 113 | +List all projects: |
| 114 | +```bash |
| 115 | +mxcp run tool list_projects |
98 | 116 | ```
|
99 | 117 |
|
100 | 118 | ### Get Project
|
101 |
| -```sql |
102 |
| --- Get project details |
103 |
| -SELECT get_project_jira($project_key) as result; |
| 119 | +Get project details: |
| 120 | +```bash |
| 121 | +mxcp run tool get_project --param project_key="TEST" |
104 | 122 | ```
|
105 | 123 |
|
106 |
| -## Example Queries |
107 |
| - |
108 |
| -1. Query issues with their assignees: |
109 |
| -```sql |
110 |
| -WITH issues AS ( |
111 |
| - SELECT * FROM jql_query_jira('project = "PROJ" ORDER BY created DESC', 100) |
112 |
| -) |
113 |
| -SELECT |
114 |
| - i.key as issue_key, |
115 |
| - i.fields.summary as summary, |
116 |
| - i.fields.assignee.displayName as assignee |
117 |
| -FROM issues i; |
| 124 | +### Get Project Roles |
| 125 | +Get all roles available in a project: |
| 126 | +```bash |
| 127 | +mxcp run tool get_project_roles --param project_key="TEST" |
118 | 128 | ```
|
119 | 129 |
|
120 |
| -## Plugin Development |
121 |
| - |
122 |
| -The `mxcp_plugin_jira` directory contains a complete MXCP plugin implementation that you can use as a reference for creating your own plugins. It demonstrates: |
| 130 | +### Get Project Role Users |
| 131 | +Get users and groups for a specific role in a project: |
| 132 | +```bash |
| 133 | +mxcp run tool get_project_role_users --param project_key="TEST" --param role_name="Developers" |
| 134 | +``` |
123 | 135 |
|
124 |
| -- Plugin class structure |
125 |
| -- Type conversion |
126 |
| -- UDF implementation |
127 |
| -- Configuration handling |
128 | 136 |
|
129 |
| -## Running the Example |
130 | 137 |
|
131 |
| -1. Set the `MXCP_CONFIG` environment variable to point to your config file: |
132 |
| - ```bash |
133 |
| - export MXCP_CONFIG=/path/to/examples/jira/config.yml |
134 |
| - ``` |
| 138 | +## Example Usage |
135 | 139 |
|
136 |
| -2. Start the MXCP server: |
| 140 | +1. Start the MXCP server: |
137 | 141 | ```bash
|
138 | 142 | mxcp serve
|
139 | 143 | ```
|
140 | 144 |
|
| 145 | +2. Or run tools directly: |
| 146 | + ```bash |
| 147 | + # Query recent issues |
| 148 | + mxcp run tool jql_query --param query="project = TEST ORDER BY created DESC" --param limit=5 |
| 149 | + |
| 150 | + # Get specific issue details |
| 151 | + mxcp run tool get_issue --param issue_key="RD-123" |
| 152 | + |
| 153 | + # Get specific user by account ID |
| 154 | + mxcp run tool get_user --param account_id="557058:ab168c94-8485-405c-88e6-6458375eb30b" |
| 155 | + |
| 156 | + # Search for users |
| 157 | + mxcp run tool search_user --param query="admin" |
| 158 | + |
| 159 | + # List all projects |
| 160 | + mxcp run tool list_projects |
| 161 | + |
| 162 | + # Get specific project |
| 163 | + mxcp run tool get_project --param project_key="TEST" |
| 164 | + |
| 165 | + # Get project roles |
| 166 | + mxcp run tool get_project_roles --param project_key="TEST" |
| 167 | + |
| 168 | + # Get users for specific role |
| 169 | + mxcp run tool get_project_role_users --param project_key="TEST" --param role_name="Developers" |
| 170 | + ``` |
| 171 | + |
| 172 | +## Project Structure |
| 173 | + |
| 174 | +``` |
| 175 | +jira-python/ |
| 176 | +├── mxcp-site.yml # Simple site configuration |
| 177 | +├── python/ # Python implementations |
| 178 | +│ └── jira_endpoints.py # All JIRA endpoint functions |
| 179 | +├── tools/ # Tool definitions |
| 180 | +│ ├── jql_query.yml |
| 181 | +│ ├── get_issue.yml |
| 182 | +│ ├── get_user.yml |
| 183 | +│ ├── search_user.yml |
| 184 | +│ ├── list_projects.yml |
| 185 | +│ ├── get_project.yml |
| 186 | +│ ├── get_project_roles.yml |
| 187 | +│ └── get_project_role_users.yml |
| 188 | +└── README.md |
| 189 | +``` |
| 190 | +
|
| 191 | +## Key Features |
| 192 | +
|
| 193 | +- **Direct Python Functions**: No SQL wrapper layer needed |
| 194 | +- **Async Support**: Functions can be async for better performance |
| 195 | +- **Database Integration**: Can optionally store results in DuckDB |
| 196 | +- **Error Handling**: Proper error responses for invalid requests |
| 197 | +- **Type Safety**: Full type hints for better IDE support |
| 198 | +- **Logging**: Comprehensive logging for debugging |
| 199 | +
|
| 200 | +## Migration from Plugin Approach |
| 201 | +
|
| 202 | +This example demonstrates how much simpler the Python endpoint approach is: |
| 203 | +
|
| 204 | +- **Plugin approach**: Plugin class → UDFs → SQL calls → Tool definitions |
| 205 | +- **Python approach**: Python functions → Tool definitions |
| 206 | +
|
| 207 | +The functionality is identical, but the implementation is much more straightforward! |
| 208 | +
|
141 | 209 | ## Notes
|
142 | 210 |
|
143 |
| -- Make sure to keep your API token secure and never commit it to version control. |
144 |
| -- The plugin requires proper authentication and API permissions to work with your Jira instance. |
145 |
| -- All functions return JSON strings containing the requested data. |
| 211 | +- Make sure to keep your API token secure and never commit it to version control |
| 212 | +- The plugin requires proper authentication and API permissions to work with your Jira instance |
| 213 | +- Functions return JSON data that can be directly used by MCP clients |
| 214 | +- Results can optionally be stored in DuckDB for further SQL analysis |
0 commit comments