mcp-refcache 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_refcache-0.1.0/.env.example +57 -0
- mcp_refcache-0.1.0/.gitignore +148 -0
- mcp_refcache-0.1.0/CHANGELOG.md +84 -0
- mcp_refcache-0.1.0/LICENSE +21 -0
- mcp_refcache-0.1.0/PKG-INFO +637 -0
- mcp_refcache-0.1.0/README.md +595 -0
- mcp_refcache-0.1.0/docker-compose.yml +117 -0
- mcp_refcache-0.1.0/pyproject.toml +259 -0
- mcp_refcache-0.1.0/src/mcp_refcache/__init__.py +157 -0
- mcp_refcache-0.1.0/src/mcp_refcache/access/__init__.py +79 -0
- mcp_refcache-0.1.0/src/mcp_refcache/access/actor.py +362 -0
- mcp_refcache-0.1.0/src/mcp_refcache/access/checker.py +421 -0
- mcp_refcache-0.1.0/src/mcp_refcache/access/namespace.py +354 -0
- mcp_refcache-0.1.0/src/mcp_refcache/backends/__init__.py +34 -0
- mcp_refcache-0.1.0/src/mcp_refcache/backends/base.py +135 -0
- mcp_refcache-0.1.0/src/mcp_refcache/backends/memory.py +158 -0
- mcp_refcache-0.1.0/src/mcp_refcache/backends/redis.py +451 -0
- mcp_refcache-0.1.0/src/mcp_refcache/backends/sqlite.py +424 -0
- mcp_refcache-0.1.0/src/mcp_refcache/cache.py +924 -0
- mcp_refcache-0.1.0/src/mcp_refcache/context.py +542 -0
- mcp_refcache-0.1.0/src/mcp_refcache/context_integration.py +308 -0
- mcp_refcache-0.1.0/src/mcp_refcache/fastmcp/__init__.py +68 -0
- mcp_refcache-0.1.0/src/mcp_refcache/fastmcp/admin_tools.py +774 -0
- mcp_refcache-0.1.0/src/mcp_refcache/fastmcp/instructions.py +480 -0
- mcp_refcache-0.1.0/src/mcp_refcache/models.py +210 -0
- mcp_refcache-0.1.0/src/mcp_refcache/permissions.py +146 -0
- mcp_refcache-0.1.0/src/mcp_refcache/preview.py +762 -0
- mcp_refcache-0.1.0/src/mcp_refcache/py.typed +0 -0
- mcp_refcache-0.1.0/src/mcp_refcache/resolution.py +390 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# mcp-refcache Configuration
|
|
2
|
+
# Copy this file to .env and customize as needed
|
|
3
|
+
|
|
4
|
+
# =============================================================================
|
|
5
|
+
# Cache Backend Configuration
|
|
6
|
+
# =============================================================================
|
|
7
|
+
|
|
8
|
+
# Cache backend type: memory | sqlite | redis (default: memory)
|
|
9
|
+
# CACHE_BACKEND=memory
|
|
10
|
+
|
|
11
|
+
# SQLite Backend Settings (when CACHE_BACKEND=sqlite)
|
|
12
|
+
# CACHE_SQLITE_PATH=cache.db
|
|
13
|
+
# CACHE_SQLITE_PATH=:memory: # For testing
|
|
14
|
+
|
|
15
|
+
# Redis/Valkey Backend Settings (when CACHE_BACKEND=redis)
|
|
16
|
+
# REDIS_URL=redis://localhost:6379/0
|
|
17
|
+
# REDIS_PASSWORD=
|
|
18
|
+
# REDIS_SSL=false
|
|
19
|
+
|
|
20
|
+
# =============================================================================
|
|
21
|
+
# Preview Configuration
|
|
22
|
+
# =============================================================================
|
|
23
|
+
|
|
24
|
+
# Maximum preview size in tokens (default: 1024)
|
|
25
|
+
# CACHE_PREVIEW_MAX_SIZE=1024
|
|
26
|
+
|
|
27
|
+
# Default preview strategy: sample | truncate | paginate (default: sample)
|
|
28
|
+
# CACHE_PREVIEW_STRATEGY=sample
|
|
29
|
+
|
|
30
|
+
# =============================================================================
|
|
31
|
+
# Namespace & TTL Configuration
|
|
32
|
+
# =============================================================================
|
|
33
|
+
|
|
34
|
+
# Default namespace for cached values (default: public)
|
|
35
|
+
# CACHE_DEFAULT_NAMESPACE=public
|
|
36
|
+
|
|
37
|
+
# Default TTL in seconds (default: 3600 = 1 hour)
|
|
38
|
+
# CACHE_DEFAULT_TTL=3600
|
|
39
|
+
|
|
40
|
+
# =============================================================================
|
|
41
|
+
# Langfuse Observability (optional)
|
|
42
|
+
# =============================================================================
|
|
43
|
+
|
|
44
|
+
# Enable Langfuse tracing
|
|
45
|
+
# LANGFUSE_PUBLIC_KEY=pk-lf-...
|
|
46
|
+
# LANGFUSE_SECRET_KEY=sk-lf-...
|
|
47
|
+
# LANGFUSE_HOST=https://cloud.langfuse.com
|
|
48
|
+
|
|
49
|
+
# =============================================================================
|
|
50
|
+
# Development & Debugging
|
|
51
|
+
# =============================================================================
|
|
52
|
+
|
|
53
|
+
# Log level: DEBUG | INFO | WARNING | ERROR (default: INFO)
|
|
54
|
+
# LOG_LEVEL=INFO
|
|
55
|
+
|
|
56
|
+
# Enable debug mode for verbose output
|
|
57
|
+
# DEBUG=false
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
archive
|
|
3
|
+
__MACOSX
|
|
4
|
+
|
|
5
|
+
__pycache__/
|
|
6
|
+
*.py[cod]
|
|
7
|
+
*$py.class
|
|
8
|
+
|
|
9
|
+
# C extensions
|
|
10
|
+
*.so
|
|
11
|
+
|
|
12
|
+
# Distribution / packaging
|
|
13
|
+
.Python
|
|
14
|
+
build/
|
|
15
|
+
develop-eggs/
|
|
16
|
+
dist/
|
|
17
|
+
downloads/
|
|
18
|
+
eggs/
|
|
19
|
+
.eggs/
|
|
20
|
+
lib/
|
|
21
|
+
lib64/
|
|
22
|
+
parts/
|
|
23
|
+
sdist/
|
|
24
|
+
var/
|
|
25
|
+
wheels/
|
|
26
|
+
share/python-wheels/
|
|
27
|
+
*.egg-info/
|
|
28
|
+
.installed.cfg
|
|
29
|
+
*.egg
|
|
30
|
+
MANIFEST
|
|
31
|
+
|
|
32
|
+
# PyInstaller
|
|
33
|
+
# Usually these files are written by a python script from a template
|
|
34
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
35
|
+
*.manifest
|
|
36
|
+
*.spec
|
|
37
|
+
|
|
38
|
+
# Installer logs
|
|
39
|
+
pip-log.txt
|
|
40
|
+
pip-delete-this-directory.txt
|
|
41
|
+
|
|
42
|
+
# Unit test / coverage reports
|
|
43
|
+
htmlcov/
|
|
44
|
+
.tox/
|
|
45
|
+
.nox/
|
|
46
|
+
.coverage
|
|
47
|
+
.coverage.*
|
|
48
|
+
.cache
|
|
49
|
+
nosetests.xml
|
|
50
|
+
coverage.xml
|
|
51
|
+
*.cover
|
|
52
|
+
*.py,cover
|
|
53
|
+
.hypothesis/
|
|
54
|
+
.pytest_cache/
|
|
55
|
+
cover/
|
|
56
|
+
|
|
57
|
+
# Translations
|
|
58
|
+
*.mo
|
|
59
|
+
*.pot
|
|
60
|
+
|
|
61
|
+
# Django stuff:
|
|
62
|
+
*.log
|
|
63
|
+
local_settings.py
|
|
64
|
+
db.sqlite3
|
|
65
|
+
db.sqlite3-journal
|
|
66
|
+
|
|
67
|
+
# Flask stuff:
|
|
68
|
+
instance/
|
|
69
|
+
.webassets-cache
|
|
70
|
+
|
|
71
|
+
# Scrapy stuff:
|
|
72
|
+
.scrapy
|
|
73
|
+
|
|
74
|
+
# Sphinx documentation
|
|
75
|
+
docs/_build/
|
|
76
|
+
|
|
77
|
+
# PyBuilder
|
|
78
|
+
.pybuilder/
|
|
79
|
+
target/
|
|
80
|
+
|
|
81
|
+
# Jupyter Notebook
|
|
82
|
+
.ipynb_checkpoints
|
|
83
|
+
|
|
84
|
+
# IPython
|
|
85
|
+
profile_default/
|
|
86
|
+
ipython_config.py
|
|
87
|
+
|
|
88
|
+
# pyenv
|
|
89
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
90
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
91
|
+
# .python-version
|
|
92
|
+
|
|
93
|
+
# pipenv
|
|
94
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
95
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
96
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
97
|
+
# install all needed dependencies.
|
|
98
|
+
#Pipfile.lock
|
|
99
|
+
|
|
100
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
|
101
|
+
__pypackages__/
|
|
102
|
+
|
|
103
|
+
# Celery stuff
|
|
104
|
+
celerybeat-schedule
|
|
105
|
+
celerybeat.pid
|
|
106
|
+
|
|
107
|
+
# SageMath parsed files
|
|
108
|
+
*.sage.py
|
|
109
|
+
|
|
110
|
+
# Environments
|
|
111
|
+
.env
|
|
112
|
+
.venv
|
|
113
|
+
env/
|
|
114
|
+
venv/
|
|
115
|
+
ENV/
|
|
116
|
+
env.bak/
|
|
117
|
+
venv.bak/
|
|
118
|
+
|
|
119
|
+
# Spyder project settings
|
|
120
|
+
.spyderproject
|
|
121
|
+
.spyproject
|
|
122
|
+
|
|
123
|
+
# Rope project settings
|
|
124
|
+
.ropeproject
|
|
125
|
+
|
|
126
|
+
# mkdocs documentation
|
|
127
|
+
/site
|
|
128
|
+
|
|
129
|
+
# mypy
|
|
130
|
+
.mypy_cache/
|
|
131
|
+
.dmypy.json
|
|
132
|
+
dmypy.json
|
|
133
|
+
|
|
134
|
+
# Pyre type checker
|
|
135
|
+
.pyre/
|
|
136
|
+
|
|
137
|
+
# pytype static type analyzer
|
|
138
|
+
.pytype/
|
|
139
|
+
|
|
140
|
+
# Cython debug symbols
|
|
141
|
+
cython_debug/
|
|
142
|
+
|
|
143
|
+
# PyCharm
|
|
144
|
+
# JetBrains specific template is maintainted in a separate JetBrains.gitignore that can
|
|
145
|
+
# be found at https://github.com/github/gitignore/blob/master/Global/JetBrains.gitignore
|
|
146
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
147
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
148
|
+
#.idea/
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
### Planned
|
|
11
|
+
- MCP template (cookiecutter/copier) for new servers with refcache
|
|
12
|
+
- Time series backend for financial data use cases (InfluxDB, TimescaleDB)
|
|
13
|
+
- Redis Cluster/Sentinel support for high availability
|
|
14
|
+
- Metrics/observability hooks (Prometheus, OpenTelemetry)
|
|
15
|
+
|
|
16
|
+
## [0.1.0] - 2025-01-XX
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
|
|
20
|
+
#### Core Features
|
|
21
|
+
- **Reference-based caching** - Large values stored by reference, returning previews to agents
|
|
22
|
+
- **`@cache.cached()` decorator** - Simple, Pythonic API for caching tool results
|
|
23
|
+
- **Namespace isolation** - Separate caches for `public`, `session:<id>`, `user:<id>`, custom scopes
|
|
24
|
+
- **Access control** - Fine-grained permissions (READ, WRITE, UPDATE, DELETE, EXECUTE)
|
|
25
|
+
- **Private computation** - EXECUTE permission enables blind computation without data exposure
|
|
26
|
+
- **Preview strategies** - Truncate, sample, or paginate large values
|
|
27
|
+
- **Cross-tool data flow** - References act as a "data bus" between MCP tools
|
|
28
|
+
|
|
29
|
+
#### Backends
|
|
30
|
+
- **MemoryBackend** - In-memory caching for testing and simple use cases
|
|
31
|
+
- **SQLiteBackend** - Persistent caching with zero external dependencies
|
|
32
|
+
- WAL mode for concurrent access
|
|
33
|
+
- Thread-safe with connection-per-thread model
|
|
34
|
+
- Cross-process reference sharing (multiple MCP servers on same machine)
|
|
35
|
+
- XDG-compliant default path (`~/.cache/mcp-refcache/cache.db`)
|
|
36
|
+
- Environment variable override (`MCP_REFCACHE_DB_PATH`)
|
|
37
|
+
- **RedisBackend** - Distributed caching for multi-user/multi-machine scenarios
|
|
38
|
+
- Valkey/Redis compatible
|
|
39
|
+
- Native TTL support via Redis expiration
|
|
40
|
+
- Connection pooling for thread safety
|
|
41
|
+
- Cross-tool reference sharing verified end-to-end
|
|
42
|
+
- Docker deployment example with Valkey
|
|
43
|
+
|
|
44
|
+
#### FastMCP Integration
|
|
45
|
+
- `@cache.cached()` decorator for automatic caching of tool results
|
|
46
|
+
- `cache.resolve()` for cross-tool reference resolution
|
|
47
|
+
- `cache.get()` for preview retrieval with pagination
|
|
48
|
+
- Admin tools for cache management (optional)
|
|
49
|
+
- Cache documentation helpers for tool descriptions
|
|
50
|
+
|
|
51
|
+
#### Examples
|
|
52
|
+
- `examples/mcp_server.py` - Scientific calculator with sequences and matrices
|
|
53
|
+
- `examples/langfuse_integration.py` - Calculator with Langfuse tracing + SQLite backend
|
|
54
|
+
- `examples/data_tools.py` - Data analysis tools demonstrating cross-tool references
|
|
55
|
+
- `examples/redis-docker/` - Docker Compose setup with Valkey + 2 MCP servers
|
|
56
|
+
|
|
57
|
+
#### Testing & CI
|
|
58
|
+
- 691+ tests with 80%+ code coverage
|
|
59
|
+
- Parametrized backend tests (Memory, SQLite, Redis)
|
|
60
|
+
- GitHub Actions CI for Python 3.10-3.13
|
|
61
|
+
- Security scanning with Trivy
|
|
62
|
+
- Automated release workflow
|
|
63
|
+
|
|
64
|
+
### Documentation
|
|
65
|
+
- Comprehensive README with installation and usage examples
|
|
66
|
+
- CONTRIBUTING.md with development guidelines
|
|
67
|
+
- Inline docstrings with examples for all public APIs
|
|
68
|
+
- Docker deployment documentation for Redis backend
|
|
69
|
+
|
|
70
|
+
## [0.0.1] - Initial Development
|
|
71
|
+
|
|
72
|
+
### Added
|
|
73
|
+
- Initial project scaffold
|
|
74
|
+
- Core reference-based caching system
|
|
75
|
+
- Memory backend with basic operations
|
|
76
|
+
- Preview generation (truncate, sample, paginate)
|
|
77
|
+
- Pydantic models for type safety
|
|
78
|
+
- Basic test suite
|
|
79
|
+
|
|
80
|
+
<!-- Uncomment when repository is public
|
|
81
|
+
[Unreleased]: https://github.com/l4b4r4b4b4/mcp-refcache/compare/v0.1.0...HEAD
|
|
82
|
+
[0.1.0]: https://github.com/l4b4r4b4b4/mcp-refcache/releases/tag/v0.1.0
|
|
83
|
+
[0.0.1]: https://github.com/l4b4r4b4b4/mcp-refcache/releases/tag/v0.0.1
|
|
84
|
+
-->
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 l4b4r4b4b4
|
|
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.
|