Skip to content

Commit acbea61

Browse files
committed
rmcp. toward packaging
1 parent e3c73c9 commit acbea61

File tree

13 files changed

+118
-4
lines changed

13 files changed

+118
-4
lines changed

pyproject.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[build-system]
2+
requires = ["setuptools>=61.0", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "rmcp"
7+
version = "0.1.0"
8+
description = "A Model Context Protocol server for R"
9+
readme = "README.md"
10+
authors = [
11+
{ name = "Your Name", email = "[email protected]" }
12+
]
13+
license = { text = "MIT License" }
14+
requires-python = ">=3.8"
15+
dependencies = [
16+
"click>=8.1.0"
17+
# add other dependencies here
18+
]
19+
20+
[project.urls]
21+
Homepage = "https://github.com/gojiplus/rmcp"
22+
23+
[project.scripts]
24+
rmcp = "rmcp.cli:cli"

requirements.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.
File renamed without changes.

rmcp/cli.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# rmcp/cli.py
2+
import click
3+
import os
4+
5+
# Import your server's main function from rmcp, adjust the import if necessary.
6+
from rmcp.server.stdio import stdio_server
7+
from rmcp.server.fastmcp import FastMCP
8+
9+
# Initialize your MCP server (update the parameters as needed)
10+
mcp = FastMCP(
11+
name="R Econometrics",
12+
version="0.1.0",
13+
description="A Model Context Protocol server for R-based econometric analysis"
14+
)
15+
16+
@click.group()
17+
def cli():
18+
"""rmcp CLI for running and managing the R Econometrics MCP Server."""
19+
pass
20+
21+
@cli.command()
22+
@click.argument("server_file", type=click.Path(exists=True))
23+
def dev(server_file):
24+
"""
25+
Run the MCP server in development mode from the given server file.
26+
27+
SERVER_FILE: The Python file containing your MCP server definition.
28+
"""
29+
click.echo(f"Running MCP server in development mode from {server_file}...")
30+
with open(server_file) as f:
31+
code = f.read()
32+
exec(code, globals())
33+
34+
@cli.command()
35+
def start():
36+
"""
37+
Start the MCP server using the default configuration.
38+
"""
39+
click.echo("Starting the MCP server via standard input...")
40+
stdio_server(mcp)
41+
42+
@cli.command()
43+
def version():
44+
"""Show the version of the rmcp package."""
45+
click.echo("rmcp version 0.1.0")
46+
47+
if __name__ == "__main__":
48+
cli()
File renamed without changes.
File renamed without changes.
File renamed without changes.

rmcp/tools.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# rmcp/tools.py
2+
from rmcp.server.fastmcp import FastMCP
3+
from rmcp.rmcp import execute_r_script # or move execute_r_script into a shared module
4+
# Import your R script constants too, if needed:
5+
from rmcp.rmcp import LINEAR_REGRESSION_SCRIPT, PANEL_MODEL_SCRIPT, DIAGNOSTICS_SCRIPT, IV_REGRESSION_SCRIPT
6+
7+
mcp = FastMCP(
8+
name="R Econometrics",
9+
version="0.1.0",
10+
description="A Model Context Protocol server for R-based econometric analysis"
11+
)
12+
13+
@mcp.tool(
14+
name="linear_model",
15+
description="Run a linear regression model",
16+
input_schema={
17+
"type": "object",
18+
"properties": {
19+
"formula": {"type": "string", "description": "The regression formula (e.g., 'y ~ x1 + x2')"},
20+
"data": {"type": "object", "description": "Dataset as a dictionary/JSON object"},
21+
"robust": {"type": "boolean", "description": "Whether to use robust standard errors"}
22+
},
23+
"required": ["formula", "data"]
24+
}
25+
)
26+
def linear_model(formula: str, data: dict, robust: bool = False) -> dict:
27+
args = {"formula": formula, "data": data, "robust": robust}
28+
return execute_r_script(LINEAR_REGRESSION_SCRIPT, args)
29+
30+
# Register additional tools similarly...
31+
32+
# Expose the instance for use in other modules.
33+
__all__ = ["mcp"]
File renamed without changes.

tests/run_cli_tests.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "Testing 'rmcp version'..."
5+
rmcp version
6+
7+
echo "Testing 'rmcp start' with test_request.json..."
8+
cat tests/test_request.json | rmcp start
9+
10+
echo "Testing 'rmcp dev' with rmcp.py..."
11+
rmcp dev rmcp.py
12+
13+
echo "All CLI tests passed."

0 commit comments

Comments
 (0)