Skip to content

Commit

Permalink
mcp
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkEdmondson1234 committed Dec 13, 2024
1 parent f298188 commit eb347db
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 21 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ pip install . --use-feature=in-tree-build
pytest tests
```

## Local dev

```sh
uv tool install --from "sunholo[cli]" sunholo --with ".[all]"
```

## Demos

Using https://github.com/charmbracelet/vhs
Expand Down
3 changes: 3 additions & 0 deletions docs/docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ sunholo
### Upgrades and installing features

```bash
#uninstall
uv tool uninstall sunholo
#upgrade
uv tool upgrade sunholo
# install tool with Anthropic MCP
uv tool install --from "sunholo[cli]" sunholo --with "sunholo[anthropic]"
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup, find_packages

version = '0.116.1'
version = '0.116.2'

setup(
name='sunholo',
Expand Down
6 changes: 3 additions & 3 deletions sunholo/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
from ..senses.stream_voice import setup_tts_subparser
from ..mcp.cli import setup_mcp_subparser


from ..utils import ConfigManager
from ..utils.version import sunholo_version

from ..custom_logging import log

from .sun_rich import console
import sys
from rich.panel import Panel


def load_default_gcp_config():
try:
Expand All @@ -43,6 +42,7 @@ def __init__(self, option_strings, dest, nargs=0, **kwargs):
super().__init__(option_strings, dest, nargs=nargs, **kwargs)

def __call__(self, parser, namespace, values, option_string=None):
from rich.panel import Panel
console.print(
Panel("Welcome to Sunholo Command Line Interface, your assistant to deploy GenAI Virtual Agent Computers (VACs) to Multivac or your own Cloud.",
title="Sunholo GenAIOps Assistant CLI",
Expand All @@ -64,7 +64,7 @@ def main(args=None):
"""
default_project, default_region = load_default_gcp_config()

parser = argparse.ArgumentParser(description="sunholo CLI tool for deploying GenAI VACs 3", add_help=False)
parser = argparse.ArgumentParser(description=f"sunholo CLI tool for deploying GenAI VACs - [{sunholo_version()}]", add_help=False)
parser.add_argument('-h', '--help', action=CustomHelpAction, help='Show this help message and exit')
parser.add_argument('--debug', action='store_true', help='Enable debug output')
parser.add_argument('--project', default=default_project, help='GCP project to list Cloud Run services from.')
Expand Down
37 changes: 20 additions & 17 deletions sunholo/mcp/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Any, Sequence
from functools import lru_cache
import subprocess
from ..utils.version import sunholo_version

try:
from mcp.server import Server
Expand All @@ -24,12 +25,10 @@
from pydantic import AnyUrl

# Configure logging
import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger("sunholo-mcp")
from ..custom_logging import setup_logging
logger = setup_logging("sunholo-mcp")


class SunholoMCPServer2:
class SunholoMCPServer:
def __init__(self):
logger.info("Initializing Sunholo MCP Server")

Expand Down Expand Up @@ -58,8 +57,8 @@ async def list_resources() -> list[Resource]:
"""List available Sunholo resources"""
return [
Resource(
uri="sunholo://vacs/list2",
name="Available Sunholo VACs 2",
uri="sunholo://vacs/list",
name="Available Sunholo VACs",
mimeType="application/json",
description="List of available Virtual Agent Computers"
)
Expand All @@ -70,15 +69,14 @@ async def read_resource(uri: AnyUrl) -> str:
"""Read Sunholo resources based on URI"""
logger.info(f"{uri} available")
console.print(f"{uri} available")
if str(uri) == "sunholo://vacs/list2":
if str(uri) == "sunholo://vacs/list":
try:
# Execute sunholo vac list command
result = subprocess.run(
["sunholo", "vac", "list"],
capture_output=True,
text=True
)
console.print(f"{result=}")
return result.stdout
except subprocess.CalledProcessError as e:
raise RuntimeError(f"Failed to list VACs: {str(e)}")
Expand All @@ -96,7 +94,7 @@ async def list_tools() -> list[Tool]:
return [
Tool(
name="chat_with_vac",
description="Chat with a specific Sunholo VAC2",
description="Chat with a specific Sunholo VAC",
inputSchema={
"type": "object",
"properties": {
Expand All @@ -114,7 +112,7 @@ async def list_tools() -> list[Tool]:
),
Tool(
name="list_configs",
description="List Sunholo configurations2",
description="List Sunholo configurations",
inputSchema={
"type": "object",
"properties": {
Expand All @@ -135,7 +133,7 @@ async def list_tools() -> list[Tool]:
),
Tool(
name="embed_content",
description="Embed content in a VAC's vector store2",
description="Embed content in a VAC's vector store",
inputSchema={
"type": "object",
"properties": {
Expand Down Expand Up @@ -269,11 +267,16 @@ def cli_mcp(args):
"""CLI handler for the MCP server command"""
try:

if not os.getenv("VAC_CONFIG_FOLDER"):
raise ValueError("sunholo configuration folder must be present in config/ or via VAC_CONFIG_FOLDER")

# Create and run the MCP server
server = SunholoMCPServer2()

logger.info("Starting Sunholo MCP server3...")
console.print("Starting Sunholo MCP server3...")
server = SunholoMCPServer()
msg = {"message": "Starting Sunholo MCP server..."}

logger.info(msg)
console.print(msg)

asyncio.run(server.run())

except Exception as e:
Expand All @@ -292,6 +295,6 @@ def setup_mcp_subparser(subparsers):
```
"""
mcp_parser = subparsers.add_parser('mcp',
help='Start an Anthropic MCP server that wraps `sunholo` functionality3')
help='Start an Anthropic MCP server that wraps `sunholo` functionality')

mcp_parser.set_defaults(func=cli_mcp)

0 comments on commit eb347db

Please sign in to comment.