ccapi-mcp-server: Schema cache directory is hardcoded relative to __file__, fails on read-only filesystems
- Dominant language
- Python
- Stars
- 9.7k
- Forks
- 1.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 50
Description
### Describe the bug
`SchemaManager.__init__()` in `schema_manager.py` hardcodes the cache directory relative to `__file__`:
```python
cache_dir = os.path.join(os.path.dirname(__file__), '.schemas')
self.cache_dir = Path(cache_dir)
self.cache_dir.mkdir(exist_ok=True)
```
This fails with `PermissionError` when the package is installed to a read-only filesystem (e.g., AWS Lambda `/var/task/`, container images with a non-root user, or any read-only deployment target). Because `SchemaManager` is instantiated as a module-level singleton, the error occurs at import time before any application code can intervene.
### Expected Behavior
The schema cache directory should be writable regardless of where the package is installed. The server should support configuring the cache location via an environment variable, or default to a platform-appropriate writable directory (e.g., `tempfile.gettempdir()` or `platformdirs.user_cache_dir()`).
### Current Behavior
```
PermissionError: [Errno 13] Permission denied: '/var/task/awslabs/ccapi_mcp_server/.schemas'
```
The server crashes on startup. No environment variable or configuration option exists to override the cache path.
### Reproduction Steps
```bash
# Install ccapi-mcp-server to a read-only location
pip install awslabs.ccapi-mcp-server --target /opt/readonly-packages
chmod -R a-w /opt/readonly-packages
# Attempt to import — fails immediately
PYTHONPATH=/opt/readonly-packages python -c "from awslabs.ccapi_mcp_server import server"
# PermissionError: [Errno 13] Permission denied: '/opt/readonly-packages/awslabs/ccapi_mcp_server/.schemas'
```
### Possible Solution
Add an environment variable override and fall back to a writable temp directory. For example in `schema_manager.py`:
```python
class SchemaManager:
def __init__(self):
cache_dir = os.environ.get(
'CCAPI_SCHEMA_CACHE_DIR',
os.path.join(os.path.dirname(__file__), '.schemas')
)
self.cache_dir = Path(cache_dir)
self.cache_dir.mkdir(exist_ok=True)
```
This is backwards-compatible — existing installations continue to use `.schemas` relative to the package, while read-only deployments can set `CCAPI_SCHEMA_CACHE_DIR=/tmp/.ccapi_schemas`.
### Additional Information/Context
The issue affects any deployment where `site-packages` is read-only: AWS Lambda, read-only container images, AWS Bedrock AgentCore direct_code_deploy, and similar serverless/immutable deployment targets. The workaround currently requires monkey-patching `os.path.dirname` before importing the module, which is fragile.
### Server
ccapi-mcp-server
### Server Version
1.0.15 (also confirmed in 1.0.10)
### OS
Linux (Amazon Linux 2023, Debian Bookworm)
### Region
us-west-2
Contributor guide
Research direction
Start in schema_manager.py at SchemaManager.__init__ and inspect how the module-level singleton is created during import. Reproduce the read-only installation case, then verify that the cache location can be configured or defaults to a writable directory and that importing awslabs.ccapi_mcp_server.server no longer raises PermissionError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100