Versions: * arcade-mcp\==1.0.0rc1 * arcade-mcp-server\==1.0.0rc1 * arcade-core\==2.5.0rc1 * arcade-tdk\==2.6.0rc1 * arcade-serve\==2.2.0rc1 ### Summary Adds first-class MCP support across Arcade, introduces a new MCP server and CLI, unifies the project under the arcade-mcp name, overhauls templates/scaffolding, and improves developer tooling, secrets management, and examples. ### Highlights - **MCP Server & Core** - New MCP server with stdio and HTTP/SSE transports, session management, resumability, and lifecycle handling. - FastAPI-like `MCPApp` for building servers with lazy init; integrated worker+MCP HTTP app option. - Middleware system (logging and error handling), robust exception hierarchy, and Pydantic-based settings. - Async-safe managers for tools, resources, and prompts backed by registries and locks. - Developer-facing, transport-agnostic runtime context interfaces (logs, tools, prompts, resources, sampling, UI, notifications). - Conversion from Arcade ToolDefinition to MCP tool schema; OpenAI JSON tool schema converter. - Parser supports `@app.tool`/`@app.tool(...)` decorators. - **CLI** - New `mcp` command to run MCP servers with stdio or HTTP/SSE. - New `secret` command to set/list/unset tool secrets (supports .env input, preserves original casing for lookups). - `new` command refactored; option to create a full toolkit package with scaffolding. - `chat` command removed. - `serve.py` imports updated to `arcade_serve.fastapi.telemetry`; version retrieval now uses `arcade-mcp`. - `show.py` refactor to use new local catalog utilities. - `display_tool_details` improved: adds “Default” column and handles nested properties. - **Configuration & Discovery** - New `configure.py` to set up Claude Desktop, Cursor, and VS Code to connect to local or Arcade Cloud MCP servers. - Discovery utilities to find/install toolkits, build `ToolCatalog`s, analyze files for tools, load kits from directories (pyproject parsing), and build minimal toolkits. - Better handling of provider API key resolution and evaluation suite loading. - **Templates & Scaffolding** - Reorganized template structure (minimal vs full); moved `.pre-commit-config.yaml`, `.ruff.toml`, license, Makefile, README, tests, and tools layout to correct paths. - Minimal template adds `.env.example` for runtime secret injection. - Template pyproject updated for MCP servers; includes sample server with greeting and secret-reveal tools. - Authorization flow in templates simplified. - **Repo-wide Renaming & Examples** - Migrates references from `arcade-ai` to `arcade-mcp` across READMEs, scripts, and package metadata. - Examples updated (LangChain/LangGraph/AI SDK/TypeScript) and package name changed to `arcade-mcp-sdk`. - **Evals & Core Utilities** - Evals now use OpenAI tooling format (`OpenAIToolList`, `to_openai`); `tool_eval` takes `provider_api_key`. - Core utilities: fixed `does_function_return_value` by dedenting before parse; version bump to `2.5.0rc1` and dependency cleanup. - **Tooling & CI** - `setup-uv-env` action splits toolkit vs contrib dependency installation. - Pre-commit: excludes `libs/arcade-mcp-server/mkdocs.yml` and `libs/tests/` from YAML and Ruff hooks; Ruff per-file ignores (e.g., C901 in `libs/**/*.py`, TRY400 in server docs paths). - Makefile updates for uv env setup, quality checks, tests, builds, and new `shell` target. - Added Makefile to MCP server library to streamline dev workflow. - **Cleanup** - Removed `claude.json` config. - Simplified stdio entrypoint; removed unused imports (`arcade_gmail`, `arcade_search`). ### Breaking Changes - **CLI**: `chat` command removed; use `mcp`, `secret`, and updated `new`. - **Naming**: All users should update references from `arcade-ai` to `arcade-mcp`. - **Templates**: File paths moved; downstream scripts referencing old template locations may need updates. ### Getting Started - Run an MCP server: - `arcade mcp --stdio --toolkits your_toolkit` - `arcade mcp --http --toolkits your_toolkit` - Manage secrets: - `arcade secret set your_toolkit KEY=value` - `arcade secret list your_toolkit` - `arcade secret unset your_toolkit KEY` - Configure clients: - `arcade configure` to set up Claude Desktop, Cursor, and VS Code for local/Arcade Cloud MCP. --------- Co-authored-by: Sam Partee <sam@arcade-ai.com> Co-authored-by: Shub <125150494+shubcodes@users.noreply.github.com>
251 lines
8.6 KiB
Python
251 lines
8.6 KiB
Python
import tempfile
|
|
from io import StringIO
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
import httpx
|
|
import pytest
|
|
from arcade_cli.secret import (
|
|
_delete_secret_from_engine,
|
|
_get_secrets_from_engine,
|
|
_remove_inline_comment,
|
|
_upsert_secret_to_engine,
|
|
load_env_file,
|
|
print_secret_table,
|
|
)
|
|
|
|
|
|
class TestPrintSecretTable:
|
|
"""Tests for print_secret_table function."""
|
|
|
|
def test_print_secret_table_empty(self, capsys):
|
|
"""Test printing a table with no secrets."""
|
|
secrets = []
|
|
print_secret_table(secrets)
|
|
|
|
captured = capsys.readouterr()
|
|
assert "Tool Secrets" in captured.out
|
|
|
|
|
|
class TestLoadEnvFile:
|
|
"""Tests for load_env_file function."""
|
|
|
|
def test_load_env_file_basic(self):
|
|
"""Test loading a basic .env file."""
|
|
env_content = """
|
|
KEY1=value1
|
|
KEY2=value2
|
|
# This is a comment
|
|
KEY3=value3
|
|
"""
|
|
with tempfile.NamedTemporaryFile(mode="w", suffix=".env", delete=False) as f:
|
|
f.write(env_content)
|
|
f.flush()
|
|
|
|
secrets = load_env_file(f.name)
|
|
|
|
assert secrets == {
|
|
"KEY1": "value1",
|
|
"KEY2": "value2",
|
|
"KEY3": "value3",
|
|
}
|
|
|
|
def test_load_env_file_with_quotes(self):
|
|
"""Test loading .env file with quoted values."""
|
|
env_content = """
|
|
KEY1="quoted value"
|
|
KEY2='single quoted'
|
|
KEY3="value with = sign"
|
|
KEY4="value with # comment inside"
|
|
"""
|
|
with tempfile.NamedTemporaryFile(mode="w", suffix=".env", delete=False) as f:
|
|
f.write(env_content)
|
|
f.flush()
|
|
|
|
secrets = load_env_file(f.name)
|
|
|
|
assert secrets == {
|
|
"KEY1": "quoted value",
|
|
"KEY2": "single quoted",
|
|
"KEY3": "value with = sign",
|
|
"KEY4": "value with # comment inside",
|
|
}
|
|
|
|
def test_load_env_file_with_inline_comments(self):
|
|
"""Test loading .env file with inline comments."""
|
|
env_content = """
|
|
KEY1=value1 # inline comment
|
|
KEY2="quoted value" # comment after quote
|
|
KEY3=value3# no space before comment
|
|
"""
|
|
with tempfile.NamedTemporaryFile(mode="w", suffix=".env", delete=False) as f:
|
|
f.write(env_content)
|
|
f.flush()
|
|
|
|
secrets = load_env_file(f.name)
|
|
|
|
assert secrets == {
|
|
"KEY1": "value1",
|
|
"KEY2": "quoted value",
|
|
"KEY3": "value3# no space before comment", # No space, so not treated as comment
|
|
}
|
|
|
|
def test_load_env_file_skip_empty_and_invalid(self):
|
|
"""Test that empty lines, comments, and invalid entries are skipped."""
|
|
env_content = """
|
|
# Comment line
|
|
KEY1=value1
|
|
|
|
KEY2=
|
|
=value_without_key
|
|
KEY3=value3
|
|
invalid_line_without_equals
|
|
KEY4=value4
|
|
"""
|
|
with tempfile.NamedTemporaryFile(mode="w", suffix=".env", delete=False) as f:
|
|
f.write(env_content)
|
|
f.flush()
|
|
|
|
secrets = load_env_file(f.name)
|
|
|
|
assert secrets == {
|
|
"KEY1": "value1",
|
|
"KEY3": "value3",
|
|
"KEY4": "value4",
|
|
}
|
|
|
|
|
|
class TestRemoveInlineComment:
|
|
"""Tests for _remove_inline_comment function."""
|
|
|
|
def test_remove_inline_comment_unquoted(self):
|
|
"""Test removing inline comments from unquoted values."""
|
|
assert _remove_inline_comment("value # comment") == "value"
|
|
assert _remove_inline_comment("value# no space") == "value# no space"
|
|
assert _remove_inline_comment("value") == "value"
|
|
assert _remove_inline_comment("value with spaces # comment") == "value with spaces"
|
|
|
|
def test_remove_inline_comment_double_quoted(self):
|
|
"""Test removing inline comments from double-quoted values."""
|
|
assert _remove_inline_comment('"quoted value" # comment') == "quoted value"
|
|
assert _remove_inline_comment('"value with # inside"') == "value with # inside"
|
|
assert _remove_inline_comment('"quoted value"') == "quoted value"
|
|
assert _remove_inline_comment('"unclosed quote') == '"unclosed quote'
|
|
|
|
def test_remove_inline_comment_single_quoted(self):
|
|
"""Test removing inline comments from single-quoted values."""
|
|
assert _remove_inline_comment("'quoted value' # comment") == "quoted value"
|
|
assert _remove_inline_comment("'value with # inside'") == "value with # inside"
|
|
assert _remove_inline_comment("'quoted value'") == "quoted value"
|
|
assert _remove_inline_comment("'unclosed quote") == "'unclosed quote"
|
|
|
|
def test_remove_inline_comment_edge_cases(self):
|
|
"""Test edge cases for inline comment removal."""
|
|
assert _remove_inline_comment("") == ""
|
|
|
|
|
|
class TestUpsertSecretToEngine:
|
|
"""Tests for _upsert_secret_to_engine function."""
|
|
|
|
@patch("arcade_cli.secret.httpx.put")
|
|
def test_upsert_secret_success(self, mock_put):
|
|
"""Test successful secret upsert."""
|
|
mock_response = MagicMock()
|
|
mock_response.raise_for_status.return_value = None
|
|
mock_put.return_value = mock_response
|
|
|
|
_upsert_secret_to_engine(
|
|
"https://api.example.com", "test-api-key", "SECRET_KEY", "secret-value"
|
|
)
|
|
|
|
mock_put.assert_called_once_with(
|
|
"https://api.example.com/v1/admin/secrets/SECRET_KEY",
|
|
headers={"Authorization": "Bearer test-api-key"},
|
|
json={"description": "Secret set via CLI", "value": "secret-value"},
|
|
)
|
|
mock_response.raise_for_status.assert_called_once()
|
|
|
|
@patch("arcade_cli.secret.httpx.put")
|
|
def test_upsert_secret_http_error(self, mock_put):
|
|
"""Test secret upsert with HTTP error."""
|
|
mock_response = MagicMock()
|
|
mock_response.raise_for_status.side_effect = httpx.HTTPStatusError(
|
|
"Bad Request", request=MagicMock(), response=MagicMock()
|
|
)
|
|
mock_put.return_value = mock_response
|
|
|
|
with pytest.raises(httpx.HTTPStatusError):
|
|
_upsert_secret_to_engine(
|
|
"https://api.example.com", "test-api-key", "SECRET_KEY", "secret-value"
|
|
)
|
|
|
|
|
|
class TestGetSecretsFromEngine:
|
|
"""Tests for _get_secrets_from_engine function."""
|
|
|
|
@patch("arcade_cli.secret.httpx.get")
|
|
def test_get_secrets_success(self, mock_get):
|
|
"""Test successful secrets retrieval."""
|
|
mock_response = MagicMock()
|
|
mock_response.raise_for_status.return_value = None
|
|
mock_response.json.return_value = {
|
|
"items": [
|
|
{"key": "SECRET1", "id": "id1"},
|
|
{"key": "SECRET2", "id": "id2"},
|
|
]
|
|
}
|
|
mock_get.return_value = mock_response
|
|
|
|
secrets = _get_secrets_from_engine("https://api.example.com", "test-api-key")
|
|
|
|
assert secrets == [
|
|
{"key": "SECRET1", "id": "id1"},
|
|
{"key": "SECRET2", "id": "id2"},
|
|
]
|
|
mock_get.assert_called_once_with(
|
|
"https://api.example.com/v1/admin/secrets",
|
|
headers={"Authorization": "Bearer test-api-key"},
|
|
)
|
|
mock_response.raise_for_status.assert_called_once()
|
|
|
|
@patch("arcade_cli.secret.httpx.get")
|
|
def test_get_secrets_http_error(self, mock_get):
|
|
"""Test secrets retrieval with HTTP error."""
|
|
mock_response = MagicMock()
|
|
mock_response.raise_for_status.side_effect = httpx.HTTPStatusError(
|
|
"Unauthorized", request=MagicMock(), response=MagicMock()
|
|
)
|
|
mock_get.return_value = mock_response
|
|
|
|
with pytest.raises(httpx.HTTPStatusError):
|
|
_get_secrets_from_engine("https://api.example.com", "test-api-key")
|
|
|
|
|
|
class TestDeleteSecretFromEngine:
|
|
"""Tests for _delete_secret_from_engine function."""
|
|
|
|
@patch("arcade_cli.secret.httpx.delete")
|
|
def test_delete_secret_success(self, mock_delete):
|
|
"""Test successful secret deletion."""
|
|
mock_response = MagicMock()
|
|
mock_response.raise_for_status.return_value = None
|
|
mock_delete.return_value = mock_response
|
|
|
|
_delete_secret_from_engine("https://api.example.com", "test-api-key", "secret-id-123")
|
|
|
|
mock_delete.assert_called_once_with(
|
|
"https://api.example.com/v1/admin/secrets/secret-id-123",
|
|
headers={"Authorization": "Bearer test-api-key"},
|
|
)
|
|
mock_response.raise_for_status.assert_called_once()
|
|
|
|
@patch("arcade_cli.secret.httpx.delete")
|
|
def test_delete_secret_http_error(self, mock_delete):
|
|
"""Test secret deletion with HTTP error."""
|
|
mock_response = MagicMock()
|
|
mock_response.raise_for_status.side_effect = httpx.HTTPStatusError(
|
|
"Not Found", request=MagicMock(), response=MagicMock()
|
|
)
|
|
mock_delete.return_value = mock_response
|
|
|
|
with pytest.raises(httpx.HTTPStatusError):
|
|
_delete_secret_from_engine("https://api.example.com", "test-api-key", "secret-id-123")
|