mcp-bcrp 0.1.1__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_bcrp-0.1.1/.github/workflows/ci.yml +68 -0
- mcp_bcrp-0.1.1/.github/workflows/publish.yml +31 -0
- mcp_bcrp-0.1.1/.gitignore +46 -0
- mcp_bcrp-0.1.1/CONTRIBUTING.md +47 -0
- mcp_bcrp-0.1.1/LICENSE +21 -0
- mcp_bcrp-0.1.1/PKG-INFO +353 -0
- mcp_bcrp-0.1.1/README.md +318 -0
- mcp_bcrp-0.1.1/examples/basic_usage.py +37 -0
- mcp_bcrp-0.1.1/mcp_bcrp/__init__.py +16 -0
- mcp_bcrp-0.1.1/mcp_bcrp/__main__.py +10 -0
- mcp_bcrp-0.1.1/mcp_bcrp/_version.py +34 -0
- mcp_bcrp-0.1.1/mcp_bcrp/client.py +312 -0
- mcp_bcrp-0.1.1/mcp_bcrp/search_engine.py +237 -0
- mcp_bcrp-0.1.1/mcp_bcrp/server.py +326 -0
- mcp_bcrp-0.1.1/mcp_bcrp.egg-info/PKG-INFO +353 -0
- mcp_bcrp-0.1.1/mcp_bcrp.egg-info/SOURCES.txt +22 -0
- mcp_bcrp-0.1.1/mcp_bcrp.egg-info/dependency_links.txt +1 -0
- mcp_bcrp-0.1.1/mcp_bcrp.egg-info/entry_points.txt +2 -0
- mcp_bcrp-0.1.1/mcp_bcrp.egg-info/requires.txt +9 -0
- mcp_bcrp-0.1.1/mcp_bcrp.egg-info/top_level.txt +1 -0
- mcp_bcrp-0.1.1/pyproject.toml +69 -0
- mcp_bcrp-0.1.1/run.py +10 -0
- mcp_bcrp-0.1.1/setup.cfg +4 -0
- mcp_bcrp-0.1.1/tests/test_basic.py +63 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main, master]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main, master]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
python-version: ["3.10", "3.11", "3.12"]
|
|
15
|
+
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
20
|
+
uses: actions/setup-python@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version: ${{ matrix.python-version }}
|
|
23
|
+
|
|
24
|
+
- name: Install dependencies
|
|
25
|
+
run: |
|
|
26
|
+
python -m pip install --upgrade pip
|
|
27
|
+
pip install -e ".[dev]"
|
|
28
|
+
|
|
29
|
+
- name: Lint with ruff
|
|
30
|
+
run: |
|
|
31
|
+
pip install ruff
|
|
32
|
+
ruff check mcp_bcrp/
|
|
33
|
+
|
|
34
|
+
- name: Type check with mypy
|
|
35
|
+
run: |
|
|
36
|
+
pip install mypy pandas-stubs types-requests
|
|
37
|
+
mypy mcp_bcrp/ --ignore-missing-imports || true
|
|
38
|
+
|
|
39
|
+
- name: Run tests
|
|
40
|
+
run: |
|
|
41
|
+
pip install pytest pytest-asyncio
|
|
42
|
+
pytest tests/ -v || echo "No tests found"
|
|
43
|
+
|
|
44
|
+
build:
|
|
45
|
+
runs-on: ubuntu-latest
|
|
46
|
+
needs: test
|
|
47
|
+
|
|
48
|
+
steps:
|
|
49
|
+
- uses: actions/checkout@v4
|
|
50
|
+
|
|
51
|
+
- name: Set up Python
|
|
52
|
+
uses: actions/setup-python@v5
|
|
53
|
+
with:
|
|
54
|
+
python-version: "3.11"
|
|
55
|
+
|
|
56
|
+
- name: Install build dependencies
|
|
57
|
+
run: |
|
|
58
|
+
python -m pip install --upgrade pip
|
|
59
|
+
pip install build
|
|
60
|
+
|
|
61
|
+
- name: Build package
|
|
62
|
+
run: python -m build
|
|
63
|
+
|
|
64
|
+
- name: Upload artifacts
|
|
65
|
+
uses: actions/upload-artifact@v4
|
|
66
|
+
with:
|
|
67
|
+
name: dist
|
|
68
|
+
path: dist/
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
publish:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
environment: release
|
|
11
|
+
permissions:
|
|
12
|
+
id-token: write
|
|
13
|
+
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
|
+
|
|
17
|
+
- name: Set up Python
|
|
18
|
+
uses: actions/setup-python@v5
|
|
19
|
+
with:
|
|
20
|
+
python-version: "3.11"
|
|
21
|
+
|
|
22
|
+
- name: Install build dependencies
|
|
23
|
+
run: |
|
|
24
|
+
python -m pip install --upgrade pip
|
|
25
|
+
pip install build
|
|
26
|
+
|
|
27
|
+
- name: Build package
|
|
28
|
+
run: python -m build
|
|
29
|
+
|
|
30
|
+
- name: Publish to PyPI
|
|
31
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# Distribution / packaging
|
|
7
|
+
*.egg-info/
|
|
8
|
+
dist/
|
|
9
|
+
build/
|
|
10
|
+
*.egg
|
|
11
|
+
|
|
12
|
+
# Virtual environments
|
|
13
|
+
venv/
|
|
14
|
+
.venv/
|
|
15
|
+
env/
|
|
16
|
+
|
|
17
|
+
# IDE
|
|
18
|
+
.vscode/
|
|
19
|
+
.idea/
|
|
20
|
+
*.swp
|
|
21
|
+
|
|
22
|
+
# OS
|
|
23
|
+
.DS_Store
|
|
24
|
+
Thumbs.db
|
|
25
|
+
|
|
26
|
+
# Project specific
|
|
27
|
+
bcrp_cache/
|
|
28
|
+
bcrp_metadata.json
|
|
29
|
+
*.log
|
|
30
|
+
|
|
31
|
+
# Generated charts (local testing)
|
|
32
|
+
*.png
|
|
33
|
+
|
|
34
|
+
# Jupyter
|
|
35
|
+
.ipynb_checkpoints/
|
|
36
|
+
|
|
37
|
+
# Testing
|
|
38
|
+
.pytest_cache/
|
|
39
|
+
.coverage
|
|
40
|
+
htmlcov/
|
|
41
|
+
|
|
42
|
+
# MyPy
|
|
43
|
+
.mypy_cache/
|
|
44
|
+
|
|
45
|
+
# Ruff
|
|
46
|
+
.ruff_cache/
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Contributing to mcp-bcrp
|
|
2
|
+
|
|
3
|
+
Thank you for your interest in contributing! This project follows a simple contribution workflow.
|
|
4
|
+
|
|
5
|
+
## Development Setup
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Clone the repository
|
|
9
|
+
git clone https://github.com/MaykolMedrano/mcp-bcrp.git
|
|
10
|
+
cd mcp-bcrp
|
|
11
|
+
|
|
12
|
+
# Create virtual environment
|
|
13
|
+
python -m venv venv
|
|
14
|
+
venv\Scripts\activate # Windows
|
|
15
|
+
# source venv/bin/activate # Linux/Mac
|
|
16
|
+
|
|
17
|
+
# Install in development mode with test dependencies
|
|
18
|
+
pip install -e ".[dev]"
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Running Tests
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pytest tests/ -v
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Code Style
|
|
28
|
+
|
|
29
|
+
- Use type hints where possible
|
|
30
|
+
- Follow PEP 8 conventions
|
|
31
|
+
- Keep functions focused and document complex logic
|
|
32
|
+
|
|
33
|
+
## Pull Request Process
|
|
34
|
+
|
|
35
|
+
1. Fork the repository
|
|
36
|
+
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
|
37
|
+
3. Commit your changes (`git commit -m 'Add amazing feature'`)
|
|
38
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
39
|
+
5. Open a Pull Request
|
|
40
|
+
|
|
41
|
+
## Reporting Issues
|
|
42
|
+
|
|
43
|
+
Please use GitHub Issues and include:
|
|
44
|
+
- Clear description of the problem
|
|
45
|
+
- Steps to reproduce
|
|
46
|
+
- Expected vs actual behavior
|
|
47
|
+
- Python version and OS
|
mcp_bcrp-0.1.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025
|
|
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.
|
mcp_bcrp-0.1.1/PKG-INFO
ADDED
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mcp-bcrp
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: MCP Server for Banco Central de Reserva del Perú (BCRP) Statistical API
|
|
5
|
+
Author-email: Maykol Medrano <mmedrano2@uc.cl>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/MaykolMedrano/mcp_bcrp
|
|
8
|
+
Project-URL: Repository, https://github.com/MaykolMedrano/mcp_bcrp
|
|
9
|
+
Project-URL: Issues, https://github.com/MaykolMedrano/mcp_bcrp/issues
|
|
10
|
+
Keywords: mcp,bcrp,peru,macroeconomics,central-bank,api,economics,statistics
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: Office/Business :: Financial
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Requires-Dist: fastmcp>=0.1.0
|
|
27
|
+
Requires-Dist: pandas>=1.3.0
|
|
28
|
+
Requires-Dist: openpyxl>=3.0.0
|
|
29
|
+
Requires-Dist: httpx>=0.23.0
|
|
30
|
+
Requires-Dist: rapidfuzz>=3.0.0
|
|
31
|
+
Provides-Extra: dev
|
|
32
|
+
Requires-Dist: pytest; extra == "dev"
|
|
33
|
+
Requires-Dist: pytest-asyncio; extra == "dev"
|
|
34
|
+
Dynamic: license-file
|
|
35
|
+
|
|
36
|
+
# mcp-bcrp
|
|
37
|
+
|
|
38
|
+
[](https://www.python.org/downloads/)
|
|
39
|
+
[](https://opensource.org/licenses/MIT)
|
|
40
|
+
[](https://modelcontextprotocol.io/)
|
|
41
|
+
[](https://estadisticas.bcrp.gob.pe/)
|
|
42
|
+
[](https://github.com/psf/black)
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
**MCP Server for Banco Central de Reserva del Peru (BCRP) Statistical API**
|
|
47
|
+
|
|
48
|
+
A Model Context Protocol (MCP) server providing programmatic access to Peru's official macroeconomic statistics. This library enables AI assistants and Python applications to query over 5,000 economic indicators directly from the Central Reserve Bank of Peru.
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## Table of Contents
|
|
53
|
+
|
|
54
|
+
- [Overview](#overview)
|
|
55
|
+
- [Features](#features)
|
|
56
|
+
- [Requirements](#requirements)
|
|
57
|
+
- [Installation](#installation)
|
|
58
|
+
- [Configuration](#configuration)
|
|
59
|
+
- [Usage](#usage)
|
|
60
|
+
- [MCP Server](#as-mcp-server)
|
|
61
|
+
- [Python Library](#as-python-library)
|
|
62
|
+
- [Available Tools](#available-tools-mcp)
|
|
63
|
+
- [Key Indicators](#key-indicators)
|
|
64
|
+
- [Search Engine](#search-engine)
|
|
65
|
+
- [Architecture](#architecture)
|
|
66
|
+
- [Limitations and Warnings](#limitations-and-warnings)
|
|
67
|
+
- [Contributing](#contributing)
|
|
68
|
+
- [License](#license)
|
|
69
|
+
- [Acknowledgments](#acknowledgments)
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## Overview
|
|
74
|
+
|
|
75
|
+
The `mcp-bcrp` package provides a standardized interface to the BCRP statistical database through the Model Context Protocol (MCP). It supports both direct Python usage and integration with AI assistants such as Claude, Gemini, and other MCP-compatible agents.
|
|
76
|
+
|
|
77
|
+
The library implements:
|
|
78
|
+
- Asynchronous HTTP client for efficient data retrieval
|
|
79
|
+
- Deterministic search engine with fuzzy matching capabilities
|
|
80
|
+
- Spanish language processing for query canonicalization
|
|
81
|
+
- Automatic frequency detection (daily, monthly, quarterly, annual)
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## Features
|
|
86
|
+
|
|
87
|
+
| Feature | Description |
|
|
88
|
+
|---------|-------------|
|
|
89
|
+
| **Smart Search** | Deterministic search engine with fuzzy matching, attribute extraction, and ambiguity detection |
|
|
90
|
+
| **Async Native** | Built on `httpx` for non-blocking HTTP requests with connection pooling |
|
|
91
|
+
| **Dual Interface** | Use as MCP server for AI agents or as standalone Python library |
|
|
92
|
+
| **Chart Generation** | Generate publication-ready charts with automatic Spanish date parsing |
|
|
93
|
+
| **Full Coverage** | Access to 5,000+ BCRP economic indicators across all categories |
|
|
94
|
+
| **Metadata Cache** | Local caching of 17MB metadata file for fast offline searches |
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## Requirements
|
|
99
|
+
|
|
100
|
+
- Python 3.10 or higher
|
|
101
|
+
- Internet connection for API requests
|
|
102
|
+
- Dependencies: `httpx`, `pandas`, `fastmcp`, `rapidfuzz`, `matplotlib`
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## Installation
|
|
107
|
+
|
|
108
|
+
### From PyPI (when published)
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
pip install mcp-bcrp
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### From Source
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
git clone https://github.com/YOUR_USERNAME/mcp-bcrp.git
|
|
118
|
+
cd mcp-bcrp
|
|
119
|
+
pip install -e .
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### With Optional Dependencies
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
pip install mcp-bcrp[charts] # Include matplotlib for chart generation
|
|
126
|
+
pip install mcp-bcrp[dev] # Include development dependencies
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## Configuration
|
|
132
|
+
|
|
133
|
+
### MCP Server Configuration
|
|
134
|
+
|
|
135
|
+
Add the following to your MCP configuration file (e.g., `mcp_config.json`):
|
|
136
|
+
|
|
137
|
+
```json
|
|
138
|
+
{
|
|
139
|
+
"mcpServers": {
|
|
140
|
+
"bcrp-api": {
|
|
141
|
+
"command": "python",
|
|
142
|
+
"args": ["C:/absolute/path/to/mcp_bcrp/run.py"]
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
> [!TIP]
|
|
149
|
+
> If you have installed the package via pip, you can also use `["-m", "mcp_bcrp"]` as the arguments.
|
|
150
|
+
|
|
151
|
+
### Environment Variables
|
|
152
|
+
|
|
153
|
+
| Variable | Description | Default |
|
|
154
|
+
|----------|-------------|---------|
|
|
155
|
+
| `BCRP_CACHE_DIR` | Directory for metadata cache | User cache dir |
|
|
156
|
+
| `BCRP_TIMEOUT` | HTTP request timeout in seconds | 120 |
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## Usage
|
|
161
|
+
|
|
162
|
+
### As MCP Server
|
|
163
|
+
|
|
164
|
+
Once configured, the server can be invoked by MCP-compatible AI assistants:
|
|
165
|
+
|
|
166
|
+
```
|
|
167
|
+
User: What is the current policy interest rate in Peru?
|
|
168
|
+
Agent: [calls search_series("tasa politica monetaria")]
|
|
169
|
+
Agent: [calls get_data(["PD04722MM"], "2024-01/2025-01")]
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### As Python Library
|
|
173
|
+
|
|
174
|
+
```python
|
|
175
|
+
import asyncio
|
|
176
|
+
from mcp_bcrp.client import AsyncBCRPClient, BCRPMetadata
|
|
177
|
+
|
|
178
|
+
async def main():
|
|
179
|
+
# Initialize metadata client
|
|
180
|
+
metadata = BCRPMetadata()
|
|
181
|
+
await metadata.load()
|
|
182
|
+
|
|
183
|
+
# Search for an indicator (deterministic)
|
|
184
|
+
result = metadata.solve("tasa politica monetaria")
|
|
185
|
+
print(result)
|
|
186
|
+
# Output: {'codigo_serie': 'PD04722MM', 'confidence': 1.0, ...}
|
|
187
|
+
|
|
188
|
+
# Fetch time series data
|
|
189
|
+
client = AsyncBCRPClient()
|
|
190
|
+
df = await client.get_series(
|
|
191
|
+
series_codes=["PD04722MM"],
|
|
192
|
+
start_date="2024-01",
|
|
193
|
+
end_date="2025-01"
|
|
194
|
+
)
|
|
195
|
+
print(df.head())
|
|
196
|
+
|
|
197
|
+
asyncio.run(main())
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
## Available Tools (MCP)
|
|
203
|
+
|
|
204
|
+
| Tool | Parameters | Description |
|
|
205
|
+
|------|------------|-------------|
|
|
206
|
+
| `search_series` | `query: str` | Search BCRP indicators by keyword. Returns deterministic match or ambiguity error. |
|
|
207
|
+
| `get_data` | `series_codes: list[str]`, `period: str` | Fetch raw time series data. Period format: `YYYY-MM/YYYY-MM`. |
|
|
208
|
+
| `get_table` | `series_codes: list[str]`, `names: list[str]`, `period: str` | Get formatted table with optional custom column names. |
|
|
209
|
+
| `plot_chart` | `series_codes: list[str]`, `period: str`, `title: str`, `names: list[str]`, `output_path: str` | Generate professional PNG chart with automatic date parsing. |
|
|
210
|
+
|
|
211
|
+
### Available Prompts
|
|
212
|
+
|
|
213
|
+
| Prompt | Description |
|
|
214
|
+
|--------|-------------|
|
|
215
|
+
| `economista_peruano` | System prompt to analyze data as a BCRP Senior Economist with rigorous methodology |
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
## Key Indicators
|
|
220
|
+
|
|
221
|
+
The following are commonly used indicator codes:
|
|
222
|
+
|
|
223
|
+
| Category | Code | Description | Frequency |
|
|
224
|
+
|----------|------|-------------|-----------|
|
|
225
|
+
| Monetary Policy | `PD04722MM` | Reference Interest Rate | Monthly |
|
|
226
|
+
| Exchange Rate | `PD04638PD` | Interbank Exchange Rate (Sell) | Daily |
|
|
227
|
+
| Inflation | `PN01270PM` | CPI Lima Metropolitan | Monthly |
|
|
228
|
+
| Copper Price | `PN01652XM` | International Copper Price (c/lb) | Monthly |
|
|
229
|
+
| GDP Growth | `PN01713AM` | Agricultural GDP (Var. %) | Annual |
|
|
230
|
+
| Business Expectations | `PD38048AM` | GDP Expectations 12 months | Monthly |
|
|
231
|
+
| International Reserves | `PN00015MM` | Net International Reserves | Monthly |
|
|
232
|
+
|
|
233
|
+
> [!NOTE]
|
|
234
|
+
> Series codes follow the BCRP naming convention. Use `search_series` to find the appropriate code for your query.
|
|
235
|
+
|
|
236
|
+
---
|
|
237
|
+
|
|
238
|
+
## Search Engine
|
|
239
|
+
|
|
240
|
+
The search engine implements a deterministic pipeline designed for high precision:
|
|
241
|
+
|
|
242
|
+
```
|
|
243
|
+
Query Input
|
|
244
|
+
│
|
|
245
|
+
▼
|
|
246
|
+
┌─────────────────────────────┐
|
|
247
|
+
│ 1. Canonicalization │ Lowercase, remove accents, filter stopwords
|
|
248
|
+
└─────────────────────────────┘
|
|
249
|
+
│
|
|
250
|
+
▼
|
|
251
|
+
┌─────────────────────────────┐
|
|
252
|
+
│ 2. Attribute Extraction │ Currency (USD/PEN), horizon, component type
|
|
253
|
+
└─────────────────────────────┘
|
|
254
|
+
│
|
|
255
|
+
▼
|
|
256
|
+
┌─────────────────────────────┐
|
|
257
|
+
│ 3. Hard Filters │ Eliminate series not matching attributes
|
|
258
|
+
└─────────────────────────────┘
|
|
259
|
+
│
|
|
260
|
+
▼
|
|
261
|
+
┌─────────────────────────────┐
|
|
262
|
+
│ 4. Fuzzy Scoring │ Token sort ratio using RapidFuzz
|
|
263
|
+
└─────────────────────────────┘
|
|
264
|
+
│
|
|
265
|
+
▼
|
|
266
|
+
┌─────────────────────────────┐
|
|
267
|
+
│ 5. Ambiguity Detection │ Return error if top matches are too close
|
|
268
|
+
└─────────────────────────────┘
|
|
269
|
+
│
|
|
270
|
+
▼
|
|
271
|
+
Deterministic Result or Explicit Ambiguity Error
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
---
|
|
275
|
+
|
|
276
|
+
## Architecture
|
|
277
|
+
|
|
278
|
+
```
|
|
279
|
+
mcp_bcrp/
|
|
280
|
+
├── __init__.py # Package initialization and version
|
|
281
|
+
├── server.py # FastMCP server with tool definitions
|
|
282
|
+
├── client.py # AsyncBCRPClient and BCRPMetadata classes
|
|
283
|
+
└── search_engine.py # Deterministic search pipeline implementation
|
|
284
|
+
|
|
285
|
+
run.py # MCP server entry point
|
|
286
|
+
bcrp_metadata.json # Cached metadata (17MB, auto-downloaded)
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
## Limitations and Warnings
|
|
292
|
+
|
|
293
|
+
> [!WARNING]
|
|
294
|
+
> **API Rate Limits**: The BCRP API does not publish official rate limits. Implement appropriate delays between requests in production applications to avoid IP blocking.
|
|
295
|
+
|
|
296
|
+
> [!WARNING]
|
|
297
|
+
> **Data Freshness**: Metadata cache (`bcrp_metadata.json`) may become stale. Delete the file periodically to force a refresh of available indicators.
|
|
298
|
+
|
|
299
|
+
> [!CAUTION]
|
|
300
|
+
> **Unofficial Package**: This is an independent implementation and is not officially endorsed by the Banco Central de Reserva del Peru. Data accuracy depends on the upstream API.
|
|
301
|
+
|
|
302
|
+
### Known Limitations
|
|
303
|
+
|
|
304
|
+
1. **Date Format**: The BCRP API returns dates in Spanish format (e.g., "Ene.2024"). The library handles this automatically, but custom date parsing may be required for edge cases.
|
|
305
|
+
|
|
306
|
+
2. **Series Availability**: Not all series are available for all time periods. The API returns empty responses for unavailable date ranges.
|
|
307
|
+
|
|
308
|
+
3. **Metadata Size**: The complete metadata file is approximately 17MB. Initial load may take several seconds on slow connections.
|
|
309
|
+
|
|
310
|
+
4. **Frequency Detection**: The library attempts to auto-detect series frequency, but some series may require explicit specification.
|
|
311
|
+
|
|
312
|
+
---
|
|
313
|
+
|
|
314
|
+
## Contributing
|
|
315
|
+
|
|
316
|
+
Contributions are welcome. Please follow these guidelines:
|
|
317
|
+
|
|
318
|
+
1. Fork the repository
|
|
319
|
+
2. Create a feature branch (`git checkout -b feature/improvement`)
|
|
320
|
+
3. Commit changes with descriptive messages
|
|
321
|
+
4. Ensure all tests pass (`pytest`)
|
|
322
|
+
5. Submit a pull request
|
|
323
|
+
|
|
324
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed guidelines.
|
|
325
|
+
|
|
326
|
+
---
|
|
327
|
+
|
|
328
|
+
## License
|
|
329
|
+
|
|
330
|
+
This project is licensed under the MIT License. See [LICENSE](LICENSE) for the full text.
|
|
331
|
+
|
|
332
|
+
---
|
|
333
|
+
|
|
334
|
+
## Acknowledgments
|
|
335
|
+
|
|
336
|
+
- [Banco Central de Reserva del Peru](https://www.bcrp.gob.pe/) for providing the public statistical API
|
|
337
|
+
- [FastMCP](https://github.com/jlowin/fastmcp) for the Model Context Protocol framework
|
|
338
|
+
- [RapidFuzz](https://github.com/maxbachmann/RapidFuzz) for fuzzy string matching
|
|
339
|
+
- [usebcrp](https://github.com/mauricioalvaradoo/usebcrp) for inspiration on BCRP API integration
|
|
340
|
+
|
|
341
|
+
---
|
|
342
|
+
|
|
343
|
+
## See Also
|
|
344
|
+
|
|
345
|
+
| Project | Description |
|
|
346
|
+
|---------|-------------|
|
|
347
|
+
| [wbgapi360](https://github.com/MaykolMedrano/mcp_wbgapi360) | Enterprise-grade MCP Client for World Bank Data API. Provides access to World Development Indicators, global rankings, country comparisons, and professional FT-style visualizations. |
|
|
348
|
+
|
|
349
|
+
Both libraries can be used together to build comprehensive macroeconomic analysis pipelines combining Peru-specific BCRP data with global World Bank indicators.
|
|
350
|
+
|
|
351
|
+
---
|
|
352
|
+
|
|
353
|
+
**Disclaimer**: This software is provided "as is" without warranty of any kind. The authors are not responsible for any errors in the data or any decisions made based on the information provided by this library.
|