Skip to content

Commit 2400e28

Browse files
committed
initial command
1 parent 1a1ae59 commit 2400e28

File tree

2 files changed

+60
-2
lines changed

2 files changed

+60
-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: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,62 @@ 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+
def list_content():
426+
try:
427+
client = Client(server, api_key)
428+
response = client.get("v1/content")
429+
return response.json()
430+
except Exception as e:
431+
raise ToolError(f"Failed to list content: {e}")
432+
433+
def get_content_item(app_guid: str):
434+
try:
435+
client = Client(server, api_key)
436+
response = client.content.get(app_guid)
437+
return response.json()
438+
except Exception as e:
439+
raise ToolError(f"Failed to get content: {e}")
440+
441+
442+
mcp = FastMCP("Connect MCP")
443+
444+
mcp.tool(description="Get content logs from Posit Connect")(get_content_logs)
445+
mcp.tool(description="List content from Posit Connect")(list_content)
446+
mcp.tool(description="Get content item from Posit Connect")(get_content_item)
447+
448+
mcp.run()
449+
450+
395451
def _test_server_and_api(server: str, api_key: str, insecure: bool, ca_cert: str | None):
396452
"""
397453
Test the specified server information to make sure it works. If so, a

0 commit comments

Comments
 (0)