mcp-proxy-oauth-dcr 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.
- mcp_proxy_oauth_dcr-0.1.0/ARCHITECTURE.md +267 -0
- mcp_proxy_oauth_dcr-0.1.0/DEVELOPMENT.md +360 -0
- mcp_proxy_oauth_dcr-0.1.0/LICENSE +21 -0
- mcp_proxy_oauth_dcr-0.1.0/MANIFEST.in +42 -0
- mcp_proxy_oauth_dcr-0.1.0/PKG-INFO +167 -0
- mcp_proxy_oauth_dcr-0.1.0/PROXY_USAGE.md +299 -0
- mcp_proxy_oauth_dcr-0.1.0/README.md +121 -0
- mcp_proxy_oauth_dcr-0.1.0/examples/.env.example +14 -0
- mcp_proxy_oauth_dcr-0.1.0/examples/CLI_USAGE.md +354 -0
- mcp_proxy_oauth_dcr-0.1.0/examples/authenticated_client_example.py +161 -0
- mcp_proxy_oauth_dcr-0.1.0/examples/config.json.example +13 -0
- mcp_proxy_oauth_dcr-0.1.0/examples/run_proxy.py +72 -0
- mcp_proxy_oauth_dcr-0.1.0/pyproject.toml +148 -0
- mcp_proxy_oauth_dcr-0.1.0/setup.cfg +4 -0
- mcp_proxy_oauth_dcr-0.1.0/src/mcp_proxy/__init__.py +89 -0
- mcp_proxy_oauth_dcr-0.1.0/src/mcp_proxy/__main__.py +340 -0
- mcp_proxy_oauth_dcr-0.1.0/src/mcp_proxy/auth/__init__.py +8 -0
- mcp_proxy_oauth_dcr-0.1.0/src/mcp_proxy/auth/manager.py +908 -0
- mcp_proxy_oauth_dcr-0.1.0/src/mcp_proxy/config/__init__.py +8 -0
- mcp_proxy_oauth_dcr-0.1.0/src/mcp_proxy/config/manager.py +200 -0
- mcp_proxy_oauth_dcr-0.1.0/src/mcp_proxy/exceptions.py +186 -0
- mcp_proxy_oauth_dcr-0.1.0/src/mcp_proxy/http/__init__.py +9 -0
- mcp_proxy_oauth_dcr-0.1.0/src/mcp_proxy/http/authenticated_client.py +388 -0
- mcp_proxy_oauth_dcr-0.1.0/src/mcp_proxy/http/client.py +997 -0
- mcp_proxy_oauth_dcr-0.1.0/src/mcp_proxy/logging_config.py +71 -0
- mcp_proxy_oauth_dcr-0.1.0/src/mcp_proxy/models.py +259 -0
- mcp_proxy_oauth_dcr-0.1.0/src/mcp_proxy/protocols.py +122 -0
- mcp_proxy_oauth_dcr-0.1.0/src/mcp_proxy/proxy.py +586 -0
- mcp_proxy_oauth_dcr-0.1.0/src/mcp_proxy/stdio/__init__.py +31 -0
- mcp_proxy_oauth_dcr-0.1.0/src/mcp_proxy/stdio/interface.py +580 -0
- mcp_proxy_oauth_dcr-0.1.0/src/mcp_proxy/stdio/jsonrpc.py +371 -0
- mcp_proxy_oauth_dcr-0.1.0/src/mcp_proxy/translator/__init__.py +11 -0
- mcp_proxy_oauth_dcr-0.1.0/src/mcp_proxy/translator/translator.py +691 -0
- mcp_proxy_oauth_dcr-0.1.0/src/mcp_proxy_oauth_dcr.egg-info/PKG-INFO +167 -0
- mcp_proxy_oauth_dcr-0.1.0/src/mcp_proxy_oauth_dcr.egg-info/SOURCES.txt +37 -0
- mcp_proxy_oauth_dcr-0.1.0/src/mcp_proxy_oauth_dcr.egg-info/dependency_links.txt +1 -0
- mcp_proxy_oauth_dcr-0.1.0/src/mcp_proxy_oauth_dcr.egg-info/entry_points.txt +2 -0
- mcp_proxy_oauth_dcr-0.1.0/src/mcp_proxy_oauth_dcr.egg-info/requires.txt +22 -0
- mcp_proxy_oauth_dcr-0.1.0/src/mcp_proxy_oauth_dcr.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
# MCP Proxy Architecture
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
This document describes the architecture and structure of the MCP Proxy with OAuth DCR support.
|
|
6
|
+
|
|
7
|
+
## Project Structure
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
mcp-proxy/
|
|
11
|
+
├── src/
|
|
12
|
+
│ └── mcp_proxy/
|
|
13
|
+
│ ├── __init__.py # Main package exports
|
|
14
|
+
│ ├── models.py # Core data models (Pydantic)
|
|
15
|
+
│ ├── protocols.py # Protocol interfaces (typing.Protocol)
|
|
16
|
+
│ ├── exceptions.py # Custom exception hierarchy
|
|
17
|
+
│ ├── logging_config.py # Structured logging setup
|
|
18
|
+
│ ├── auth/ # Authentication module
|
|
19
|
+
│ │ ├── __init__.py
|
|
20
|
+
│ │ └── manager.py # OAuth DCR implementation (TBD)
|
|
21
|
+
│ ├── config/ # Configuration module
|
|
22
|
+
│ │ ├── __init__.py
|
|
23
|
+
│ │ └── manager.py # Config loading/validation (TBD)
|
|
24
|
+
│ ├── http/ # HTTP client module
|
|
25
|
+
│ │ ├── __init__.py
|
|
26
|
+
│ │ └── client.py # HTTP MCP client (TBD)
|
|
27
|
+
│ ├── stdio/ # Stdio interface module
|
|
28
|
+
│ │ ├── __init__.py
|
|
29
|
+
│ │ └── interface.py # Stdio communication (TBD)
|
|
30
|
+
│ └── translator/ # Protocol translator module
|
|
31
|
+
│ ├── __init__.py
|
|
32
|
+
│ └── translator.py # Protocol conversion (TBD)
|
|
33
|
+
├── tests/
|
|
34
|
+
│ ├── __init__.py
|
|
35
|
+
│ ├── conftest.py # Pytest fixtures
|
|
36
|
+
│ └── test_models.py # Model tests
|
|
37
|
+
├── .kiro/
|
|
38
|
+
│ └── specs/
|
|
39
|
+
│ └── mcp-proxy-oauth-dcr/ # Feature specifications
|
|
40
|
+
├── pyproject.toml # Project configuration
|
|
41
|
+
├── README.md # User documentation
|
|
42
|
+
├── ARCHITECTURE.md # This file
|
|
43
|
+
└── .gitignore # Git ignore rules
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Core Components
|
|
47
|
+
|
|
48
|
+
### 1. Data Models (`models.py`)
|
|
49
|
+
|
|
50
|
+
Defines all data structures using Pydantic for validation:
|
|
51
|
+
|
|
52
|
+
- **JsonRpcMessage**: JSON-RPC 2.0 message structure
|
|
53
|
+
- **HttpMcpRequest/Response**: HTTP MCP protocol structures
|
|
54
|
+
- **ClientCredentials**: OAuth client credentials
|
|
55
|
+
- **OAuthTokenResponse**: OAuth token response
|
|
56
|
+
- **AuthenticationState**: Current authentication state
|
|
57
|
+
- **SessionState**: MCP session state
|
|
58
|
+
- **MessageCorrelation**: Request/response correlation tracking
|
|
59
|
+
- **ProxyConfig**: Proxy configuration
|
|
60
|
+
|
|
61
|
+
### 2. Protocol Interfaces (`protocols.py`)
|
|
62
|
+
|
|
63
|
+
Defines abstract interfaces using `typing.Protocol`:
|
|
64
|
+
|
|
65
|
+
- **StdioInterface**: Stdio communication interface
|
|
66
|
+
- **ProtocolTranslator**: Protocol translation interface
|
|
67
|
+
- **AuthenticationManager**: OAuth DCR and token management interface
|
|
68
|
+
- **HttpClient**: HTTP communication interface
|
|
69
|
+
- **ConfigurationManager**: Configuration management interface
|
|
70
|
+
|
|
71
|
+
### 3. Exception Hierarchy (`exceptions.py`)
|
|
72
|
+
|
|
73
|
+
Custom exceptions for error handling:
|
|
74
|
+
|
|
75
|
+
- **McpProxyError**: Base exception
|
|
76
|
+
- **ProtocolError**: Protocol translation errors
|
|
77
|
+
- **AuthenticationError**: Authentication errors
|
|
78
|
+
- **NetworkError**: Network and connection errors
|
|
79
|
+
- **ConfigurationError**: Configuration errors
|
|
80
|
+
|
|
81
|
+
### 4. Logging (`logging_config.py`)
|
|
82
|
+
|
|
83
|
+
Structured logging using `structlog`:
|
|
84
|
+
|
|
85
|
+
- Configurable log levels
|
|
86
|
+
- JSON output for production
|
|
87
|
+
- Console output for development
|
|
88
|
+
- Context variable support
|
|
89
|
+
|
|
90
|
+
## Module Organization
|
|
91
|
+
|
|
92
|
+
### Authentication Module (`auth/`)
|
|
93
|
+
|
|
94
|
+
Handles OAuth Dynamic Client Registration and token management:
|
|
95
|
+
|
|
96
|
+
- DCR protocol implementation (RFC 7591)
|
|
97
|
+
- Token acquisition and refresh
|
|
98
|
+
- Credential storage and lifecycle
|
|
99
|
+
- Authentication state management
|
|
100
|
+
|
|
101
|
+
### Configuration Module (`config/`)
|
|
102
|
+
|
|
103
|
+
Manages proxy configuration:
|
|
104
|
+
|
|
105
|
+
- Environment variable loading
|
|
106
|
+
- Configuration file parsing
|
|
107
|
+
- Parameter validation
|
|
108
|
+
- Default value management
|
|
109
|
+
|
|
110
|
+
### HTTP Module (`http/`)
|
|
111
|
+
|
|
112
|
+
HTTP communication with backend MCP servers:
|
|
113
|
+
|
|
114
|
+
- aiohttp-based async HTTP client
|
|
115
|
+
- Server-Sent Events (SSE) support
|
|
116
|
+
- Connection pooling and retry logic
|
|
117
|
+
- Session management
|
|
118
|
+
|
|
119
|
+
### Stdio Module (`stdio/`)
|
|
120
|
+
|
|
121
|
+
Stdio interface for Kiro communication:
|
|
122
|
+
|
|
123
|
+
- Async stdin/stdout handling
|
|
124
|
+
- JSON-RPC message parsing
|
|
125
|
+
- Newline-delimited message protocol
|
|
126
|
+
- Subprocess lifecycle management
|
|
127
|
+
|
|
128
|
+
### Translator Module (`translator/`)
|
|
129
|
+
|
|
130
|
+
Protocol translation between stdio and HTTP:
|
|
131
|
+
|
|
132
|
+
- Stdio to HTTP conversion
|
|
133
|
+
- HTTP to stdio conversion
|
|
134
|
+
- Message correlation tracking
|
|
135
|
+
- Error translation
|
|
136
|
+
|
|
137
|
+
## Design Principles
|
|
138
|
+
|
|
139
|
+
### 1. Separation of Concerns
|
|
140
|
+
|
|
141
|
+
Each module has a single, well-defined responsibility:
|
|
142
|
+
|
|
143
|
+
- Models: Data structures only
|
|
144
|
+
- Protocols: Interface definitions only
|
|
145
|
+
- Implementations: Concrete behavior in separate modules
|
|
146
|
+
|
|
147
|
+
### 2. Dependency Injection
|
|
148
|
+
|
|
149
|
+
Components depend on protocol interfaces, not concrete implementations:
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
class ProxyOrchestrator:
|
|
153
|
+
def __init__(
|
|
154
|
+
self,
|
|
155
|
+
auth_manager: AuthenticationManager,
|
|
156
|
+
http_client: HttpClient,
|
|
157
|
+
translator: ProtocolTranslator,
|
|
158
|
+
):
|
|
159
|
+
...
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### 3. Async/Await
|
|
163
|
+
|
|
164
|
+
All I/O operations use async/await for concurrency:
|
|
165
|
+
|
|
166
|
+
- Stdio communication
|
|
167
|
+
- HTTP requests
|
|
168
|
+
- Token refresh
|
|
169
|
+
- Message processing
|
|
170
|
+
|
|
171
|
+
### 4. Type Safety
|
|
172
|
+
|
|
173
|
+
Strong typing throughout:
|
|
174
|
+
|
|
175
|
+
- Pydantic models for runtime validation
|
|
176
|
+
- Type hints for static analysis
|
|
177
|
+
- Protocol interfaces for structural typing
|
|
178
|
+
|
|
179
|
+
### 5. Error Handling
|
|
180
|
+
|
|
181
|
+
Comprehensive error handling:
|
|
182
|
+
|
|
183
|
+
- Custom exception hierarchy
|
|
184
|
+
- Error translation between protocols
|
|
185
|
+
- Graceful degradation
|
|
186
|
+
- Detailed error messages
|
|
187
|
+
|
|
188
|
+
## Testing Strategy
|
|
189
|
+
|
|
190
|
+
### Unit Tests
|
|
191
|
+
|
|
192
|
+
Test individual components in isolation:
|
|
193
|
+
|
|
194
|
+
- Model validation
|
|
195
|
+
- Protocol translation
|
|
196
|
+
- Authentication flows
|
|
197
|
+
- Configuration parsing
|
|
198
|
+
|
|
199
|
+
### Property-Based Tests
|
|
200
|
+
|
|
201
|
+
Test universal properties using Hypothesis:
|
|
202
|
+
|
|
203
|
+
- Protocol compliance
|
|
204
|
+
- Message correlation
|
|
205
|
+
- Token lifecycle
|
|
206
|
+
- Configuration validation
|
|
207
|
+
|
|
208
|
+
### Integration Tests
|
|
209
|
+
|
|
210
|
+
Test component interactions:
|
|
211
|
+
|
|
212
|
+
- End-to-end message flow
|
|
213
|
+
- Authentication integration
|
|
214
|
+
- Error handling
|
|
215
|
+
- Connection resilience
|
|
216
|
+
|
|
217
|
+
## Development Workflow
|
|
218
|
+
|
|
219
|
+
### 1. Setup
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
python3 -m venv venv
|
|
223
|
+
source venv/bin/activate # or venv\Scripts\activate on Windows
|
|
224
|
+
pip install -e ".[dev]"
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### 2. Testing
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
# Run all tests
|
|
231
|
+
pytest
|
|
232
|
+
|
|
233
|
+
# Run specific test file
|
|
234
|
+
pytest tests/test_models.py
|
|
235
|
+
|
|
236
|
+
# Run with coverage
|
|
237
|
+
pytest --cov=mcp_proxy --cov-report=html
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### 3. Code Quality
|
|
241
|
+
|
|
242
|
+
```bash
|
|
243
|
+
# Format code
|
|
244
|
+
black src tests
|
|
245
|
+
isort src tests
|
|
246
|
+
|
|
247
|
+
# Type checking
|
|
248
|
+
mypy src
|
|
249
|
+
|
|
250
|
+
# Linting
|
|
251
|
+
flake8 src tests
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
## Next Steps
|
|
255
|
+
|
|
256
|
+
The following components need implementation:
|
|
257
|
+
|
|
258
|
+
1. **Configuration Manager** (Task 2)
|
|
259
|
+
2. **JSON-RPC Message Handling** (Task 3)
|
|
260
|
+
3. **Stdio Interface** (Task 4)
|
|
261
|
+
4. **OAuth DCR Authentication** (Task 6)
|
|
262
|
+
5. **HTTP Client** (Task 7)
|
|
263
|
+
6. **Protocol Translator** (Task 8)
|
|
264
|
+
7. **Main Proxy Orchestration** (Task 11)
|
|
265
|
+
8. **CLI Interface** (Task 12)
|
|
266
|
+
|
|
267
|
+
Each task builds on the foundation established in Task 1.
|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
# Development Guide
|
|
2
|
+
|
|
3
|
+
## Getting Started
|
|
4
|
+
|
|
5
|
+
### Prerequisites
|
|
6
|
+
|
|
7
|
+
- Python 3.8 or higher
|
|
8
|
+
- pip and venv
|
|
9
|
+
- Git
|
|
10
|
+
|
|
11
|
+
### Initial Setup
|
|
12
|
+
|
|
13
|
+
1. Clone the repository:
|
|
14
|
+
```bash
|
|
15
|
+
git clone <repository-url>
|
|
16
|
+
cd mcp-proxy
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
2. Create and activate virtual environment:
|
|
20
|
+
```bash
|
|
21
|
+
python3 -m venv venv
|
|
22
|
+
source venv/bin/activate # On Windows: venv\Scripts\activate
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
3. Install development dependencies:
|
|
26
|
+
```bash
|
|
27
|
+
pip install -e ".[dev]"
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Project Structure
|
|
31
|
+
|
|
32
|
+
See [ARCHITECTURE.md](ARCHITECTURE.md) for detailed architecture documentation.
|
|
33
|
+
|
|
34
|
+
## Development Tasks
|
|
35
|
+
|
|
36
|
+
### Running Tests
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
# Run all tests
|
|
40
|
+
pytest
|
|
41
|
+
|
|
42
|
+
# Run specific test file
|
|
43
|
+
pytest tests/test_models.py
|
|
44
|
+
|
|
45
|
+
# Run with verbose output
|
|
46
|
+
pytest -v
|
|
47
|
+
|
|
48
|
+
# Run with coverage
|
|
49
|
+
pytest --cov=mcp_proxy --cov-report=html
|
|
50
|
+
|
|
51
|
+
# Run only unit tests
|
|
52
|
+
pytest -m unit
|
|
53
|
+
|
|
54
|
+
# Run only property-based tests
|
|
55
|
+
pytest -m property
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Code Formatting
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
# Format Python code
|
|
62
|
+
black src tests
|
|
63
|
+
|
|
64
|
+
# Sort imports
|
|
65
|
+
isort src tests
|
|
66
|
+
|
|
67
|
+
# Format everything
|
|
68
|
+
black src tests && isort src tests
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Type Checking
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
# Run mypy type checker
|
|
75
|
+
mypy src
|
|
76
|
+
|
|
77
|
+
# Check specific file
|
|
78
|
+
mypy src/mcp_proxy/models.py
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Linting
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
# Run flake8 linter
|
|
85
|
+
flake8 src tests
|
|
86
|
+
|
|
87
|
+
# Check specific file
|
|
88
|
+
flake8 src/mcp_proxy/models.py
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Running All Quality Checks
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
# Format, type check, and lint
|
|
95
|
+
black src tests && \
|
|
96
|
+
isort src tests && \
|
|
97
|
+
mypy src && \
|
|
98
|
+
flake8 src tests && \
|
|
99
|
+
pytest
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Code Style Guidelines
|
|
103
|
+
|
|
104
|
+
### Python Style
|
|
105
|
+
|
|
106
|
+
- Follow PEP 8 style guide
|
|
107
|
+
- Use Black for automatic formatting (line length: 88)
|
|
108
|
+
- Use isort for import sorting
|
|
109
|
+
- Use type hints for all function signatures
|
|
110
|
+
- Write docstrings for all public functions and classes
|
|
111
|
+
|
|
112
|
+
### Docstring Format
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
def function_name(param1: str, param2: int) -> bool:
|
|
116
|
+
"""Brief description of function.
|
|
117
|
+
|
|
118
|
+
Longer description if needed, explaining the purpose,
|
|
119
|
+
behavior, and any important details.
|
|
120
|
+
|
|
121
|
+
Args:
|
|
122
|
+
param1: Description of param1
|
|
123
|
+
param2: Description of param2
|
|
124
|
+
|
|
125
|
+
Returns:
|
|
126
|
+
Description of return value
|
|
127
|
+
|
|
128
|
+
Raises:
|
|
129
|
+
ExceptionType: When this exception is raised
|
|
130
|
+
"""
|
|
131
|
+
pass
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Type Hints
|
|
135
|
+
|
|
136
|
+
Always use type hints:
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
from typing import Optional, List, Dict
|
|
140
|
+
|
|
141
|
+
def process_data(
|
|
142
|
+
data: List[str],
|
|
143
|
+
config: Optional[Dict[str, Any]] = None
|
|
144
|
+
) -> bool:
|
|
145
|
+
...
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Error Handling
|
|
149
|
+
|
|
150
|
+
Use custom exceptions from `exceptions.py`:
|
|
151
|
+
|
|
152
|
+
```python
|
|
153
|
+
from mcp_proxy.exceptions import AuthenticationError, DcrError
|
|
154
|
+
|
|
155
|
+
def authenticate() -> None:
|
|
156
|
+
try:
|
|
157
|
+
# Authentication logic
|
|
158
|
+
pass
|
|
159
|
+
except Exception as e:
|
|
160
|
+
raise AuthenticationError("Authentication failed", details=str(e))
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## Testing Guidelines
|
|
164
|
+
|
|
165
|
+
### Unit Tests
|
|
166
|
+
|
|
167
|
+
- Test individual functions and classes
|
|
168
|
+
- Use fixtures from `conftest.py`
|
|
169
|
+
- Mock external dependencies
|
|
170
|
+
- Test both success and failure cases
|
|
171
|
+
|
|
172
|
+
Example:
|
|
173
|
+
```python
|
|
174
|
+
def test_valid_config(sample_config):
|
|
175
|
+
"""Test that valid configuration is accepted."""
|
|
176
|
+
assert sample_config.log_level == "info"
|
|
177
|
+
assert sample_config.retry_attempts == 3
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Property-Based Tests
|
|
181
|
+
|
|
182
|
+
- Use Hypothesis for property-based testing
|
|
183
|
+
- Test universal properties that should hold for all inputs
|
|
184
|
+
- Generate diverse test data
|
|
185
|
+
|
|
186
|
+
Example:
|
|
187
|
+
```python
|
|
188
|
+
from hypothesis import given, strategies as st
|
|
189
|
+
|
|
190
|
+
@given(st.text(), st.integers())
|
|
191
|
+
def test_message_correlation(request_id, http_id):
|
|
192
|
+
"""Test that message correlation works for any IDs."""
|
|
193
|
+
# Test logic
|
|
194
|
+
pass
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Test Organization
|
|
198
|
+
|
|
199
|
+
- Place tests in `tests/` directory
|
|
200
|
+
- Name test files `test_*.py`
|
|
201
|
+
- Name test functions `test_*`
|
|
202
|
+
- Group related tests in classes
|
|
203
|
+
- Use descriptive test names
|
|
204
|
+
|
|
205
|
+
## Logging
|
|
206
|
+
|
|
207
|
+
Use structured logging:
|
|
208
|
+
|
|
209
|
+
```python
|
|
210
|
+
from mcp_proxy.logging_config import get_logger
|
|
211
|
+
|
|
212
|
+
logger = get_logger(__name__)
|
|
213
|
+
|
|
214
|
+
logger.info("processing_request", request_id=123, method="tools/list")
|
|
215
|
+
logger.error("authentication_failed", error=str(e))
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## Debugging
|
|
219
|
+
|
|
220
|
+
### Enable Debug Logging
|
|
221
|
+
|
|
222
|
+
```python
|
|
223
|
+
from mcp_proxy.logging_config import configure_logging
|
|
224
|
+
|
|
225
|
+
configure_logging(log_level="debug")
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### Using Python Debugger
|
|
229
|
+
|
|
230
|
+
```python
|
|
231
|
+
import pdb; pdb.set_trace() # Set breakpoint
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### VS Code Debug Configuration
|
|
235
|
+
|
|
236
|
+
Create `.vscode/launch.json`:
|
|
237
|
+
|
|
238
|
+
```json
|
|
239
|
+
{
|
|
240
|
+
"version": "0.2.0",
|
|
241
|
+
"configurations": [
|
|
242
|
+
{
|
|
243
|
+
"name": "Python: Current File",
|
|
244
|
+
"type": "python",
|
|
245
|
+
"request": "launch",
|
|
246
|
+
"program": "${file}",
|
|
247
|
+
"console": "integratedTerminal",
|
|
248
|
+
"justMyCode": false
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
"name": "Python: Pytest",
|
|
252
|
+
"type": "python",
|
|
253
|
+
"request": "launch",
|
|
254
|
+
"module": "pytest",
|
|
255
|
+
"args": ["-v"],
|
|
256
|
+
"console": "integratedTerminal",
|
|
257
|
+
"justMyCode": false
|
|
258
|
+
}
|
|
259
|
+
]
|
|
260
|
+
}
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
## Common Development Tasks
|
|
264
|
+
|
|
265
|
+
### Adding a New Model
|
|
266
|
+
|
|
267
|
+
1. Define model in `src/mcp_proxy/models.py`
|
|
268
|
+
2. Add validation using Pydantic validators
|
|
269
|
+
3. Export from `src/mcp_proxy/__init__.py`
|
|
270
|
+
4. Write tests in `tests/test_models.py`
|
|
271
|
+
5. Update documentation
|
|
272
|
+
|
|
273
|
+
### Adding a New Exception
|
|
274
|
+
|
|
275
|
+
1. Define exception in `src/mcp_proxy/exceptions.py`
|
|
276
|
+
2. Inherit from appropriate base exception
|
|
277
|
+
3. Export from `src/mcp_proxy/__init__.py`
|
|
278
|
+
4. Update error code mapping if needed
|
|
279
|
+
5. Document when it's raised
|
|
280
|
+
|
|
281
|
+
### Adding a New Component
|
|
282
|
+
|
|
283
|
+
1. Create module directory under `src/mcp_proxy/`
|
|
284
|
+
2. Define protocol interface in `protocols.py`
|
|
285
|
+
3. Implement concrete class in module
|
|
286
|
+
4. Write unit tests
|
|
287
|
+
5. Write integration tests
|
|
288
|
+
6. Update documentation
|
|
289
|
+
|
|
290
|
+
## Git Workflow
|
|
291
|
+
|
|
292
|
+
### Commit Messages
|
|
293
|
+
|
|
294
|
+
Use conventional commit format:
|
|
295
|
+
|
|
296
|
+
```
|
|
297
|
+
type(scope): brief description
|
|
298
|
+
|
|
299
|
+
Longer description if needed
|
|
300
|
+
|
|
301
|
+
- Bullet points for details
|
|
302
|
+
- Reference issues: #123
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
Types:
|
|
306
|
+
- `feat`: New feature
|
|
307
|
+
- `fix`: Bug fix
|
|
308
|
+
- `docs`: Documentation
|
|
309
|
+
- `test`: Tests
|
|
310
|
+
- `refactor`: Code refactoring
|
|
311
|
+
- `style`: Code style changes
|
|
312
|
+
- `chore`: Maintenance tasks
|
|
313
|
+
|
|
314
|
+
### Branch Naming
|
|
315
|
+
|
|
316
|
+
- `feature/description`: New features
|
|
317
|
+
- `fix/description`: Bug fixes
|
|
318
|
+
- `docs/description`: Documentation
|
|
319
|
+
- `test/description`: Tests
|
|
320
|
+
|
|
321
|
+
## Troubleshooting
|
|
322
|
+
|
|
323
|
+
### Import Errors
|
|
324
|
+
|
|
325
|
+
If you get import errors, ensure the package is installed in editable mode:
|
|
326
|
+
|
|
327
|
+
```bash
|
|
328
|
+
pip install -e .
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
### Test Failures
|
|
332
|
+
|
|
333
|
+
1. Check test output for specific failure
|
|
334
|
+
2. Run single test: `pytest tests/test_file.py::test_name -v`
|
|
335
|
+
3. Enable debug logging in test
|
|
336
|
+
4. Use debugger to step through code
|
|
337
|
+
|
|
338
|
+
### Type Checking Errors
|
|
339
|
+
|
|
340
|
+
1. Ensure all functions have type hints
|
|
341
|
+
2. Check for missing imports
|
|
342
|
+
3. Use `# type: ignore` for known issues (sparingly)
|
|
343
|
+
4. Update type stubs if needed
|
|
344
|
+
|
|
345
|
+
## Resources
|
|
346
|
+
|
|
347
|
+
- [Pydantic Documentation](https://docs.pydantic.dev/)
|
|
348
|
+
- [Pytest Documentation](https://docs.pytest.org/)
|
|
349
|
+
- [Hypothesis Documentation](https://hypothesis.readthedocs.io/)
|
|
350
|
+
- [Structlog Documentation](https://www.structlog.org/)
|
|
351
|
+
- [aiohttp Documentation](https://docs.aiohttp.org/)
|
|
352
|
+
- [JSON-RPC 2.0 Specification](https://www.jsonrpc.org/specification)
|
|
353
|
+
- [OAuth 2.0 DCR (RFC 7591)](https://tools.ietf.org/html/rfc7591)
|
|
354
|
+
|
|
355
|
+
## Getting Help
|
|
356
|
+
|
|
357
|
+
- Check existing documentation
|
|
358
|
+
- Review test examples
|
|
359
|
+
- Ask in team chat
|
|
360
|
+
- Create an issue for bugs or feature requests
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 MCP Proxy Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# MANIFEST.in - Include additional files in the distribution package
|
|
2
|
+
# This ensures that non-Python files are included when building the package
|
|
3
|
+
|
|
4
|
+
# Include documentation files
|
|
5
|
+
include README.md
|
|
6
|
+
include LICENSE
|
|
7
|
+
include ARCHITECTURE.md
|
|
8
|
+
include DEVELOPMENT.md
|
|
9
|
+
include PROXY_USAGE.md
|
|
10
|
+
|
|
11
|
+
# Include example configuration files
|
|
12
|
+
include examples/.env.example
|
|
13
|
+
include examples/config.json.example
|
|
14
|
+
include examples/CLI_USAGE.md
|
|
15
|
+
|
|
16
|
+
# Include example scripts
|
|
17
|
+
include examples/run_proxy.py
|
|
18
|
+
include examples/authenticated_client_example.py
|
|
19
|
+
|
|
20
|
+
# Include type stubs if any
|
|
21
|
+
recursive-include src/mcp_proxy *.pyi
|
|
22
|
+
|
|
23
|
+
# Exclude unnecessary files from the distribution
|
|
24
|
+
global-exclude __pycache__
|
|
25
|
+
global-exclude *.py[co]
|
|
26
|
+
global-exclude .DS_Store
|
|
27
|
+
global-exclude *.so
|
|
28
|
+
global-exclude *.dylib
|
|
29
|
+
|
|
30
|
+
# Exclude test files
|
|
31
|
+
prune tests
|
|
32
|
+
prune .pytest_cache
|
|
33
|
+
prune htmlcov
|
|
34
|
+
|
|
35
|
+
# Exclude development files
|
|
36
|
+
exclude .coverage
|
|
37
|
+
exclude coverage.xml
|
|
38
|
+
exclude .gitignore
|
|
39
|
+
exclude verify_stdio_interface.py
|
|
40
|
+
prune .kiro
|
|
41
|
+
prune venv
|
|
42
|
+
prune .mypy_cache
|