Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/rerun-unacquired.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
run: |
# Count the test jobs no runner took, and the ones which did not pass for another reason.
counts=$(gh api "repos/$GH_REPO/actions/runs/$RUN_ID/attempts/$RUN_ATTEMPT/jobs?per_page=100" --jq '
[.jobs[] | select(.name | startswith("tests (") or startswith("example-tests ("))
[.jobs[] | select(.name | startswith("tests (") or startswith("mcp-tests ("))
| select(.conclusion != "success")] as $bad
| [$bad[] | select(.conclusion == "cancelled" and .runner_id == 0 and (.steps | length) == 0)] as $unacquired
| "\($unacquired | length) \(($bad | length) - ($unacquired | length))"')
Expand Down
34 changes: 22 additions & 12 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ jobs:
allow-prereleases: true
- name: Install the project
run: uv sync --no-default-groups --group test
- name: Verify the base installation has no MCP SDK
run:
uv run --no-sync python -c "from importlib.util import find_spec; assert find_spec('mcp')
is None"

# faulthandler_timeout in pyproject.toml makes pytest print the stack of every thread once a
# test has run for a minute. A test which hangs keeps the job going until its timeout, above.
Expand All @@ -92,10 +96,10 @@ jobs:
use_oidc: true
verbose: true

# The MCP server example is the one example with tests, and its tests of the server itself need
# the MCP SDK, which the test group does not install. This job installs it, so that they run
# somewhere on every pull request.
example-tests:
mcp-tests:
permissions:
contents: read
id-token: write
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
Expand All @@ -105,7 +109,7 @@ jobs:
timeout-minutes: 10
env:
# With this set, a test which needs the SDK fails where the SDK is missing. It is not skipped.
CMD2_EXAMPLE_TESTS_NEED_SDK: "1"
CMD2_MCP_TESTS_NEED_SDK: "1"
defaults:
run:
shell: bash
Expand All @@ -122,22 +126,28 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
- name: Install the project with the examples group
run: uv sync --no-default-groups --group test --group examples
- name: Install the project with the MCP extra
run: uv sync --no-default-groups --group test --extra mcp

- name: Run the example's tests
- name: Run MCP server and example tests
run: >-
uv run --no-default-groups --group test --group examples python -Xutf8 -m pytest
tests/test_example_mcp_server.py --no-cov -rs
uv run --no-sync python -Xutf8 -m pytest tests/test_mcp_server.py -rs
- name: Upload MCP coverage to Codecov
if: ${{ !cancelled() }}
uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1
with:
files: coverage.xml
flags: unittests
use_oidc: true

# Single stable status check for the whole test matrix, so branch protection
# doesn't need updating every time the OS/Python matrix changes.
all-tests-passed:
name: All Tests Passed
if: always()
needs: [tests, example-tests]
needs: [tests, mcp-tests]
runs-on: ubuntu-latest
steps:
- name: Fail if any matrix job did not succeed
if: needs.tests.result != 'success' || needs.example-tests.result != 'success'
if: needs.tests.result != 'success' || needs.mcp-tests.result != 'success'
run: exit 1
11 changes: 4 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,10 @@
cannot be reassigned. A parser given to `@with_argparser` is the spec's `parser_source`
itself, shared by every application which has not built the command's parser yet: to change
one application's parser, change the one which `self.command_parsers.get(func)` returns.
- Added the
[mcp_server.py](https://github.com/python-cmd2/cmd2/blob/main/examples/mcp_server.py) example,
a `cmd2` application which, while its prompt is live, serves a read-only description of its
own commands to an AI assistant over MCP, so that the assistant can work out the command line
for what the person asks. It needs the MCP SDK, which is not a `cmd2` dependency. See
[MCP Server](docs/examples/mcp_server.md) for how to run it, connect an assistant, and use it
in your own application.
- Added an optional [MCP server](docs/features/mcp_server.md) to `Cmd`. Install `cmd2[mcp]` and
set `mcp_port` to let local clients discover the running application's commands, arguments,
shortcuts, aliases, and macros. The server is read-only and disabled by default. The
[Fleet console example](docs/examples/mcp_server.md) shows how to connect a client.

## 4.4.5 (2026-12-02)

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ dashboards and panels that show realtime status and other information. See
example.

An AI assistant can use the Model Context Protocol (MCP) to discover the commands, arguments, and
aliases available in a running `cmd2` application. The read-only
[MCP server example](examples/mcp_server.py) shows how. Follow the
[setup guide](docs/examples/mcp_server.md) to connect a client or add the server to your own app.
aliases available in a running `cmd2` application. Install `cmd2[mcp]` and pass `mcp_port=8765` to
`cmd2.Cmd` to enable the read-only server. See the [MCP server guide](docs/features/mcp_server.md)
and [Fleet console example](examples/mcp_server.py).

## Quick start

Expand Down
Loading