Skip to content

Commit 8e9a3f9

Browse files
Reorganize file structure and tests to reduce context issues for AI (#20)
* Update configuration files and enhance documentation - Added missing newlines at the end of several configuration files (.eslintrc.json, .prettierrc, tsconfig.json, jest.config.js, jest.integration.config.js). - Updated README.md to include additional environment variable setup instructions for Azure DevOps. - Improved documentation across various files, ensuring clarity and completeness, particularly in authentication and project setup sections. - Removed deprecated files and tests to streamline the codebase and improve maintainability. * Refactor test structure and enhance error handling - Updated test files to follow colocation patterns, improving organization and maintainability. - Added tasks to fix specific test files by co-locating or moving individual tests to appropriate files. - Enhanced error handling in authentication tests to provide clearer error messages for token acquisition failures. - Updated mock implementations in tests to ensure accurate behavior and error handling for Azure DevOps API interactions. * Enhance error handling in authentication and repository listing tests - Added tests to handle non-Error objects in catch blocks for both listRepositories and listWorkItems functions, ensuring proper error messages are thrown. - Updated existing tests to convert generic error messages into specific Azure DevOps error types, improving clarity and robustness in error handling. - Refactored mock implementations in authentication tests to simulate various error scenarios, enhancing test coverage and reliability. * Remove obsolete test files and refactor existing tests for improved organization - Deleted outdated test files including server-coverage.test.ts, server-client.test.ts, auth.test.ts, and server-auth.test.ts to streamline the codebase. - Refactored existing tests to enhance clarity and maintainability, ensuring they follow updated patterns and practices. - Improved error handling in authentication tests, ensuring comprehensive coverage for various authentication scenarios. - Updated mock implementations to accurately simulate Azure DevOps API interactions, enhancing test reliability. * Reorganize test structure to follow co-location pattern This PR completes the test reorganization task by moving tests to follow the co-location pattern, ensuring proper organization and maintainability of the codebase. * Complete task to reorganize repository structure around "Screaming Architecture" and "Vertical Slices" This commit finalizes the restructuring of the codebase to emphasize business domains over technical layers, implementing a feature-based module organization. All tasks related to the refactor have been completed, including the migration of tests to co-locate with their respective implementations, enhancing clarity and maintainability. The old layer-based directories have been removed, and the new structure has been validated with passing tests across all features. * Refactor setup_env.sh to remove PAT creation logic and update authentication method This commit simplifies the setup_env.sh script by removing the Personal Access Token (PAT) creation process, which included both automated and manual methods. The script now defaults to using Azure Identity for authentication, streamlining the setup process. Additionally, the .env file has been updated to reflect the new authentication method, enhancing clarity and maintainability. --------- Co-authored-by: Micah Rairdon <[email protected]>
1 parent 500f67a commit 8e9a3f9

File tree

150 files changed

+6154
-6220
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+6154
-6220
lines changed

.eslintrc.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@
1515
"prettier/prettier": "error",
1616
"@typescript-eslint/explicit-function-return-type": "off",
1717
"@typescript-eslint/no-explicit-any": "warn",
18-
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }]
18+
"@typescript-eslint/no-unused-vars": [
19+
"error",
20+
{ "argsIgnorePattern": "^_" }
21+
]
1922
},
2023
"parserOptions": {
2124
"ecmaVersion": 2020,
2225
"sourceType": "module"
2326
}
24-
}
27+
}

.github/workflows/main.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: CI/CD
22

33
on:
44
push:
5-
branches: [ main ]
5+
branches: [main]
66
pull_request:
7-
branches: [ main ]
7+
branches: [main]
88

99
jobs:
1010
build:
@@ -28,4 +28,4 @@ jobs:
2828
CI: 'true'
2929
AZURE_DEVOPS_ORG_URL: ${{ secrets.AZURE_DEVOPS_ORG_URL }}
3030
AZURE_DEVOPS_PAT: ${{ secrets.AZURE_DEVOPS_PAT }}
31-
AZURE_DEVOPS_DEFAULT_PROJECT: ${{ secrets.AZURE_DEVOPS_DEFAULT_PROJECT }}
31+
AZURE_DEVOPS_DEFAULT_PROJECT: ${{ secrets.AZURE_DEVOPS_DEFAULT_PROJECT }}

.prettierrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
"tabWidth": 2,
77
"useTabs": false,
88
"endOfLine": "lf"
9-
}
9+
}

README.md

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,49 +43,59 @@ The server is structured around the Model Context Protocol (MCP) for communicati
4343
### Installation
4444

4545
1. Clone the repository:
46+
4647
```
4748
git clone https://github.com/your-username/azure-devops-mcp.git
4849
cd azure-devops-mcp
4950
```
5051

5152
2. Install dependencies:
53+
5254
```
5355
npm install
5456
```
5557

5658
3. Set up your environment:
5759

5860
Option A: Using the automated setup script (recommended):
61+
5962
```
6063
chmod +x setup_env.sh
6164
./setup_env.sh
6265
```
66+
6367
This script will:
68+
6469
- Check for and install the Azure CLI DevOps extension if needed
6570
- Let you select from your available Azure DevOps organizations
6671
- Optionally set a default project
6772
- Create a Personal Access Token with the required permissions
6873
- Generate your `.env` file with the correct settings
6974

7075
Option B: Manual setup:
76+
7177
```
7278
cp .env.example .env
7379
```
80+
7481
Then edit the `.env` file with your Azure DevOps credentials (see Authentication section below).
7582

7683
### Running the Server
7784

7885
Build the TypeScript files:
86+
7987
```
8088
npm run build
8189
```
8290

8391
Start the server:
92+
8493
```
8594
npm start
8695
```
8796

8897
For development with hot reloading:
98+
8999
```
90100
npm run dev
91101
```
@@ -108,26 +118,27 @@ For a complete list of environment variables and their descriptions, see the [Au
108118

109119
Key environment variables include:
110120

111-
| Variable | Description | Required | Default |
112-
|----------|-------------|----------|---------|
113-
| `AZURE_DEVOPS_AUTH_METHOD` | Authentication method (`pat`, `azure-identity`, or `azure-cli`) | No | `azure-identity` |
114-
| `AZURE_DEVOPS_ORG` | Azure DevOps organization name | No | Extracted from URL |
115-
| `AZURE_DEVOPS_ORG_URL` | Full URL to your Azure DevOps organization | Yes | - |
116-
| `AZURE_DEVOPS_PAT` | Personal Access Token (for PAT auth) | Only with PAT auth | - |
117-
| `AZURE_DEVOPS_DEFAULT_PROJECT` | Default project if none specified | No | - |
118-
| `AZURE_DEVOPS_API_VERSION` | API version to use | No | Latest |
119-
| `AZURE_AD_TENANT_ID` | Azure AD tenant ID (for AAD auth) | Only with AAD auth | - |
120-
| `AZURE_AD_CLIENT_ID` | Azure AD application ID (for AAD auth) | Only with AAD auth | - |
121-
| `AZURE_AD_CLIENT_SECRET` | Azure AD client secret (for AAD auth) | Only with AAD auth | - |
122-
| `PORT` | Server port | No | 3000 |
123-
| `HOST` | Server host | No | localhost |
124-
| `LOG_LEVEL` | Logging level (debug, info, warn, error) | No | info |
121+
| Variable | Description | Required | Default |
122+
| ------------------------------ | --------------------------------------------------------------- | ------------------ | ------------------ |
123+
| `AZURE_DEVOPS_AUTH_METHOD` | Authentication method (`pat`, `azure-identity`, or `azure-cli`) | No | `azure-identity` |
124+
| `AZURE_DEVOPS_ORG` | Azure DevOps organization name | No | Extracted from URL |
125+
| `AZURE_DEVOPS_ORG_URL` | Full URL to your Azure DevOps organization | Yes | - |
126+
| `AZURE_DEVOPS_PAT` | Personal Access Token (for PAT auth) | Only with PAT auth | - |
127+
| `AZURE_DEVOPS_DEFAULT_PROJECT` | Default project if none specified | No | - |
128+
| `AZURE_DEVOPS_API_VERSION` | API version to use | No | Latest |
129+
| `AZURE_AD_TENANT_ID` | Azure AD tenant ID (for AAD auth) | Only with AAD auth | - |
130+
| `AZURE_AD_CLIENT_ID` | Azure AD application ID (for AAD auth) | Only with AAD auth | - |
131+
| `AZURE_AD_CLIENT_SECRET` | Azure AD client secret (for AAD auth) | Only with AAD auth | - |
132+
| `PORT` | Server port | No | 3000 |
133+
| `HOST` | Server host | No | localhost |
134+
| `LOG_LEVEL` | Logging level (debug, info, warn, error) | No | info |
125135

126136
## Troubleshooting Authentication
127137

128138
For detailed troubleshooting information for each authentication method, see the [Authentication Guide](docs/authentication.md#troubleshooting-authentication-issues).
129139

130140
Common issues include:
141+
131142
- Invalid or expired credentials
132143
- Insufficient permissions
133144
- Network connectivity problems
@@ -142,23 +153,27 @@ For technical details about how authentication is implemented in the Azure DevOp
142153
The Azure DevOps MCP server provides a variety of tools for interacting with Azure DevOps resources. For detailed documentation on each tool, please refer to the corresponding documentation.
143154

144155
### Core Navigation Tools
156+
145157
- `list_organizations`: List all accessible organizations
146158
- `list_projects`: List all accessible projects
147159
- `list_repositories`: List all repositories in a project
148160

149161
For comprehensive documentation on all core navigation tools, see the [Core Navigation Tools Guide](docs/tools/core-navigation.md).
150162

151163
### Project Tools
164+
152165
- `get_project`: Get details of a specific project
153166

154167
For project-specific tool documentation, see the [Projects Tools Guide](docs/tools/projects.md).
155168

156169
### Repository Tools
170+
157171
- `get_repository`: Get repository details
158172

159173
For repository-specific tool documentation, see the [Repositories Tools Guide](docs/tools/repositories.md).
160174

161175
### Work Item Tools
176+
162177
- `get_work_item`: Retrieve a work item by ID
163178
- `create_work_item`: Create a new work item
164179

@@ -177,6 +192,7 @@ npm run test:unit
177192
Integration tests require a connection to a real Azure DevOps instance. To run them:
178193

179194
1. Ensure your `.env` file is configured with valid Azure DevOps credentials:
195+
180196
```
181197
AZURE_DEVOPS_ORG_URL=https://dev.azure.com/your-organization
182198
AZURE_DEVOPS_PAT=your-personal-access-token

docs/authentication.md

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ PAT authentication is the simplest method and works well for personal use or tes
1717
### Setup Instructions
1818

1919
1. **Generate a PAT in Azure DevOps**:
20+
2021
- Go to https://dev.azure.com/{your-organization}/_usersSettings/tokens
2122
- Or click on your profile picture > Personal access tokens
2223
- Select "+ New Token"
@@ -69,6 +70,7 @@ This makes it ideal for applications that need to work in different environments
6970
The SDK is already included as a dependency in the Azure DevOps MCP Server.
7071

7172
2. **Configure your `.env` file**:
73+
7274
```
7375
AZURE_DEVOPS_AUTH_METHOD=azure-identity
7476
AZURE_DEVOPS_ORG_URL=https://dev.azure.com/your-organization
@@ -78,18 +80,20 @@ This makes it ideal for applications that need to work in different environments
7880
3. **Set up credentials based on your environment**:
7981

8082
a. **For service principals (client credentials)**:
81-
```
82-
AZURE_TENANT_ID=your-tenant-id
83-
AZURE_CLIENT_ID=your-client-id
84-
AZURE_CLIENT_SECRET=your-client-secret
85-
```
83+
84+
```
85+
AZURE_TENANT_ID=your-tenant-id
86+
AZURE_CLIENT_ID=your-client-id
87+
AZURE_CLIENT_SECRET=your-client-secret
88+
```
8689

8790
b. **For managed identities in Azure**:
88-
No additional configuration needed if running in Azure with a managed identity.
91+
No additional configuration needed if running in Azure with a managed identity.
8992

9093
c. **For local development**:
91-
- Log in with Azure CLI: `az login`
92-
- Or use Visual Studio Code Azure Account extension
94+
95+
- Log in with Azure CLI: `az login`
96+
- Or use Visual Studio Code Azure Account extension
9397

9498
### Security Considerations
9599

@@ -105,9 +109,11 @@ Azure CLI authentication uses the `AzureCliCredential` class from the `@azure/id
105109
### Setup Instructions
106110

107111
1. **Install the Azure CLI**:
112+
108113
- Follow the instructions at https://docs.microsoft.com/cli/azure/install-azure-cli
109114

110115
2. **Log in to Azure**:
116+
111117
```bash
112118
az login
113119
```
@@ -127,26 +133,28 @@ Azure CLI authentication uses the `AzureCliCredential` class from the `@azure/id
127133

128134
## Configuration Reference
129135

130-
| Environment Variable | Description | Required | Default |
131-
|----------|-------------|----------|---------|
132-
| `AZURE_DEVOPS_AUTH_METHOD` | Authentication method (`pat`, `azure-identity`, or `azure-cli`) | No | `azure-identity` |
133-
| `AZURE_DEVOPS_ORG_URL` | Full URL to your Azure DevOps organization | Yes | - |
134-
| `AZURE_DEVOPS_PAT` | Personal Access Token (for PAT auth) | Only with PAT auth | - |
135-
| `AZURE_DEVOPS_DEFAULT_PROJECT` | Default project if none specified | No | - |
136-
| `AZURE_DEVOPS_API_VERSION` | API version to use | No | Latest |
137-
| `AZURE_TENANT_ID` | Azure AD tenant ID (for service principals) | Only with service principals | - |
138-
| `AZURE_CLIENT_ID` | Azure AD application ID (for service principals) | Only with service principals | - |
139-
| `AZURE_CLIENT_SECRET` | Azure AD client secret (for service principals) | Only with service principals | - |
136+
| Environment Variable | Description | Required | Default |
137+
| ------------------------------ | --------------------------------------------------------------- | ---------------------------- | ---------------- |
138+
| `AZURE_DEVOPS_AUTH_METHOD` | Authentication method (`pat`, `azure-identity`, or `azure-cli`) | No | `azure-identity` |
139+
| `AZURE_DEVOPS_ORG_URL` | Full URL to your Azure DevOps organization | Yes | - |
140+
| `AZURE_DEVOPS_PAT` | Personal Access Token (for PAT auth) | Only with PAT auth | - |
141+
| `AZURE_DEVOPS_DEFAULT_PROJECT` | Default project if none specified | No | - |
142+
| `AZURE_DEVOPS_API_VERSION` | API version to use | No | Latest |
143+
| `AZURE_TENANT_ID` | Azure AD tenant ID (for service principals) | Only with service principals | - |
144+
| `AZURE_CLIENT_ID` | Azure AD application ID (for service principals) | Only with service principals | - |
145+
| `AZURE_CLIENT_SECRET` | Azure AD client secret (for service principals) | Only with service principals | - |
140146

141147
## Troubleshooting Authentication Issues
142148

143149
### PAT Authentication Issues
144150

145151
1. **Invalid PAT**: Ensure your PAT hasn't expired and has the required scopes
152+
146153
- Error: `TF400813: The user 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' is not authorized to access this resource.`
147154
- Solution: Generate a new PAT with the correct scopes
148155

149156
2. **Scope issues**: If receiving 403 errors, check if your PAT has the necessary permissions
157+
150158
- Error: `TF401027: You need the Git 'Read' permission to perform this action.`
151159
- Solution: Update your PAT with the required scopes
152160

@@ -157,10 +165,12 @@ Azure CLI authentication uses the `AzureCliCredential` class from the `@azure/id
157165
### Azure Identity Authentication Issues
158166

159167
1. **Missing credentials**: Ensure you have the necessary credentials configured
168+
160169
- Error: `CredentialUnavailableError: DefaultAzureCredential failed to retrieve a token`
161170
- Solution: Check that you're logged in with Azure CLI or have environment variables set
162171

163172
2. **Permission issues**: Verify your identity has the necessary permissions
173+
164174
- Error: `AuthorizationFailed: The client does not have authorization to perform action`
165175
- Solution: Assign the appropriate roles to your identity
166176

@@ -171,10 +181,12 @@ Azure CLI authentication uses the `AzureCliCredential` class from the `@azure/id
171181
### Azure CLI Authentication Issues
172182

173183
1. **CLI not installed**: Ensure Azure CLI is installed and in your PATH
184+
174185
- Error: `AzureCliCredential authentication failed: Azure CLI not found`
175186
- Solution: Install Azure CLI
176187

177188
2. **Not logged in**: Verify you're logged in to Azure CLI
189+
178190
- Error: `AzureCliCredential authentication failed: Please run 'az login'`
179191
- Solution: Run `az login`
180192

@@ -185,15 +197,18 @@ Azure CLI authentication uses the `AzureCliCredential` class from the `@azure/id
185197
## Best Practices
186198

187199
1. **Choose the right authentication method for your environment**:
200+
188201
- For local development: Azure CLI or PAT
189202
- For CI/CD pipelines: PAT or service principal
190203
- For Azure-hosted applications: Managed Identity
191204

192205
2. **Follow the principle of least privilege**:
206+
193207
- Only grant the permissions needed for your use case
194208
- Regularly review and rotate credentials
195209

196210
3. **Secure your credentials**:
211+
197212
- Use environment variables or a secrets manager
198213
- Never commit credentials to source control
199214
- Set appropriate expiration dates for PATs
@@ -242,4 +257,4 @@ AZURE_CLIENT_SECRET=your-client-secret
242257
AZURE_DEVOPS_AUTH_METHOD=azure-cli
243258
AZURE_DEVOPS_ORG_URL=https://dev.azure.com/mycompany
244259
AZURE_DEVOPS_DEFAULT_PROJECT=MyProject
245-
```
260+
```

0 commit comments

Comments
 (0)