Skip to content

Commit 2ae7d12

Browse files
committed
initial command
1 parent 1a1ae59 commit 2ae7d12

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

pyproject.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@ description = "The Posit Connect command-line interface."
55
authors = [{ name = "Posit, PBC", email = "[email protected]" }]
66
license = { file = "LICENSE.md" }
77
readme = { file = "README.md", content-type = "text/markdown" }
8-
requires-python = ">=3.8"
8+
requires-python = ">=3.10"
99

1010
dependencies = [
1111
"typing-extensions>=4.8.0",
1212
"pip>=10.0.0",
1313
"semver>=2.0.0,<4.0.0",
1414
"pyjwt>=2.4.0",
1515
"click>=8.0.0",
16-
"toml>=0.10; python_version < '3.11'"
16+
"toml>=0.10; python_version < '3.11'",
17+
"fastmcp",
18+
"posit-sdk"
1719
]
1820

1921
dynamic = ["version"]

rsconnect/main.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,44 @@ def version():
392392
click.echo(VERSION)
393393

394394

395+
@cli.command(help="Start the MCP server")
396+
@click.option(
397+
"--server",
398+
"-s",
399+
envvar="CONNECT_SERVER",
400+
help="Posit Connect server URL"
401+
)
402+
@click.option(
403+
"--api-key",
404+
"-k",
405+
envvar="CONNECT_API_KEY",
406+
help="The API key to use to authenticate with Posit Connect."
407+
)
408+
def mcp_server(server: str, api_key: str):
409+
from fastmcp import FastMCP
410+
from fastmcp.exceptions import ToolError
411+
from posit.connect import Client
412+
413+
def get_content_logs(app_guid: str):
414+
try:
415+
client = Client(server, api_key)
416+
response = client.get(f"v1/content/{app_guid}/jobs")
417+
jobs = response.json()
418+
# first job key is the most recent one
419+
key = jobs[0]["key"]
420+
logs = client.get(f"v1/content/{app_guid}/jobs/{key}/log")
421+
return logs.json()
422+
except Exception as e:
423+
raise ToolError(f"Failed to get logs: {e}")
424+
425+
426+
mcp = FastMCP("Connect MCP")
427+
428+
mcp.tool(description="Get content logs from Posit Connect")(get_content_logs)
429+
430+
mcp.run()
431+
432+
395433
def _test_server_and_api(server: str, api_key: str, insecure: bool, ca_cert: str | None):
396434
"""
397435
Test the specified server information to make sure it works. If so, a

0 commit comments

Comments
 (0)