Skip to content

Commit 4208ead

Browse files
committed
streamlit
1 parent c08cf45 commit 4208ead

7 files changed

Lines changed: 1150 additions & 1 deletion

File tree

run_streamlit.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Launch script for RMCP Streamlit app
4+
"""
5+
6+
import subprocess
7+
import sys
8+
import os
9+
10+
def main():
11+
"""Launch the Streamlit app"""
12+
app_path = os.path.join(os.path.dirname(__file__), "streamlit_app.py")
13+
14+
try:
15+
# Launch Streamlit
16+
subprocess.run([
17+
sys.executable, "-m", "streamlit", "run", app_path,
18+
"--server.headless", "false",
19+
"--server.port", "8501"
20+
], check=True)
21+
except subprocess.CalledProcessError as e:
22+
print(f"Error launching Streamlit: {e}")
23+
sys.exit(1)
24+
except KeyboardInterrupt:
25+
print("\nShutting down Streamlit app...")
26+
sys.exit(0)
27+
28+
if __name__ == "__main__":
29+
main()

src/rmcp/core/server.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,44 @@ async def cancel_request(self, request_id: str) -> None:
283283
self._active_requests[request_id].cancel()
284284
logger.info(f"Cancelled request {request_id}")
285285

286+
async def _handle_initialize(self, params: Dict[str, Any]) -> Dict[str, Any]:
287+
"""
288+
Handle MCP initialize request.
289+
290+
Returns server capabilities and metadata according to MCP protocol.
291+
292+
Args:
293+
params: Initialize parameters from client
294+
295+
Returns:
296+
Initialize response with server capabilities
297+
"""
298+
client_info = params.get("clientInfo", {})
299+
logger.info(f"Initializing MCP connection with client: {client_info.get('name', 'unknown')}")
300+
301+
return {
302+
"protocolVersion": "2024-11-05",
303+
"capabilities": {
304+
"tools": {
305+
"listChanged": False
306+
},
307+
"resources": {
308+
"subscribe": False,
309+
"listChanged": False
310+
},
311+
"prompts": {
312+
"listChanged": False
313+
},
314+
"logging": {
315+
"level": "info"
316+
}
317+
},
318+
"serverInfo": {
319+
"name": self.name,
320+
"version": self.version
321+
}
322+
}
323+
286324
async def handle_request(self, request: Dict[str, Any]) -> Optional[Dict[str, Any]]:
287325
"""
288326
Handle incoming MCP request and route to appropriate handler.
@@ -300,6 +338,7 @@ async def handle_request(self, request: Dict[str, Any]) -> Optional[Dict[str, An
300338
JSON-RPC response dict or None for notifications
301339
302340
Supported methods:
341+
- initialize: Initialize MCP connection and return capabilities
303342
- tools/list: List available tools
304343
- tools/call: Execute a tool with parameters
305344
- resources/list: List available resources
@@ -320,7 +359,9 @@ async def handle_request(self, request: Dict[str, Any]) -> Optional[Dict[str, An
320359
context = self.create_context(request_id, method)
321360

322361
# Route to appropriate handler
323-
if method == "tools/list":
362+
if method == "initialize":
363+
result = await self._handle_initialize(params)
364+
elif method == "tools/list":
324365
result = await self.tools.list_tools(context)
325366
elif method == "tools/call":
326367
tool_name = params.get("name")

streamlit/.streamlit/config.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[theme]
2+
primaryColor = "#FF6B6B"
3+
backgroundColor = "#FFFFFF"
4+
secondaryBackgroundColor = "#F0F2F6"
5+
textColor = "#262730"
6+
7+
[server]
8+
headless = true
9+
enableCORS = false
10+
enableXsrfProtection = false
11+
12+
[browser]
13+
gatherUsageStats = false

streamlit/README.md

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
# RMCP Streamlit Cloud Demo
2+
3+
An interactive web interface demonstrating RMCP's econometric capabilities with Claude AI integration.
4+
5+
## 🌐 Live Demo
6+
7+
**🚀 Try it now:** [RMCP on Streamlit Cloud](https://your-app-url.streamlit.app)
8+
9+
## 🔧 Local Development
10+
11+
1. **Install Dependencies:**
12+
```bash
13+
pip install -r requirements.txt
14+
```
15+
16+
2. **Run the App:**
17+
```bash
18+
streamlit run app.py
19+
```
20+
21+
3. **Open in Browser:**
22+
- Navigate to http://localhost:8501
23+
24+
## ☁️ Deploy to Streamlit Community Cloud
25+
26+
1. **Fork this repository**
27+
2. **Connect to Streamlit Cloud:**
28+
- Go to [share.streamlit.io](https://share.streamlit.io)
29+
- Connect your GitHub account
30+
- Select this repository
31+
- Set main file path: `streamlit/app.py`
32+
3. **Deploy!**
33+
34+
## 🔧 Setup
35+
36+
### Claude API Key
37+
1. Get your API key from [Claude Console](https://console.anthropic.com/)
38+
2. Enter it in the sidebar when the app starts
39+
3. The key is stored only for your session (not saved)
40+
41+
### Data Upload
42+
- Upload CSV files with your data
43+
- The app will show a preview and data information
44+
- All analyses work with your uploaded data
45+
46+
## 📊 Available Tools
47+
48+
### 📈 Descriptive Statistics
49+
- **Summary Statistics**: Mean, median, mode, variance, etc.
50+
- **Correlation Analysis**: Pearson and Spearman correlations
51+
- **Outlier Detection**: Identify and analyze outliers
52+
53+
### 📊 Regression Analysis
54+
- **Linear Regression**: Simple and multiple regression
55+
- **Logistic Regression**: Binary outcome modeling
56+
- **Panel Regression**: Fixed effects, random effects
57+
58+
### 🧪 Statistical Tests
59+
- **T-Tests**: One-sample, two-sample, paired
60+
- **Chi-Square Tests**: Independence testing
61+
- **Normality Tests**: Shapiro-Wilk, Kolmogorov-Smirnov
62+
- **Stationarity Tests**: Augmented Dickey-Fuller
63+
64+
### 📉 Time Series Analysis
65+
- **ARIMA Models**: Autoregressive integrated moving average
66+
- **VAR Models**: Vector autoregression
67+
- **Forecasting**: Time series predictions
68+
- **Cointegration Tests**: Long-run relationships
69+
70+
### 🔄 Data Transformations
71+
- **Lag Variables**: Create lagged versions
72+
- **Difference Variables**: First/second differences
73+
- **Winsorization**: Outlier treatment
74+
- **Standardization**: Z-score, min-max scaling
75+
76+
### 📊 Visualizations
77+
- **Scatter Plots**: With trend lines and grouping
78+
- **Time Series Plots**: Multiple variables over time
79+
- **Histograms**: Distribution analysis
80+
- **Correlation Heatmaps**: Visual correlation matrices
81+
82+
### 🎯 Advanced Econometrics
83+
- **Instrumental Variables**: 2SLS estimation
84+
- **Panel Fixed Effects**: Within-group estimation
85+
- **Difference-in-Differences**: Causal inference
86+
- **Regression Discontinuity**: Threshold effects
87+
88+
### 🤖 Machine Learning
89+
- **Random Forest**: Ensemble modeling
90+
- **Decision Trees**: Classification and regression
91+
- **Clustering**: K-means, hierarchical
92+
- **PCA Analysis**: Dimensionality reduction
93+
94+
## 🤖 Claude AI Assistant
95+
96+
The built-in Claude AI assistant can help you:
97+
- Choose appropriate statistical methods
98+
- Interpret analysis results
99+
- Suggest next steps in your research
100+
- Explain complex statistical concepts
101+
102+
Simply ask questions like:
103+
- "What regression method should I use for this data?"
104+
- "How do I interpret these coefficients?"
105+
- "What does this p-value mean?"
106+
107+
## 📁 Example Data
108+
109+
The app works with any CSV file. Your data should have:
110+
- Column headers in the first row
111+
- Numeric variables for quantitative analysis
112+
- Categorical variables for grouping/factors
113+
- Time variables in standard formats (for time series)
114+
115+
## 🔒 Privacy & Security
116+
117+
- All analysis runs locally with your R installation
118+
- Data is processed temporarily and not stored
119+
- Claude API key is session-only (not saved)
120+
- Uploaded files are automatically cleaned up
121+
122+
## 🛠️ Technical Details
123+
124+
- **Backend**: R statistical computing via subprocess
125+
- **Frontend**: Streamlit web interface
126+
- **AI Integration**: Anthropic Claude API
127+
- **Data Processing**: Pandas DataFrames
128+
- **Visualization**: R ggplot2 + Plotly integration
129+
130+
## 📞 Support
131+
132+
- Check the troubleshooting guide in `docs/troubleshooting.md`
133+
- Report issues on GitHub
134+
- Consult R documentation for statistical methods
135+
136+
## 🎯 Use Cases
137+
138+
Perfect for:
139+
- **Academic Research**: Econometric analysis for papers
140+
- **Business Analytics**: Market research and forecasting
141+
- **Policy Analysis**: Causal inference and impact evaluation
142+
- **Financial Modeling**: Risk analysis and portfolio optimization
143+
- **Data Science**: Exploratory analysis and feature engineering
144+
145+
---
146+
147+
*Powered by RMCP (R Model Context Protocol) - Making advanced econometrics accessible to everyone.*

0 commit comments

Comments
 (0)