Skip to content

Stage 3: Implement mci install command for project initialization#10

Merged
MaestroError merged 8 commits intomainfrom
copilot/implement-cli-install-command
Oct 29, 2025
Merged

Stage 3: Implement mci install command for project initialization#10
MaestroError merged 8 commits intomainfrom
copilot/implement-cli-install-command

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 29, 2025

Implements the mci install CLI command to bootstrap MCI projects with starter configuration files and directory structure.

Changes

Asset Templates

  • src/mci/assets/: Package-bundled templates for project initialization
    • mci.json / mci.yaml: Main configuration with example echo tool
    • example_toolset.mci.json / example_toolset.mci.yaml: CLI tool example using ls command (both JSON and YAML formats)
    • gitignore: Template for MCP server directory exclusion

Install Command

  • src/mci/cli/install.py: Install command implementation
    • copy_asset(): Zip-safe asset copying using importlib.resources
    • create_mci_file(): Creates JSON or YAML configuration (via --yaml flag)
    • create_mci_directory(): Sets up ./mci/ with smart .gitignore management
    • create_example_toolset(): Copies example toolset in matching format (JSON or YAML based on --yaml flag)
    • Idempotent design—never overwrites existing files

Integration

  • src/mci/mci.py: Registered install command with main CLI group
  • pyproject.toml: Force-include assets in wheel via [tool.hatch.build.targets.wheel.force-include]

Tests

  • Unit (16 tests): Asset copying, file creation, directory management, YAML example toolset
  • Feature (7 tests): End-to-end workflows, schema validation, MCIClient integration, YAML validation
  • Manual (4 scenarios): Real-world usage verification

Usage

# Initialize with JSON (default)
$ mci install
✓ Created mci.json
✓ Created ./mci/ directory
✓ Created ./mci/.gitignore
✓ Created ./mci/example_toolset.mci.json

# Initialize with YAML
$ mci install --yaml
✓ Created mci.yaml
✓ Created ./mci/ directory
✓ Created ./mci/.gitignore
✓ Created ./mci/example_toolset.mci.yaml

Generated files are valid MCI schemas that integrate with mci-py's MCIClient. Both JSON and YAML formats create matching example toolsets, ensuring consistency across different project setups.

Original prompt

This section details on the original issue you should resolve

<issue_title>Stage 3: CLI Command — mci install</issue_title>
<issue_description>## Goal
Implement the install CLI command to initialize an MCI project structure. Provide a simple way for users to bootstrap a new MCI project with starter schema files and directory organization.

Deliverables

  • Click command uvx mci install with optional --yaml flag
    • Copies template files (mci.json or mci.yaml) from package assets into project root (default: JSON; YAML if --yaml is passed)
    • Creates ./mci/ library directory
    • Copies example_toolset.mci.json from assets into ./mci/
    • Creates/updates ./mci/.gitignore with mcp/ entry (append if not present)
    • Handles existing files gracefully (no overwrite by default; friendly messaging)
  • Template files stored as assets:
    • src/mci/assets/mci.json
    • src/mci/assets/mci.yaml
    • src/mci/assets/example_toolset.mci.json
    • src/mci/assets/gitignore (contains mcp/)
  • Use importlib.resources to access and copy assets (zip-safe, avoids hardcoded paths)
  • Package configuration in pyproject.toml:
    • [tool.hatch.build.targets.wheel] should force-include src/mci/assets in the package wheel
  • Command registration in the root CLI group so uv run mci install works

Files to Create/Modify (from PLAN.md, updated for asset approach)

  • src/mci/cli/install.py — Install command implementation
  • src/mci/assets/mci.json — Main template file
  • src/mci/assets/mci.yaml — Main YAML template file
  • src/mci/assets/example_toolset.mci.json — Example toolset file
  • src/mci/assets/example_toolset.mci.yaml — Example toolset file
  • src/mci/assets/gitignore — Template for .gitignore
  • src/mci/mci.py — Register install command in Click group
  • pyproject.toml — Ensure asset inclusion in build config

Classes/Functions

  • install_command(yaml: bool = False) — Click command for mci install
  • copy_asset(package: str, resource_name: str, dest_path: Path, overwrite: bool = False) — Utility for copying assets
  • create_mci_file(format: str) -> None — Copy mci.json or mci.yaml from assets
  • create_mci_directory() -> None — Create ./mci directory and update .gitignore
  • create_example_toolset() -> None — Copy example.mci.json from assets

Initial MCI File Structure

The default JSON template (located at src/mci/assets/mci.json) should create:

{
  "schemaVersion": "1.0",
  "metadata": {
    "name": "Example Project",
    "description": "Example MCI configuration"
  },
  "tools": [
    {
      "name": "echo_test",
      "description": "Simple echo test tool",
      "inputSchema": {
        "type": "object",
        "properties": {
          "message": {
            "type": "string",
            "description": "Message to echo"
          }
        },
        "required": ["message"]
      },
      "execution": {
        "type": "text",
        "text": "Echo: {{props.message}}"
      }
    }
  ],
  "toolsets": [],
  "mcp_servers": {}
}

YAML template should be equivalent and reside in src/mci/assets/mci.yaml.

Implementation Notes

  • Do NOT embed large JSON/YAML strings in Python modules; use real files as templates (easier maintenance, validation, editing)
  • Use importlib.resources.files() for zip-safe asset access and copying
  • Print helpful messages if files already exist; skip unless future --force is introduced
  • Asset inclusion in wheel/package is critical for CLI usability
  • example_toolset file should contain only one CLI tool which runs ls command to list directory

LS command example

{
  "name": "list_files",
  "description": "List files in a directory",
  "inputSchema": {
    "type": "object",
    "properties": {
      "directory": { "type": "string" }
    }
  },
  "execution": {
    "type": "cli",
    "command": "ls",
    "args": ["-la", "{{props.directory}}"]
  },
  "enableAnyPaths": false,
  "directoryAllowList": [ "{{env.PROJECT_ROOT}}" ]
}

Tests

Unit Tests

  • tests/unit/cli/test_install.py
    • test_create_json_file() — Copies mci.json from assets
    • test_create_yaml_file() — Copies mci.yaml from assets with --yaml flag
    • test_file_already_exists() — Handles existing file gracefully
    • test_create_mci_directory() — Creates ./mci dir
    • test_create_gitignore() — Copies/updates .gitignore
  • Mock/sandbox filesystem to verify contents

Feature Tests

  • tests/test_install_command.py — Full install workflow in a temp directory

Manual Tests

  • testsManual/test_install.py — Run install in a real directory; verify files

Acceptance Criteria

  • uvx mci install copies mci.json with the specified structure
  • uvx mci install --yaml copies mci.yaml
  • ./mci/ directory is created with example.mci.json
  • ./mci/.gitignore exists and includes mcp/
  • Existing files are not overwritten by default; user sees a clear message
  • All tests pass (unit ...

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits October 29, 2025 16:22
Co-authored-by: MaestroError <46760939+MaestroError@users.noreply.github.com>
Co-authored-by: MaestroError <46760939+MaestroError@users.noreply.github.com>
Co-authored-by: MaestroError <46760939+MaestroError@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement CLI command to initialize MCI project structure Stage 3: Implement mci install command for project initialization Oct 29, 2025
Copilot AI requested a review from MaestroError October 29, 2025 16:31
@MaestroError MaestroError requested a review from Copilot October 29, 2025 18:20
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements the mci install command, which bootstraps a new MCI project by creating configuration files and directory structure. The implementation follows the project's testing strategy with unit tests, feature tests, and manual tests.

  • Adds install CLI command that creates mci.json (or mci.yaml with --yaml flag), ./mci/ directory, example toolset, and .gitignore configuration
  • Implements asset file copying from package resources using importlib.resources
  • Ensures idempotent behavior by gracefully handling existing files without overwriting them

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/mci/cli/install.py Core implementation of the install command with helper functions for file creation
src/mci/mci.py Registers the install command to the main CLI group
src/mci/assets/mci.json Template for JSON configuration file
src/mci/assets/mci.yaml Template for YAML configuration file
src/mci/assets/gitignore Template for .gitignore file in ./mci/ directory
src/mci/assets/example_toolset.mci.json Example toolset demonstrating CLI tool usage
tests/unit/cli/test_install.py Unit tests for individual functions in the install command
tests/test_install_command.py Feature tests for end-to-end install workflow
testsManual/test_install.py Manual test script for real-world install command verification
pyproject.toml Adds force-include configuration for assets directory in wheel build
README.md Documentation for the install command usage and examples
Comments suppressed due to low confidence (1)

testsManual/test_install.py:16

  • Import of 'shutil' is not used.
import shutil

@MaestroError
Copy link
Copy Markdown
Contributor

@copilot There is only the example_toolset.mci.json file, but we need to create YAML example toolset file when --yaml option is specified. Please add it and make sure it will be used when installing using yaml

Co-authored-by: MaestroError <46760939+MaestroError@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Oct 29, 2025

@copilot There is only the example_toolset.mci.json file, but we need to create YAML example toolset file when --yaml option is specified. Please add it and make sure it will be used when installi...

Added YAML example toolset file (example_toolset.mci.yaml) and updated the install command to use it when --yaml flag is specified.

When running mci install --yaml, the command now creates:

  • mci.yaml (main config)
  • ./mci/example_toolset.mci.yaml (example toolset)

Both JSON and YAML versions contain the same list_files CLI tool example.

Implemented in commit dc902b6.

@MaestroError MaestroError marked this pull request as ready for review October 29, 2025 18:42
@MaestroError MaestroError merged commit 27e0c04 into main Oct 29, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stage 3: CLI Command — mci install

3 participants