@@ -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+
395451def _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